I created a C++ DLL, when called from VBA returns SAFEARRAY*.
My VBA Function :
Declare Function GetData_V Lib "xyz.dll" (ByVal path As String, ByVal id As String, ByRef inputArr() As String, ByRef output() As String) As Variant()
My C++ implementation :
SafeArrayLock(*outputArray);
for (LONG i = 0; i < countElements; i++)
{
CComBSTR bstr = CComBSTR(outputCustom[i]);
SafeArrayPutElement(*outputArray, &i, bstr);
}
SafeArrayUnlock(*outputArray);
delete [] outputCustom;
return *outputArray;
Where outputCustom is defined as
outputCustom = new char*[nCount+1];
In VBA when I check the output it shows string as :
1 0 . 9 4 4 9 d 0
2 . 8 3 4 6 d 0
0 . 0 1 1 8 d 0
0 . 6 2 9 9 d 0
0 . 6 2 9 9 d 0
0 . 6 2 9 9 d 0
2 5 . 0 d 0
0 . 0 7 6 4 d 0
1 0 . 9 4 4 9 d 0
2 . 8 3 4 6 d 0
0 . 0 1 1 8 d 0
I debugged the code and checked the values of *outputArray in C++ but everything is fine there, but when I checked my array in VBA it got extra spaces in between each character of each strings.