How to pass data to C# COM DLL from unmanaged 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
精彩评论