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