首页 > 作文

C#判断DLL文件是32位还是64位的示例代码

更新时间:2023-04-04 04:14:11 阅读: 评论:0

c#判断dll文件是32位还是64位,实例代码如下所示:

using system;using system.io;namespace getdllversiondemo{/// <summary>///     /d/file/titlepic/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.badirectory, @"dll\ibm.data.informix.dll");var result = getpearchitecture(dllpath);//523 64位    267 32位if (result == 523)console.writeline(dllpath + "是【64】位的dll");el if (result == 267)console.writeline(dllpath + "是【32】位的dll");elconsole.writeline("执行错误!");}        /// <summary>/e的x次方定义域//     获取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.ek(0x3a, ekorigin.current); //ek to e_lfanew.fstream.ek(breader.readuint32(), ekorigin.begin); //ek to the start of the nt header.if (breader.readuint32() == 17744) //check the p江苏2013高考e
using system;using 倍爽 大张伟system.io;namespace getdllversiondemo{/// <summary>///     /d/file/titlepic/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.badirectory, @"dll\ibm.data.informix.dll");var result = getpearchitecture(dllpath);//523 64位    267 32位if (result == 523)console.writeline(dllpath + "是【64】位的dll");el if (result == 267)console.writeline(dllpath + "是【32】位的dll");elconsole.writeline("执行错误!");}/// <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.ek(0x3a, ekorigin.current); //ek to e_lfanew.fstream.ek(breader.readuint32(), ekorigin.begin); //ek to the start of the nt header.if (breader.readuint32() == 17744) //check the pe\0\0 signature.{fstream.ek(20, ekorigin.current); //ek 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;}}}
using system;using system.io;namespace getdllversiondemo{/// <summary>///     /d/file/titlepic/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.badirectory, @"dll\ibm.data.informix.dll");var result = getpearchitecture(dllpath);//523 64位    267 32位if (result == 523)console.writeline(dllpath + "是【64】位的dll");el if (result == 267)console.writeline(dllpath + "是【32】位的dll");elconsole.writeline("执行错误!");}/// <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.ek(0x3a, ekorigin.current); //ek to e_lfanew.fstream.ek(breader.readuint32(), ekorigin.begin); //ek to the start of the nt header.if (breader.readuint32() == 17744) //check the pe\0\0 signature.{fstream.ek(20, ekorigin.current); //ek 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;}}}
signature.{fstream.ek(20, ekorigin.current); //ek 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;}}}

到此这篇关于c#判断dll文件是32位还是64位的文章就介绍到这了,更多相关c#判断dll文件内容请搜索www.887551.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持www.887551.com!

本文发布于:2023-04-04 04:14:09,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/2faed699f552aa1e2febf66de58a24cc.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:C#判断DLL文件是32位还是64位的示例代码.doc

本文 PDF 下载地址:C#判断DLL文件是32位还是64位的示例代码.pdf

标签:文件   路径   错误   共青团
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图