I have a managed function with the following declaration (for both the interface and the implementation):
[return: MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_BSTR)] String[] ManagedFunction() { String[] foo = new String[1]; foo[0] = "bar"; return foo; }
There is also a native C ++ interface with the same methods as the managed interface; inside this interface, this method has the following declaration:
void ManagedFunction(SAFEARRAY* foo);
This function is called by native code as follows:
void NativeFunction(ManagedBinding binding) { CComSafeArray<BSTR> cComSafeArray; cComSafeArray.Create(); LPSAFEARRAY safeArray = cComSafeArray.Detach(); binding.comObject->ManagedFunction(safeArray); }
I'm not sure what I'm doing wrong, but after my managed function was called, safeArray seems to have garbage values, something is wrong when you return the return value back to native code. Can anyone with more experience than me, with the .Net internet, please shed some light on this? Also, it might be appropriate to mention that I had no problem returning a ValueType from my managed function ( boolean , if you're interested), something about returning a String array is a mess. Thanks!
source share