I am currently facing the problem of passing SAFEARRAY (GUID) as the return value from C ++ to C #.
Currently, the C # side uses the Interop library created from Tlbimp.exe (Type library importer).
IDL:
HRESULT GetGuids( [out]SAFEARRAY(GUID)* guids);
I also tried [out, retval]
Function Signature:
HRESULT WINAPI MyClass::GetGuids(SAFEARRAY** guids)
If I use SafeArrayCreate() or SafeArrayCreateVector() :
SAFEARRAY* psa psa = SafeArrayCreate(VT_CLSID, 1, rgsabound);
I get a NULL SAFEARRAY pointer, which should indicate an invalid E_OUTOFMEMORY .
I found that VT_CLSID is only for Ole property sets, not SAFEARRAY: http://poi.apache.org/apidocs/org/apache/poi/hpsf/Variant.html It states that CLSID
I also tried alternative means of building a safe array with: SafeArrayAllocDescriptor() and SafeArrayAllocData() .
hResult = SafeArrayAllocDescriptor(1, guids) hResult = SafeArrayAllocData(*guids);
This allows me to create an array, but when filling it with SafeArrayPutElement() I get HRESULT 0x80070057 (parameter is incorrect). This is probably due to the fact that it accepts the VT_CLSID parameter, as well as
I can fill it manually with SafeArrayAccessData()
GUID* pData = NULL; hResult = SafeArrayAccessData(*guids, (void**)&pData);
but I get an error from C #: "The value does not fall into the expected range"
I'm not sure how to accomplish the desired SAFEARRAY (GUID) return functionality in C # with either the retval or out parameter.
It seems to be simple - there are many areas in the IDL where I already pass the GUID without UDT or sorting. Everything works fine until I need to pass them to SAFEARRAY.
Any help is appreciated, thanks in advance