Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write sample code for C # to determine whether a DLL file is 32-bit or 64-bit?

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

C # to determine whether the DLL file is 32-bit or 64-bit sample code how to write, I believe that many inexperienced people do not know what to do, so this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

C # determines whether the dll file is 32-bit or 64-bit. The example code is as follows:

Using System;using System.IO;namespace GetDllVersionDemo {/ https://www.cnblogs.com/LifeDecidesHappiness/p/15711169.html/// C# determines whether the DLL file is 32-bit or 64-bit / LDH @ 2021-12-20 / internal class Program {private static void Main () {Console.Title = "C # determines whether the DLL file is 32-bit or 64-bit"; 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-bit 267 32-bit if (result = = 523) Console.WriteLine (dllPath + "is [64] bit dll"); else if (result = = 267) Console.WriteLine (dllPath + "is [32] bit dll"); elseConsole.WriteLine ("execution error!") ;} / get whether the dll file is 32-bit or 64-bit / 523 64-bit 267 32-bit / dll file path / 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;}

After reading the above, have you mastered the method of how to write sample code in C # to determine whether the DLL file is 32-bit or 64-bit? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report