Author Topic: Using a Purebasic DLL from Powerbasic - Return a STRING to Powerbasic  (Read 590 times)

0 Members and 1 Guest are viewing this topic.

Offline Theo Gottwald

  • Administrator
  • Hero Member
  • *****
  • Posts: 1081
  • User-Rate: +30/-4
  • Gender: Male
    • it-berater
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.

Code: [Select]
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:

Code: [Select]
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