• Welcome to Jose's Read Only Forum 2023.
 

Using a Purebasic DLL from Powerbasic - Return a STRING to Powerbasic

Started by Theo Gottwald, March 09, 2022, 06:06:07 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Theo Gottwald

Using a Purebasic DLL from Powerbasic is possible.
Yet its not as intuitive as it could be. I will give some examples that help on the Powerbasic Side.

Purebasic will return a STRING to Powerbasic.


Asume this function is in a dll written in Purebasic 32-bit
;---------------------------------------------------------------------- 
; Returns a WSTRING to Powerbasic
  ProcedureDLL.s DName(T03.i)
    Protected S02.s{32768}
   T02=ExamineDesktops()
   If T02>0
     S01=DesktopName(T03)
   Else
     S01="" 
   EndIf
   S02=Trim(S01)
   ProcedureReturn S02
EndProcedure   


On the Powerbasic Side it will look like this:

DECLARE FUNCTION DName LIB "XYZ.DLL" ALIAS "DName" (BYVAL A1 AS DWORD) AS WSTRING   

' This Function is a Sample how to Interface a Purebasic written DLL from Powerbasic
' Returning a STRING
FUNCTION Pure_Get_Desktop_Name(BYVAL U01 AS LONG) AS STRING
  LOCAL W01 AS WSTRING*32768
  LOCAL S01 as STRING
  W01=DName(R02)
  S01=TRIM$(W01)
  FUNCTION=S01
END FUNCTION