i am trying to pass an array of struct exported from a c# library to c++ code. the objective is to pass SAFEARRAY of struct from c++ to c#.
I have followed instructions from
but getting this error with the call GetRecordInfoFromTypeInfo
0x80028019 Old format or invalid type library.
If you don't need to have a dispinterface, following should work:
void MyMethod([MarshalAs(UnmanagedType.LPArray, SizeParamIndex=1)] MyStruct[] data, long size);
If you need to use SAFEARRAY, I would expect following to work (but I am not 100% sure, as I don't have Windows machine available at the moment):
void MyMethod([MarshalAs(UnmanagedType.SafeArray, SafeArraySubType=VarEnum.VT_USERDEFINED)] MyStruct[] data);
If you can afford to change your struct
to class
then this will also work, and save you from UDT hassle:
void MyMethod([MarshalAs(UnmanagedType.SafeArray, SafeArraySubType=VarEnum.VT_UNKNOWN)] MyStruct[] data);
Does the struct contains strings? If so, make sure to tag them [MarshalAs(UnmanagedType.BStr)]. There is a limitation in COM: strings in arrays of structs must be BSTRs. TLBExp defaults to LPWSTR and then the call dies. See here: http://msdn.microsoft.com/en-us/library/z6cfh6e6(v=vs.100).aspx
User contributions licensed under CC BY-SA 3.0