Passing VB Arrays
Passing VB Arrays
Can I pass a VB string array into PureBasic?
I want to create a PureBasic DLL that handles arrays created in VB. e.g.
In VB:
Redim MyArray(2) as string
MyArray(0)="one"
MyArray(1)="two"
MyArray(2)="three"
PureBasicFunction MyArray()
Any help would be appreciated, thanks
I want to create a PureBasic DLL that handles arrays created in VB. e.g.
In VB:
Redim MyArray(2) as string
MyArray(0)="one"
MyArray(1)="two"
MyArray(2)="three"
PureBasicFunction MyArray()
Any help would be appreciated, thanks
Last edited by ukandrewc on Tue Oct 05, 2004 9:16 am, edited 1 time in total.
This is how to pass the memory pointer of a VB array of bytes. With strings, it could be different as you must cope with VARIANT type (I think).
Anyway, this could be a good starting point.
VB:
PB:
Anyway, this could be a good starting point.
VB:
Code: Select all
Private Declare Function My_Function Lib "My_dll.dll" (ByRef Array As Byte) As Long
Code: Select all
Dim MyArray(255) As Byte
Dim res As Long
res=My_Function(MyArray(0)) '1st element to pass its memory pointer
Code: Select all
ProcedureDLL My_Function(*mem_pointer)
ProcedureReturn 0
EndProcedure
- SimpleMind
- Enthusiast
- Posts: 112
- Joined: Sun May 18, 2003 12:40 pm
- Location: Netherlands
Thanks Seldon! Your code example did the job. Now I can pass a string from MS-Word 2003 to PureBacis. Now, I'm starting the afterburner.Seldon wrote:This is how to pass the memory pointer of a VB array of bytes. With strings, it could be different as you must cope with VARIANT type (I think).
Anyway, this could be a good starting point.
VB:Code: Select all
Private Declare Function My_Function Lib "My_dll.dll" (ByRef Array As Byte) As Long
PB:Code: Select all
Dim MyArray(255) As Byte Dim res As Long res=My_Function(MyArray(0)) '1st element to pass its memory pointer
Code: Select all
ProcedureDLL My_Function(*mem_pointer) ProcedureReturn 0 EndProcedure
VBA-code:
Code: Select all
Declare Function InitString4 Lib "IS2.dll" (ByRef MyArray As Byte) As Long
Public Sub fromuc()
Dim i As Long
Dim x() As Byte
x = StrConv("ABCDEFG", vbFromUnicode)
a = InitString4(x(0))
End Sub
Code: Select all
ProcedureDLL.l InitString4(*mem_pointer)
MessageRequester("Message from IS2.dll - peeks",PeekS(*mem_pointer))
ProcedureReturn 1
EndProcedure
Give me books, fruit, french wine, fine weather and a little music.
John Keats
John Keats
- Kwai chang caine
- Always Here
- Posts: 5494
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Hello at all
Like usual...i have not understand all the example, for pass an array of string of VB to Pure
I have do this.....but like i never must change a looser team.....
That's don't works
VB Code
Pure Code
Thanks
Like usual...i have not understand all the example, for pass an array of string of VB to Pure

I have do this.....but like i never must change a looser team.....
That's don't works

VB Code
Code: Select all
Private Declare Function InitString4 Lib "c:\MyDll.dll" (ByRef MyArray As Byte) As Long
Private Sub Form_Load()
Dim Tablo(10) As String
Tablo(1) = "Hello...i'm KCC"
Tablo(2) = "i'm locked in VB :-("
Tablo(3) = "and i want to jump in PB :-)"
Dim x() As Byte
x = StrConv(Tablo(1), vbFromUnicode)
a = InitString4(x(0))
End Sub
Code: Select all
ProcedureDLL.l InitString4(*mem_pointer)
Dim Tablo.s(10)
Repeat
Char = PeekB(*mem_pointer + Offset)
Offset + 1
If Char = #LF Or Char = #Null
LineNum + 1
MessageRequester("", Str(LineNum) + ".) " + PeekS(*mem_pointer + Marker, Offset - Marker - 2))
Marker = Offset
EndIf
Until LineNum = 5
EndProcedure

Not a destination
Re: Passing VB Arrays
I'm not sure if it works, because I haven't got VB for ages, but you can try to test this:ukandrewc wrote:Can I pass a VB string array into PureBasic?
I want to create a PureBasic DLL that handles arrays created in VB. e.g.
In VB:
Redim MyArray(2) as string
MyArray(0)="one"
MyArray(1)="two"
MyArray(2)="three"
PureBasicFunction MyArray()
Any help would be appreciated, thanks
VB:
Code: Select all
Dim MyArrayVB(1) as String
Dim MyArrayPB(1) as Long
MyArrayVB(0)="one"
MyArrayVB(1)="two"
MyArrayPB(0)= StrPtr(MyArrayVB(0))
MyArrayPB(1)= StrPtr(MyArrayVB(1))
MyFunctionPB MyArrayPB(0) 'Send pointer to PB DLL function (ByRef)
Code: Select all
ProcedureDLL MyFunctionPB(*ArrayFromVB)
Dim MyArray.s(1)
CopyMemory(*ArrayFromVB, @MyArray(), 2*4)
MessageRequester(MyArray(0), MyArray(1))
EndProcedure
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
- Kwai chang caine
- Always Here
- Posts: 5494
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
@THEARR my savior of VB
Glad to talk to you another time
I have try your method but i have an error "TypeArgument BYREF incompatible" in VB
I have try to change the BYREF in the declaration by a BYVAL but i have another error "out of capacity"
VB Code
PB Code
@KAERU GAMAN
Thanks to explain me, and try to help me
I believe that an array of string, is an array of pointers, only if the array is dynamic like this "Dim Array()" ???
Because like we don't know the len of the variable, we have just the adress of her :roll:
Like this
Array.s(0) = @Array.s(0)
Array.s(1) = @Array.s(1)
Array.s(2) = @Array.s(2)
But when the array is STATIC like this "Dim Array(10)"
The variable is one after other separate by a chr(0)
Like this
Array.s(0) + chr(0) + Array.s(1) + chr(0) + Array.s(2) + chr(0)
I be mistaked ????

Glad to talk to you another time
I have try your method but i have an error "TypeArgument BYREF incompatible" in VB
I have try to change the BYREF in the declaration by a BYVAL but i have another error "out of capacity"

VB Code
Code: Select all
Private Declare Function MyFunctionPB Lib "c:\MyDll.dll" (ByVal MyArray As Byte) As Long
Private Sub Form_Load()
Dim MyArrayVB(1) As String
Dim MyArrayPB(1) As Long
MyArrayVB(0) = "one"
MyArrayVB(1) = "two"
MyArrayPB(0) = StrPtr(MyArrayVB(0))
MyArrayPB(1) = StrPtr(MyArrayVB(1))
MyFunctionPB MyArrayPB(0) 'Send pointer to PB DLL function (ByRef)
End Sub
Code: Select all
ProcedureDLL MyFunctionPB(*ArrayFromVB)
Dim MyArray.s(1)
CopyMemory(*ArrayFromVB, @MyArray(), 2*4)
MessageRequester(MyArray(0), MyArray(1))
EndProcedure
Thanks to explain me, and try to help me

I believe that an array of string, is an array of pointers, only if the array is dynamic like this "Dim Array()" ???

Because like we don't know the len of the variable, we have just the adress of her :roll:
Like this
Array.s(0) = @Array.s(0)
Array.s(1) = @Array.s(1)
Array.s(2) = @Array.s(2)
But when the array is STATIC like this "Dim Array(10)"
The variable is one after other separate by a chr(0)
Like this
Array.s(0) + chr(0) + Array.s(1) + chr(0) + Array.s(2) + chr(0)
I be mistaked ????

Not a destination
You declare MyArray as Long and trying to pass it to the function as Byte, try to change MyFunction declaration.Kwaï chang caïne wrote:I have try your method but i have an error "TypeArgument BYREF incompatible" in VB
I have try to change the BYREF in the declaration by a BYVAL but i have another error "out of capacity"
VB Code
Code: Select all
Private Declare Function MyFunctionPB Lib "c:\MyDll.dll" (ByVal MyArray As Byte) As Long
No, it's the array of pointers to null-terminated strings that are located somethere as Kaeru Gaman has written.Kwaï chang caïne wrote: But when the array is STATIC like this "Dim Array(10)"
The variable is one after other separate by a chr(0)
- Kwai chang caine
- Always Here
- Posts: 5494
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
I'm really a waffer
I have try all solution
And or i have a message of error.....or the VB IDE crash
Some array with chr(0) at the end of each recor
And some array without chr(o) ?????

I have try all solution
Code: Select all
Private Declare Function MyFunctionPB Lib "c:\MyDll.dll" (ByRef MyArray As Long) As Long
Private Declare Function MyFunctionPB Lib "c:\MyDll.dll" (ByRef MyArray As byte) As Long
Private Declare Function MyFunctionPB Lib "c:\MyDll.dll" (Byval MyArray As Byte) As Long
Private Declare Function MyFunctionPB Lib "c:\MyDll.dll" (ByRef MyArray As Long) As Byte
etc .....

Code: Select all
I have also change
Dim MyArrayPB(1) As Long
Dim MyArrayPB(1) As Byte
Oooohh !!! because they are two type of arrayMy savior wrote:No, it's the array of pointers to null-terminated strings that are located somethere as Kaeru Gaman has written.

Some array with chr(0) at the end of each recor
And some array without chr(o) ?????


Not a destination
Try this:
And also declare MyArrayVB and MyArrayPB as global arrays.
Code: Select all
***VB***
Private Declare Sub MyFunctionPB Lib "c:\MyDll.dll" (ByRef MyArray As Long)
***PB***
Dim MyArrayPB(1) as Long
- Kwai chang caine
- Always Here
- Posts: 5494
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
KCC do all the thing that THEARR say to him
VB FORM Code
VB MODULE Code
PB Code
And i obtain a msgbox with a "o" in the titlebar and a "t" in the prompt
When i click ok......VB crash
KCC is very very sad

VB FORM Code
Code: Select all
Private Declare Sub MyFunctionPB Lib "c:\MyDll.dll" (ByRef MyArray As Long)
Public Sub Form_Load()
MyArrayVB(0) = "one"
MyArrayVB(1) = "two"
MyArrayPB(0) = StrPtr(MyArrayVB(0))
MyArrayPB(1) = StrPtr(MyArrayVB(1))
MyFunctionPB MyArrayPB(0) 'Send pointer to PB DLL function (ByRef)
End Sub
Code: Select all
Public MyArrayVB(1) As String
Public MyArrayPB(1) As Long
Code: Select all
ProcedureDLL MyFunctionPB(*ArrayFromVB)
Dim MyArray.s(1)
CopyMemory(*ArrayFromVB, @MyArray(), 2*4)
MessageRequester(MyArray(0), MyArray(1))
EndProcedure

When i click ok......VB crash
KCC is very very sad


Not a destination
Vb uses safearrays.
A good documentation (for all VB-Types )
can be found here:
http://www.codeguru.com/vb/gen/vb_misc/ ... php/c7495/
A good documentation (for all VB-Types )
can be found here:
http://www.codeguru.com/vb/gen/vb_misc/ ... php/c7495/
SPAMINATOR NR.1
- Kwai chang caine
- Always Here
- Posts: 5494
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
@THEARR
Yes KCC again do that the master THEARR say....and KCC move
Now ....it's the same things, but in the title i have "One" and in the prompt i have "two"
And the VB crash
It's better, it's better continue the fight
If you have the same code, who don't crash the RAD....i'm interesting
Because i prefer close the VB with the button "quit"
Thanks for your help
@RINGS
I'm happy because i believe it's the first time i talk to you, since the beginning of the big adventure of "KCC in the land of the programming"
I want to say to you, because i don't have the way before, that you are also one of my hero
But KCC is sad because you are not enough on the forum now.
When i begin to read this forum ...the MASTER RINGS is always...
And now .....
It' the reason why, i'm proud to see one of your answer for me
Obviously ......you have right....i have see this story of "safearrays" somewhere :roll:
But like all the thing that KCC read........KCC not understand
Perhaps my SAVIOR THEARR understand,....... and what you say help him,.... to help me
I wish you a good day
Yes KCC again do that the master THEARR say....and KCC move

Now ....it's the same things, but in the title i have "One" and in the prompt i have "two"

And the VB crash

It's better, it's better continue the fight

If you have the same code, who don't crash the RAD....i'm interesting

Because i prefer close the VB with the button "quit"

Thanks for your help

@RINGS
Hello RINGSRings wrote:Vb uses safearrays.
A good documentation (for all VB-Types )
can be found here:
http://www.codeguru.com/vb/gen/vb_misc/ ... php/c7495/
I'm happy because i believe it's the first time i talk to you, since the beginning of the big adventure of "KCC in the land of the programming"

I want to say to you, because i don't have the way before, that you are also one of my hero

But KCC is sad because you are not enough on the forum now.
When i begin to read this forum ...the MASTER RINGS is always...
And now .....

It' the reason why, i'm proud to see one of your answer for me

Obviously ......you have right....i have see this story of "safearrays" somewhere :roll:
But like all the thing that KCC read........KCC not understand

Perhaps my SAVIOR THEARR understand,....... and what you say help him,.... to help me

I wish you a good day


Not a destination