equivalent of c strings in pure basic

Just starting out? Need help? Post your questions and find answers here.
rory-games
User
User
Posts: 39
Joined: Sun Feb 02, 2020 9:14 am
Contact:

equivalent of c strings in pure basic

Post by rory-games »

Hello,
It's been a while since using this language, so I apologize if this is a silly question, but I can't find immediately available information regarding this.
I'm calling a DLL from pure basic. In this instance, I need to use char* as parameters and sometimes as the return value of procedures as well. Should I use .s for this or something else?
Is this legal or do alternative methods need to be used?
In conclusion: what is pb's direct equivalent of c's char* when calling functions from a c dll?
Thanks,
Rory Michie.
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: equivalent of c strings in pure basic

Post by idle »

if you import a function from a lib that want's a string parameter and it doesn't work as expected you will generally want to use p-utf8 or p-Ascii. The pseudo types convert to or from PB's UCS2 format

Code: Select all

ImportC "some.lib" 
some_function(inputStr.p-utf8,*outPut.p-utf8) 
Endimport  
rory-games
User
User
Posts: 39
Joined: Sun Feb 02, 2020 9:14 am
Contact:

Re: equivalent of c strings in pure basic

Post by rory-games »

Hello,
Thanks for the response, this is what I was looking for!
Well, really there is only one more piece I think: how does one convert a pointer at a p-ascii back into a regular string?
Thanks,
Rory Michie.
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: equivalent of c strings in pure basic

Post by idle »

if the return type is a string then you need to use peeks(*ptr,-1,#PB_UTF8)
and if it's a parameter use *ptr.p-utf8
rory-games
User
User
Posts: 39
Joined: Sun Feb 02, 2020 9:14 am
Contact:

Re: equivalent of c strings in pure basic

Post by rory-games »

Thanks very much again! I see how this works now.
Post Reply