Assume this as your VB6 declaration:-
vb Code:
Private Declare Sub ReadVB6StringArray Lib "PInvokeTestingGround.dll" (strn() As String)
And this as its usage:-
vb Code:
' Dim s(4) As String s(0) = "Pippo" s(1) = "Pluto" s(2) = "Paperino" s(3) = "Minnie" ReadVB6StringArray s
This is what you C++ function should look like:-
c++ Code:
// void _stdcall ReadVB6StringArray(SAFEARRAY **strings) { SAFEARRAY* vbarray =(*strings); ULONG numElements = vbarray->rgsabound[0].cElements; int lbound = vbarray->rgsabound[0].lLbound; BSTR* vbStrings=(BSTR*) vbarray->pvData; // Loops through the strings for(int i=lbound; (i < lbound+numElements);i++) { //Gets the current string BSTR current = vbStrings[i]; } }
Now, I'm not 100% sure that C++ function works since its really a royal pain in my ass to find a way to convert VB's BSTR string into a C string to test reading the strings. But I'm reasonably certain its reading the SAFEARRAY correctly. I'll leave finding a way to convert from a BSTR up to you.




Reply With Quote