Interactive PowerBasic Forum

IT-Consultant: Charles Pegge => OxygenBasic Examples => Topic started by: Charles Pegge on February 04, 2025, 08:50:28 AM

Title: Spitting DLLs
Post by: Charles Pegge on February 04, 2025, 08:50:28 AM

'MAKING A DLL
$ dll
$ filename "t.dll"
uses rtl32 'or rtl64

print "loading dll"

function hello(int a) export as string
  return a*2 " Hello World!"
end function

sub finish() external
  print "unloading dll"
  terminate
end sub

'TEST THE DLL
extern lib "t.dll"
  declare hello(int a) as string
end extern
print hello(123) '246 Hello World!
Title: Re: Spitting DLLs
Post by: Zlatko Vid on February 04, 2025, 09:51:32 AM
Hi Charles
I made few DLLs just to try how work and work well
both 32 or 64 even with old A403 version
Dlls are good if we want to protect our work on easy way  ;)

but i never use

$ DLL ..i think
just
$ filename "myDLL.dll"
Title: Re: Spitting DLLs
Post by: Theo Gottwald on February 04, 2025, 08:45:25 PM
Interesting feature.
How compatible are these with Powerbasic?
Title: Re: Spitting DLLs
Post by: Charles Pegge on February 04, 2025, 10:17:01 PM
Very similar but more wordy. Since 2007 I've forgotten my PowerBasic. Do you have a simple DLL?

o2 has an internal libmain, and if there are no procedures required when the DLL unloads, the Finish procedure is generated internally. So the DLL code can be shortened to:

$ dll
$ filename "t.dll"
uses rtl32 'or rtl64

'print "loading dll"

function hello(int a) export as string
  return a*2 " Hello World!"
end function

PS:

PowerBasic:
'
'https://www.garybeene.com/power/code/gbsnippets0807.htm
'
#Compiler PBWin 9, PBWin 10
#Compile DLL
'
Function LibMain (ByVal hInstance&, ByVal fwdReason&, ByVal lpvReserved&) As Long
   '... load/unload code as needed
End Function
'
Function Hello ALIAS "hello" (Byval i As Long) EXPORT As String
   Function=Str(i*2) + " Hello  World!
End Function