运行时 C# 知道是否正在使用 32 位或 64 位版本的 COM 接口 [英] Runtime C# knowing if 32-bit or 64-bit version of COM Interface is being used
问题描述
我想构建一个使用 COM Interop 的 DLL 类库,使用 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
}
附注.有关是否需要检查大小为 16 的讨论,请参阅 我对这个问题的回答.
PS. for discussion of whether you need to check for a size of 16, see my answer to this question.
这篇关于运行时 C# 知道是否正在使用 32 位或 64 位版本的 COM 接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!