1
votes

For my job I need to use a 32 bit c++ dll with a 64bit c# program. I wanted to try doing this using dlls as wrappers.

What I have done for the moment is I made a dll that uses dll import to expose the function of the c++ dll and then make it COM+ enabled to make these functions available in 64 bit.

The problem I am facing is using this COM+ dll. To do it I followed this documentation

I signed it with a strong name, compiled it, registered it using gacutil and then sent it to com+ with Regsvcs. But when I want to use it I need to have a reference about it in my 64 bit app.

I tried to do add reference, select COM and then my class and it tells me that:

the ActiveX type library was exported from a .net assembly and cannot be registered.

If I try to add the tlb file it tells me:

check that the file is accessible and this is an assembly or a valid COM component

If I had the dll as reference, I get a badImageException. My computer is not in English so the messages might not be accurate.

1

1 Answers

0
votes

You cannot load a 32-bit DLL in a 64-bit process (nor the other way around). Wrapping it around COM can only help if the COM server is out-of-proc (i.e. an executable). If it's an in-proc COM server (i.e. a DLL), as I understood from your description, that's not going to work. Your 64-bit process will load the 64-bit COM server and then this will try to load the 32-bit DLL and that will fail. What you need to do is to change the COM wrapper into an out-of-proc server. That will run in its own 32-bit process. Communication with proper data marshaling between the 32-bit and the 64-bit process is done transparently through COM.