I'm trying to pass a VB string array to PB, enlarge it, write to it, and pass it back to VB. Something's not working. Here's the code --
In VB ------
Private Declare Sub enlarge_string_array _
Lib "m:\Power Basic\Lib\Sorting and Searching\main.dll" _
(s() As String)
===================================================
Private Sub Command1_Click()
Dim s() As String
Dim msg As String
Dim i As Integer
ReDim s(0 To 5)
'goto PB --
Call enlarge_string_array(s())
'show results --
For i = LBound(s) To UBound(s)
msg = msg & i & " -- " & s(i) & Chr(10)
Next
MsgBox msg
End Sub
'=======================================================
In PB -------
SUB enlarge_string_array ALIAS "enlarge_string_array" (pSA AS DWORD) EXPORT
DIM LBound_ AS LONG
DIM UBound_ AS LONG
DIM array_address AS DWORD
DIM ret AS LONG
LBound_ = vbArrayLBound(pSA, 1)
UBound_ = vbArrayUBound(pSA, 1)
array_address = vbArrayFirstElem(pSA)
MSGBOX STR$(array_address)
DIM s(LBound_ TO UBound_) AS STRING AT array_address
'try to redim from (0 ... 5) to (0 ... 10) --
ret = vbArrayRedim(pSA, 11)
IF ret = 0 THEN
MSGBOX "problem with vbArrayRedim"
END IF
MSGBOX "after enlargement" 'OK THRU HERE
s(3) = "new value at #3" 'DOESN'T CAUSE A CRASH 'BUT ASSIGNMENT DOES NOT GET BACK TO VB
MSGBOX "after first assignment"
s(7) = "new value at #7" 'CAUSES VB TO CRASH
MSGBOX "after second assignment"
END SUB
In VB ------
Private Declare Sub enlarge_string_array _
Lib "m:\Power Basic\Lib\Sorting and Searching\main.dll" _
(s() As String)
===================================================
Private Sub Command1_Click()
Dim s() As String
Dim msg As String
Dim i As Integer
ReDim s(0 To 5)
'goto PB --
Call enlarge_string_array(s())
'show results --
For i = LBound(s) To UBound(s)
msg = msg & i & " -- " & s(i) & Chr(10)
Next
MsgBox msg
End Sub
'=======================================================
In PB -------
SUB enlarge_string_array ALIAS "enlarge_string_array" (pSA AS DWORD) EXPORT
DIM LBound_ AS LONG
DIM UBound_ AS LONG
DIM array_address AS DWORD
DIM ret AS LONG
LBound_ = vbArrayLBound(pSA, 1)
UBound_ = vbArrayUBound(pSA, 1)
array_address = vbArrayFirstElem(pSA)
MSGBOX STR$(array_address)
DIM s(LBound_ TO UBound_) AS STRING AT array_address
'try to redim from (0 ... 5) to (0 ... 10) --
ret = vbArrayRedim(pSA, 11)
IF ret = 0 THEN
MSGBOX "problem with vbArrayRedim"
END IF
MSGBOX "after enlargement" 'OK THRU HERE
s(3) = "new value at #3" 'DOESN'T CAUSE A CRASH 'BUT ASSIGNMENT DOES NOT GET BACK TO VB
MSGBOX "after first assignment"
s(7) = "new value at #7" 'CAUSES VB TO CRASH
MSGBOX "after second assignment"
END SUB
Comment