Page 1 of 1

Crossplatform DLL with string parameters

Posted: Tue Mar 18, 2025 3:22 pm
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

Re: Crossplatform DLL with string parameters

Posted: Tue Mar 18, 2025 4:56 pm
by Fred
I would advice the 2nd case then as the 1st will only accept UTF-16 strings for all plateforms.

Re: Crossplatform DLL with string parameters

Posted: Tue Mar 18, 2025 10:37 pm
by Justin
Ok, thanks