Runtime C# knowing if 32-bit or 64-bit version of COM Interface is being used

淺唱寂寞╮ 提交于 2019-12-13 12:29:02

问题


I want to build a DLL Class Library use COM Interop, with C#, target ANY CPU, and register it as 32-bit and 64-bit interfaces.

I want to be able to, at runtime, display what interface was used - if I am using the 32-bit version, or 64-bit version.

Any ideas?


回答1:


In order for a process to load a 32-bit DLL, the process has to be 32-bit. And same for 64-bit. So to find out what has been loaded, assuming it has already worked, you just need to find out the bit-ness of the CLR:

if (System.IntPtr.Size == 8)
{
    // 64-bit
}
else
{
    // 32-bit
}

PS. for discussion of whether you need to check for a size of 16, see my answer to this question.




回答2:


and again, what about 32-bit processes running on win64 ?

https://stackoverflow.com/a/3461562/1498669

If you're using .Net 4.0, it's a one-liner for the current process:

Environment.Is64BitProcess

http://msdn.microsoft.com/en-us/library/system.environment.is64bitprocess.aspx



来源:https://stackoverflow.com/questions/372023/runtime-c-sharp-knowing-if-32-bit-or-64-bit-version-of-com-interface-is-being-us

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!