2
votes

What happens when you use CoCreateInstance to create a managed code COM object from 64-bit unmanaged code.

I have a dll that wraps log4net providing a COM interface. I'm calling CoCreateInstance and it is returning a class not registered error. I've ran regasm on the dll and I see entries appearing in the register. I suspect this is some sort of 32/64 bit mismatch. I assumed that the managed dll is JIT'ed x64 when called from a 64 bit dll. Does anyone know what happens when creating a managed COM object from a 64 bit dll? Any advice on what to check, things seem to work with a 32 bit dll.

Thanks

1
There are 4 versions of Regasm.exe, v2 vs v4 and 32-bit vs 64-bit. You have to use the right one, a blind guess when you post this little info.Hans Passant

1 Answers

2
votes

It's a classic 32/64 mismatch problem.

What you want to do is register your .NET DLL with the 64-bit .NET runtime. Use the "regasm /tlb /codebase" in "c:\windows\microsoft.net\framework64\vXYZ\regasm.exe" where XYZ is the version.

If you search for the CLSID of the object in your .NET class, you will find it in the HKEY_CLASSES_ROOT\Wow6432Node\CLSID hive, but not in HKEY_CLASSES_ROOT\CLSID hive. After you register it with the 64 bit tools, then you will find your CLSID in HKEY_CLASSES_ROOT\CLSID.

You may also want to look at this answer: Class not registered error for Instantiation of C# object via COM from VC++