views:

1670

answers:

1

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?

+5  A: 

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.

Daniel Earwicker
You could just say if(IntPtr.Size==8)
Sean
Holy cow, that's neat. Will update.
Daniel Earwicker
You don't handle the other case, when it's not 8 and it's not 32-bit.
Ian Boyd
@Ian Boyd - Correct. But why would you? http://stackoverflow.com/questions/342433/what-is-going-to-happen-to-our-primitive-types-when-128-bit-processors-come-out/342486#342486
Daniel Earwicker