How to pass data to C# COM DLL from unmanaged application

3

ะก# COM DLL Interface:

public interface IShowDialog
{
   void showMessage(byte[] array);
}

and call it in unmanaged C++ application:

SAFEARRAY *array;

array = SafeArrayCreateVector(VT_BSTR, 0, 1);

long lidx = 0;

SafeArrayPutElement( array, &lidx, SysAllocString(L"test") );

hr = dlg->showMessage(array);

Result: 0x80131533 - COR_E_SAFEARRAYTYPEMISMATCH

c#
c++
dll
com
asked on Stack Overflow May 20, 2011 by nen777w • edited May 20, 2011 by Hazem Farahat

1 Answer

4

The COM interface needs to be called from native code with a SAFEARRAY whose contents are VT_I1 instances. You are providing instead VT_BSTR values and hence receiving the error.

You need to convert the string value into VT_I1 values and put those into the array.

EDIT

The proper in C++ name is VT_I1 and not VT_BYTE

answered on Stack Overflow May 20, 2011 by JaredPar • edited May 20, 2011 by JaredPar

User contributions licensed under CC BY-SA 3.0