开发者

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

开发者 https://www.devze.com 2023-03-07 03:22 出处:网络
С# COM DLL Interface: public interface IShowDialog { void showMessage(byte[] array); } and call it in unmanaged C++ application:

С# 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, SysAllocS开发者_JS百科tring(L"test") );

hr = dlg->showMessage(array);

Result: 0x80131533 - COR_E_SAFEARRAYTYPEMISMATCH


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

  • http://msdn.microsoft.com/en-us/library/cc235118(v=PROT.10).aspx
0

精彩评论

暂无评论...
验证码 换一张
取 消