Using a 32 bit unmanaged COM server in a 64 bit .NET application

3

I need to use a 32 bit unmanaged COM server in a 64 bit .NET application.

I did some research and it seemed that I found a suitable solution: hosting the COM server in a COM+ server application. So the component is activated in a dedicated (32 bit) process and it communicates with the 64 bit process via RPC. (link)

To test the above, I created a sample COM server and registered it in a COM+ application. Its interface looks like this:

interface ITestComObj: IUnknown
{
  HRESULT _stdcall Ping( void );
  HRESULT _stdcall Uppercase([in] LPSTR input, [out, retval] LPSTR * output );
};

Then I created a simple .NET console application that calls these methods via COM interop.

First I tested it on a 32 bit WinXP and it worked fine.

Then I moved to a 64 bit Win7. The first call (to the parameterless Ping() method) was successful, but the second call threw an exception (after some waiting): the remote procedure call failed. (Exception from HRESULT: 0x800706BE).

I did some further investigations. I forced the client into a 32 bit process (built it to x86 target platform) to see if anything changes, but the result was the same. However, if I switched to in-process activiation (changed the COM+ application type to library application), the client worked.

Obviously, something with the cross-process parameter passing is going wrong on Win7, but I couldn't find the answer even after googling for hours.

Any ideas?

.net
com
64-bit
com-interop
unmanaged
asked on Stack Overflow Jul 13, 2011 by luc • edited May 23, 2017 by Community

2 Answers

0

The problem is with marshalling - the interop layer for whatever reason can't properly marshal the second call parameters. I suggest you change the signature to use arrays with size_is attribute.

answered on Stack Overflow Jul 14, 2011 by sharptooth
0

I thing the problem could be in the marshalling of string types. I would try using:

HRESULT _stdcall Uppercase([in] BSTR input, [out, retval] BSTR * output );

instead of

HRESULT _stdcall Uppercase([in] LPSTR input, [out, retval] LPSTR * output );
answered on Stack Overflow Aug 1, 2011 by yms

User contributions licensed under CC BY-SA 3.0