Returning Strings to VBA - Is this the right way ?

Just starting out? Need help? Post your questions and find answers here.
User avatar
mk-soft
Always Here
Always Here
Posts: 5405
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Returning Strings to VBA - Is this the right way ?

Post by mk-soft »

You're right. Variant ByRef works correctly with call. :D

Works now
Private Declare PtrSafe Function GetVersion Lib "D:\Daten\Purebasic5\Ablage\ReturnStringTest.dll" () As String
Private Declare PtrSafe Function GetVersionVariant Lib "D:\Daten\Purebasic5\Ablage\ReturnStringTest.dll" (ByRef Version As Variant) As Long
Private Declare PtrSafe Function GetVersionsInfo Lib "D:\Daten\Purebasic5\Ablage\ReturnStringTest.dll" (ByRef Info As Variant) As Long

Sub Schaltfläche1_Klicken()
Dim text As Variant
Call GetVersionVariant(text)
MsgBox text
End Sub

Sub Schaltfläche2_Klicken()
Dim Info As Variant
Dim text
text = ""
If GetVersionsInfo(Info) Then
If IsArray(Info) Then
For i = LBound(Info) To UBound(Info)
text = text & "" & i & ": " & Info(i) & vbNewLine
Next
Else
text = "Info is not an array"
End If
Else
text = "DLL can´t allocate SafeArray"
End If
MsgBox text
End Sub
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply