DLL function returns pointer to a string

Everything else that doesn't fall into one of the other PB categories.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by mindplay.

I'm calling a function in a DLL, with CallFunction, and it returns a pointer to a string - how do I copy that string into an ordinary string variable so I can print it out?

My idea was to make a little procedure that takes a point as an argument, and returns a string, so I wrote this:

Procedure.s PStr(*str.s)
ProcedureReturn *str.s
EndProcedure

and then I would use it like this:

mystring = PStr(CallFunction(0, "GetDeviceInfo"))

but it won't compile my call to PStr() - it says "bad parameter type, a string is expected" ... but how come a string is expected for PStr, when I've specifically declared the parameter as a POINTER to a string, not just a string??

help, please! thanks :)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by dreamer.

Hi mindplay!

First you have to set a global stringvar out of the ProcedureDLLs. Then you have to return the pointer of this global var und you can get the information with PeekS out of the functioncall. Look at this example:

Code: Select all

GLobal Back.s

ProcedureDLL.l Func(String1.s, String2.s)
  Back.s = String1.s + String2.s
  ProcedureReturn @Back.s
EndProcedure
And than you must call it like this:

Code: Select all

 MyString.s = PeekS(CallFunction(0, "Func", "Hello ", "World!"))
Hope this helps!
Post Reply