C#判斷DLL文件是32位還是64位的示例代碼
c#判斷dll文件是32位還是64位,實(shí)例代碼如下所示:
using System; using System.IO; namespace GetDllVersionDemo { /// <summary> /// https://www.cnblogs.com/LifeDecidesHappiness/p/15711169.html /// C#判斷DLL文件是32位還是64位 /// LDH @ 2021-12-20 /// </summary> internal class Program { private static void Main() { Console.Title = "C#判斷DLL文件是32位還是64位"; GetDll32Or64(); Console.ReadKey(); } private static void GetDll32Or64() { var dllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Dll\IBM.Data.Informix.dll"); var result = GetPeArchitecture(dllPath); //523 64位 267 32位 if (result == 523) Console.WriteLine(dllPath + "是【64】位的dll"); else if (result == 267) Console.WriteLine(dllPath + "是【32】位的dll"); else Console.WriteLine("執(zhí)行錯(cuò)誤!"); } /// <summary> /// 獲取dll文件是32位還是64位 /// 523 64位 267 32位 /// </summary> /// <param name="dllFilePath">dll文件路徑</param> /// <returns></returns> public static ushort GetPeArchitecture(string dllFilePath) { ushort architecture = 0; try { using (var fStream = new FileStream(dllFilePath, FileMode.Open, FileAccess.Read)) { using (var bReader = new BinaryReader(fStream)) { if (bReader.ReadUInt16() == 23117) //check the MZ signature { fStream.Seek(0x3A, SeekOrigin.Current); //seek to e_lfanew. fStream.Seek(bReader.ReadUInt32(), SeekOrigin.Begin); //seek to the start of the NT header. if (bReader.ReadUInt32() == 17744) //check the PE\0\0 signature. { fStream.Seek(20, SeekOrigin.Current); //seek past the file header, architecture = bReader.ReadUInt16(); //read the magic number of the optional header. } } } } } catch { // ignored } // if architecture returns 0, there has been an error. return architecture; } } }
到此這篇關(guān)于C#判斷DLL文件是32位還是64位的文章就介紹到這了,更多相關(guān)C#判斷DLL文件內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Unity的Console的控制類(lèi)LogEntries深入解析與實(shí)用案例
這篇文章主要為大家介紹了Unity的Console的控制類(lèi)LogEntries深入解析與實(shí)用案例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-07-07C#語(yǔ)言中字符類(lèi)char的使用方法(總結(jié))
下面小編就為大家?guī)?lái)一篇C#語(yǔ)言中字符類(lèi)char的使用方法(總結(jié))。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-03-03快速解決owin返回json字符串多帶了雙引號(hào)"多了重string轉(zhuǎn)義字符串
下面小編就為大家?guī)?lái)一篇快速解決owin返回json字符串多帶了雙引號(hào)"多了重string轉(zhuǎn)義字符串。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-08-08C#中把DataTable、Dataset轉(zhuǎn)Json數(shù)據(jù)
這篇文章介紹了C#中把DataTable、Dataset轉(zhuǎn)Json數(shù)據(jù)的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-04-04Unity的AssetPostprocessor?Model動(dòng)畫(huà)函數(shù)使用案例深究
這篇文章主要介紹了Unity的AssetPostprocessor?Model動(dòng)畫(huà)函數(shù)使用案例的深入解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08