網(wǎng)站首頁 編程語言 正文
c#判斷dll文件是32位還是64位,實例代碼如下所示:
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í)行錯誤!"); } /// <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; } } }
原文鏈接:https://www.cnblogs.com/LifeDecidesHappiness/p/15711169.html
相關推薦
- 2022-01-04 微信小程序內(nèi)部A頁面向內(nèi)嵌H5頁面跳轉,并且傳參
- 2022-05-22 Flutter應用框架搭建之屏幕適配詳解_Android
- 2022-06-16 docker?maven?plugin快速部署微服務的詳細流程_docker
- 2022-05-29 Android?App如何防止抓包_Android
- 2022-01-10 設置Radio不可點擊遇到的問題
- 2022-05-23 C#多線程之線程同步WaitHandle_C#教程
- 2023-01-13 C#實現(xiàn)動態(tài)圖標閃爍顯示的示例代碼_C#教程
- 2022-08-02 C#定時器組件FluentScheduler用法_C#教程
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結構-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支