Use a 32-bit COM server from a 64-bit .NET program

I'm having problems with COM Interop, the situation is this:

The 32-bit COM Exe server (which was programmed in C ++) offers a class with some member functions that deal with third-party equipment (this equipment also associates the COM Exe server with 32-bit because the manufacturer does not support 64-bit) .

I want to use a 32-bit COM Exe server in a 64-bit .NET (C #) application ... First I tried to add a link to the Exe Server in Visual Studio 2010 and created an Interop-DLL. This Interop-DLL provided me with the necessary functions, one of which was declared as:

int Initialize(ref string callingApplicationPath);

The original declaration in C ++ is as follows:

LONG Class::Initialize(BSTR* callingApplicationPath)

... and like this in IDL:

[id(1)] LONG Initialize([in] BSTR* callingApplicationPath);

, # Interop-DLL, BadImageFormatException. , Interop-DLL - 32- DLL (, 64- DLL?).

, Exe Server :

Type type = Type.GetTypeFromProgID("OurCompany.Class");
Object o = Activator.CreateInstance(type);
Object[] args = { Marshal.StringToBSTR(str) };
Object result = type.InvokeMember("Initialize", BindingFlags.InvokeMethod, null, o, args);

, , TargetInvocationException (: 0x80020005 (DISP_E_TYPEMISMATCH)) . , , #... StringToXXX , :/, - , , .

!

Christian

+5
3

IDL

[id(1)] LONG Initialize([in] BSTR* str);    

. BSTR in, " ":

[id(1)] LONG Initialize([in] BSTR str);

- # - string , .

, .

+1

.NET COM Interop LPTSTR ++. , ( BSTR) .NET , MarshalAs.

 int Initialize([MarshalAs(UnmanagedType.BStr)] ref string callingApplicationPath);
+1

- , .net, , 32 64 . .net envoirement. , , ( ) 64 . .
32- .net wcf 64- . ++ / wcf , "" clr (#, vb.net ..) .

0
source

All Articles