Date: 02-16-2022
Return to Index
created by gbSnippets
'This snippet is 2 of 4 covering DLL creation, in this case a DLL which
'demonstrates the use of PBLibMain, instead of LibMain, for incorporating DLL
'startup/shutdown actions. PBLibMain requires no arguments and will be run
'at load/unload in the same fashion as LibMain.
'Check out the background information on DLLs at http://gbl_00320
'Primary Code:
'This code shows using the #Compile DLL to direct the compiler to create
'a DLL rather than an EXE. It shows the use of PBLibMain (alternative to
'LibMain) that is called when the DLL is loaded and when it is unloaded.
'It also shows the use of two exported functions.
#Compile DLL
Function PBLibMain
'... load/unload code as needed
Function = 1 'required or DLL will not load
End Function
Function FlipCoin ALIAS "FlipCoin" (uLimit&) EXPORT As Long 'exported function
'... see details in compilable example below
End Function
Function PleaseWait ALIAS "PleaseWait" (hParent as Dword, wMsg$) EXPORT As Long 'exported function
'... see details in compilable example below
End Function
'Compilable Example: (Jose Includes)
'Using the compiler directive #Compile DLL is the key line, telling the
'compiler to create a DLL rather than an EXE. In this example, the
'DLL has two exported functions, accessible from the two buttons on the
'main dialog. In this case, a PBLibMain function manages load/unload actions.
'The load-DLL code is simply initializes an array. The unload-DLL code saves
'the values to a file. Load/unload actions take place unprompted by the user.
#Compiler PBWin 9, PBWin 10
#Compile DLL
%ID_Label = 500
Global MyArray() As String
Function PBLibMain
Static i as Long
Local j as long
If i Then
'run this on unload - save the array to a file
Open "myfile.txt" For Output as #1
Print #1, Join$(MyArray(), $crlf)
Close #1
Else
'run this on load - initialize an array
Dim MyArray(100)
For j = 0 to UBound(MyArray) : MyArray(j)=Str$(Rnd(1,100)) : Next j
End If
Incr i
Function = 1 'required or DLL will not load!
End Function
Function FlipCoin ALIAS "FlipCoin" (uLimit&) EXPORT As Long
Function = Rnd(0,uLimit&)
End Function
Function PleaseWait ALIAS "PleaseWait" (hParent as Dword, wMsg$) EXPORT As Long
Local x As Long, y As Long, w As Long, h As Long, wX As Long, wY As Long, hWait as Long
Dialog Get Client hParent To w,h
wX = 150 : wY = 60 'size of popup dialog
x = (w-wX)/2 'gets left position of WaitDialog to center over app
y = (h-wY)/2 'gets top position of WaitDialog to center over app
Dialog New Pixels, hParent, "", x, y, wX, wY, %WS_Popup To hWait
Control Add Label, hWait, %ID_Label, wMsg$, 0, 0, wX, wY, %SS_Center Or %SS_CenterImage Or %WS_Border
Control Set Color hWait, %ID_Label, %Black, %White
Dialog Show Modeless hWait
Function = hWait
End Function
'gbs_00316
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm