Crossplatform DLL with string parameters

Just starting out? Need help? Post your questions and find answers here.
Justin
Addict
Addict
Posts: 948
Joined: Sat Apr 26, 2003 2:49 pm

Crossplatform DLL with string parameters

Post by Justin »

Let's say i want to build a crossplatform dll with a function that accepts a string as a parameter.
The dll will be called from another language like C or objective-c for example.
Wich kind of string expects PB on the three paltforms?,
Passing this will work?
LPWSTR windows
const char* linux
const char* macos
For a dll like this, declaring a as s converts the string to a PB string?

Code: Select all

ProcedureDLL test(a.s)
	MessageRequester("Hello", a)
EndProcedure
Or do i need to do something like:

Code: Select all

Procedure.s GetString(a.i)
	CompilerIf #PB_Compiler_OS = #PB_OS_Windows
		ProcedureReturn PeekS(a)
		
	CompilerElseIf #PB_Compiler_OS = #PB_OS_Linux
		ProcedureReturn PeekS(a, -1, #PB_UTF8)

	CompilerElseIf #PB_Compiler_OS = #PB_OS_MacOS
		ProcedureReturn PeekS(a, -1, #PB_UTF8)
	CompilerEndIf
EndProcedure

ProcedureDLL test(a.i)
	MessageRequester("Hello", GetString(a))
EndProcedure
Fred
Administrator
Administrator
Posts: 18247
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Crossplatform DLL with string parameters

Post by Fred »

I would advice the 2nd case then as the 1st will only accept UTF-16 strings for all plateforms.
Justin
Addict
Addict
Posts: 948
Joined: Sat Apr 26, 2003 2:49 pm

Re: Crossplatform DLL with string parameters

Post by Justin »

Ok, thanks
Post Reply