Page 1 of 1
Posted: Tue Oct 22, 2002 2:19 pm
by BackupUser
Restored from previous forum. Originally posted by Kendrel.
I have tried using a dll i made with pb inside my visual basic project i have to do for school, but i cant get it to work properly.
i have also looked at the dll sample code that comes with pb, but it seems that vb doesnt free the dll after it has called it (i guess you have to do this!)
PLEASE if someone could post or upload some working PB/VB code, it would be very nice since i dont have a clue about pb dlls
thx in advance!
Posted: Tue Oct 22, 2002 5:54 pm
by BackupUser
Restored from previous forum. Originally posted by Rings.
Okay here it goes.First DLL Example in PureBasic:
Code: Select all
Global BackString.s
ProcedureDLL EasyRequester(Message$)
MessageRequester("EasyRequester !", Message$, #MB_ICONINFORMATION)
ProcedureReturn Len(Message$)
EndProcedure
ProcedureDLL EasyString(Message$)
MessageRequester("EasyString !", Message$, #MB_ICONINFORMATION)
BackString="1234"+Message$
ProcedureReturn @Backstring.s
EndProcedure
and now the VBCode for it (paste it in a form with a CommandButton
and change path for dll if needed:
Code: Select all
Private Declare Function EasyRequester Lib "c:\Purebasic\Compilers\Purebasic.dll" (ByVal Message As String) As Long
Private Declare Function EasyString Lib "c:\Purebasic\Compilers\Purebasic.dll" (ByVal Message As String) As Long 'String
Private Declare Function lstrcpy Lib "Kernel32.dll" (ByVal MyString As String, ByVal MyLong As Long) As Long
Private Sub Command1_Click()
Dim Result As Long
Dim MyString As String
Dim Pointer As Long
Result = EasyRequester("Test")
MsgBox Str(Result)
Pointer = EasyString("Test")
MsgBox Str(Pointer)
MyString = Space(255)
Res = lstrcpy(MyString, Pointer)
MsgBox MyString
End Sub
as you see you have to deal with the Pointer to the string.
in Pure you can easily use PeekS(Zeiger)
Its a long way to the top if you wanna .....CodeGuru
Posted: Wed Oct 23, 2002 2:55 pm
by BackupUser
Restored from previous forum. Originally posted by Kendrel.
Thank you very much!
After all i should be able so solve most of my problems now...
there is only one question left on my list
how would i pass an array from vb to pb and pass the array back from pb to vb
Some good people in the forums told me that you would have to use memory banks to do this, but a working example about this would be veeeeery nice!
thank you so much,
Kendrel
Posted: Wed Oct 23, 2002 3:40 pm
by BackupUser
Restored from previous forum. Originally posted by Rings.
vb's arrays are completly different than Pure's one.
Use a Memoryspace or Bytearray() or similar like that.
Try with Pointers.Use your brain!
On the other hand, i never had the use to pass arrays back.
Its a long way to the top if you wanna .....CodeGuru