运行C#如果正在使用32位或64位版本的COM接口的认识 [英] Runtime C# knowing if 32-bit or 64-bit version of COM Interface is being used
问题描述
我想建立一个DLL类库使用COM互操作,用C#,针对任何CPU,并将其注册为32位和64位接口。
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.
我希望能够在运行时,显示的内容界面使用 - 如果我现在用的是32位版本或64位版本的
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.
任何想法?
推荐答案
为了让一个进程加载32位的DLL,该过程必须是32位。而同样为64位。因此,要找出已经被加载,假设它已经工作,你只需要找出位岬的CLR的:
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。对于是否需要检查16的大小讨论,请参阅<一href="http://stackoverflow.com/questions/342433/what-is-going-to-happen-to-our-primative-types-when-128-bit-processors-come-out#342486">my这个问题的答案。
这篇关于运行C#如果正在使用32位或64位版本的COM接口的认识的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!