There may be a possible bug in PowerBASIC's implementation of Fixed-length strings.
Below is the Excel VBA code which calls a PowerBASIC DLL function:
Following is the code for the PowerBasic DLL called by the above Excel VBA code:
Executing the above Excel VBA code always yields a correct display by the PowerBasic DLL of Result0, namely "xc". This correct result is repeatable. The displays for Result1, Result2, and Result3, however, appear to be random text and are not repeatable.
Hopefully the bug is in my code and not in PowerBASIC's implementation of
Fixed-length strings. Your suggestions and corrections will be greatly appreciated. May you have a blessed evening.
Below is the Excel VBA code which calls a PowerBASIC DLL function:
Code:
Declare Function ProcStrArry Lib "C:\PBWin90\MySamples\MySample1.dll" (ByRef x$) As String Sub TestPassStrArrs() Dim MyVarArr(0 To 3) As String ' The following strings have a Fixed length of 2: MyVarArr(0) = "xc" MyVarArr(1) = "SR" MyVarArr(2) = "DI" MyVarArr(3) = "CO" Dim AnswStr As String ' Call the PowerBASIC DLL's ProcStrArry function: AnswStr = ProcStrArry(MyVarArr(0)) MsgBox "AnswStr = " & AnswStr End Sub
Code:
FUNCTION ProcStrArry ALIAS "ProcStrArry" (BYREF x AS STRING) EXPORT AS STRING DIM xPtr AS STRING PTR * 2 ' Using xPtr = VARPTR(x$) gives random non-repeatable displays of Result0 - Result4 ' Let's try: xPtr = STRPTR(x$) ' At least this results in a correct display of Result0. DIM Result0 AS STRING DIM Result1 AS STRING DIM Result2 AS STRING DIM Result3 AS STRING Result0 = @xPtr[0] MSGBOX "Current value of Result0 is: " & Result0 Result1 = @xPtr[1] MSGBOX "Current value of Result1 is: " & STR$(Result1=Result1) Result2 = @xPtr[2] MSGBOX "Current value of Result2 is: " & Result2 Result3 = @xPtr[3] MSGBOX "Current value of Result3 is: " & Result3 FUNCTION = "DONE" END FUNCTION
Hopefully the bug is in my code and not in PowerBASIC's implementation of
Fixed-length strings. Your suggestions and corrections will be greatly appreciated. May you have a blessed evening.
Comment