Restored from previous forum. Originally posted by gnozal.
Some examples of calling a PureBasic DLL from Powerbasic or Rapid-Q :
It works BUT I don't know how to get information back from the DLL (the string passed to the DLL remains unchanged.
************ PureBasic 2.90 ************
ProcedureDLL Toto(Param$)
MessageRequester("Essai DLL", param$, 0)
Param$ = "Toto"+Param$
EndProcedure
************ PowerBasic CC ************
DECLARE SUB EssaiDLL LIB "purebasic.dll" ALIAS "_Toto" (a AS ASCIIZ) ----------> STRING DON'T WORK
FUNCTION PBMAIN()AS LONG
DIM a AS ASCIIZ * 40 -------> STRING don't work
a = "Essai"
PRINT a -------> Essai
CALL EssaiDLL(a) ---------------> MessageResquester OK
PRINT a -------> Essai SHOULD BE TotoEssai
END FUNCTION
************ Rapid-Q ************
DECLARE SUB EssaiDLL LIB "purebasic" ALIAS "_Toto" (Param AS LONG) ----------> STRING DON'T WORK
a$ = "Essai"
print a$ ----------> Essai
CALL EssaiDLL(VARPTR(a$)) ------> NEED TO PASS POINTER (LONG)
print a$ ----------> Essai
************
Calling a PureBasic DLL from PowerBasic or Rapid-Q
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by gnozal.
Fred ?
How can I get information back from a Purebasic DLL (Powerbasic, Rapid-Q, else )?
I can do it with Rapid-Q (main EXE) and PowerBasic(DLL). I would like to use Purebasic for writing DLL's for some of my Rapid-Q progs.
Please help !
Edited by - gnozal on 01 February 2002 11:35:35
Fred ?
How can I get information back from a Purebasic DLL (Powerbasic, Rapid-Q, else )?
I can do it with Rapid-Q (main EXE) and PowerBasic(DLL). I would like to use Purebasic for writing DLL's for some of my Rapid-Q progs.
Please help !
Edited by - gnozal on 01 February 2002 11:35:35
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by gnozal.
Thanks for your answer !
I tried with a pointer, but it didn't work :
************ PureBasic 2.90 ************
ProcedureDLL Toto(Param$)
MessageRequester("Essai DLL", param$, 0)
Param$ = "Toto"+Param$
EndProcedure
************ Rapid-Q ************
DECLARE SUB EssaiDLL LIB "purebasic" ALIAS "_Toto" (Param AS LONG)
Dim a AS STRING, aPointer AS LONG
a = "Essai" : aPointer = VARPTR(a)
print a, aPointer --------> "Essai 30618012"
CALL EssaiDLL(aPointer) --------> messageBox with "Essai"
a = VARPTR$(aPointer)
print a, aPointer --------> "Essai 30618012" (should be "EssaiToto 30618012"!)
************************
Thanks for your answer !
I tried with a pointer, but it didn't work :
************ PureBasic 2.90 ************
ProcedureDLL Toto(Param$)
MessageRequester("Essai DLL", param$, 0)
Param$ = "Toto"+Param$
EndProcedure
************ Rapid-Q ************
DECLARE SUB EssaiDLL LIB "purebasic" ALIAS "_Toto" (Param AS LONG)
Dim a AS STRING, aPointer AS LONG
a = "Essai" : aPointer = VARPTR(a)
print a, aPointer --------> "Essai 30618012"
CALL EssaiDLL(aPointer) --------> messageBox with "Essai"
a = VARPTR$(aPointer)
print a, aPointer --------> "Essai 30618012" (should be "EssaiToto 30618012"!)
************************
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Pupil.
Hi,
one word of advice, PB can't allocate extra memory and pass it to your Powerbasic application(at least i think not, anyone with more experience that can confirm this?), you have to allocate enough memory on the powerbasic side to fit what you add on the PureBasic side. Was that clear or did i just mess things up
What you should try to do is allocate some safe amount of memory for example 1024 bytes or so, and fit the string you're passing in the begining of this memory. Then you pass the pointer to this memory and perhaps one more argument that tells the dll how many bytes it has to work with (in my example 1024). I dont know any PowerBasic or Rapid-Q so regretfully i can't be of more assistance.
Good luck!
Hi,
one word of advice, PB can't allocate extra memory and pass it to your Powerbasic application(at least i think not, anyone with more experience that can confirm this?), you have to allocate enough memory on the powerbasic side to fit what you add on the PureBasic side. Was that clear or did i just mess things up
What you should try to do is allocate some safe amount of memory for example 1024 bytes or so, and fit the string you're passing in the begining of this memory. Then you pass the pointer to this memory and perhaps one more argument that tells the dll how many bytes it has to work with (in my example 1024). I dont know any PowerBasic or Rapid-Q so regretfully i can't be of more assistance.
Good luck!
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by gnozal.
It works if ProcedureDLL is a function :
************** PUREBASIC ****************
ProcedureDLL.s Essai(String.s)
MessageRequester("EssaiDLL",String,0)
ProcedureReturn "TOTO"+String+"TOTO"
EndProcedure
************** RAPID - Q ****************
DECLARE FUNCTION Essai LIB "PureBasic" ALIAS "_Essai" (PtrString AS LONG) AS STRING
DIM a AS STRING, aPtr AS LONG
DIM b AS STRING
a = "ESSAI"
aPtr = VARPTR(a)
PRINT a;"/";aPtr ---------------------> ESSAI/26946660
b = Essai(aPtr) ----------------------> MessageBox "ESSAI"
PRINT a;"/";aPtr;"/";b ---------------> ESSAI/26946660/TOTOESSAITOTO
*****************************************
It works if ProcedureDLL is a function :
************** PUREBASIC ****************
ProcedureDLL.s Essai(String.s)
MessageRequester("EssaiDLL",String,0)
ProcedureReturn "TOTO"+String+"TOTO"
EndProcedure
************** RAPID - Q ****************
DECLARE FUNCTION Essai LIB "PureBasic" ALIAS "_Essai" (PtrString AS LONG) AS STRING
DIM a AS STRING, aPtr AS LONG
DIM b AS STRING
a = "ESSAI"
aPtr = VARPTR(a)
PRINT a;"/";aPtr ---------------------> ESSAI/26946660
b = Essai(aPtr) ----------------------> MessageBox "ESSAI"
PRINT a;"/";aPtr;"/";b ---------------> ESSAI/26946660/TOTOESSAITOTO
*****************************************