Use - DLL (PBLibMain)

Category: DLLs

Date: 02-16-2022

Return to Index


 
'This snippet shows how to use the DLL created in the snippet http://gbl_00316 ,
'which uses PBLibMain (instead of LibMain) to manage load/unload actions. Note
'that regardless of whether LibMain or PBLibMain is used, the EXE is the same.
'The DLLs are different, but the EXEs are the same.
 
'Primary Code:
'To use exported Subs/Functions from a DLL, you must Declare each Sub/Function.
'See the snippet ".Declare Syntax" for more information on Declare syntax options. http://gbl_00080
 
'In this case, there are two functions to Declare. Notice the two ways of providing the
'argument list. Once Declared, DLL functions are used just like any other function in the application.
Declare Function FlipCoin LIB "gbsnippets_temp.dllALIAS "FlipCoin" (uLimit As LongAs Long
Declare Function PleaseWait LIB "gbsnippets_temp.dllALIAS "PleaseWait" (DwordStringAs Long
 
 
'Compilable Example:  (Jose Includes)
'Whether LibMain or PBLibMain are used, the compilable EXE example is the same.
'Two DLL functions are Declared, called from the two buttons on the dialog.
'That the DLL uses a PBLibMain function to manage load/unload actions is
'transparent to the user/calling application. In the DLL corresponding to this
'example, the load-DLL code is to simply initialize 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 EXE
#Dim All
%Unicode=1
Declare Function FlipCoin LIB "gbsnippets_temp.dllALIAS "FlipCoin" (uLimit As LongAs Long
Declare Function PleaseWait LIB "gbsnippets_temp.dllALIAS "PleaseWait"(DwordStringAs Long
Global hDlg as Dword, hWait as Dword
 
Function PBMain() As Long
   Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
   Control Add Button, hDlg, 100,"Push", 50,10,100,20
   Control Add Label, hDlg, 110,"<result>", 50,40,100,20
   Control Add Button, hDlg, 120,"Push", 50,70,100,20
   Dialog Show Modal hDlg Call DlgProc
End Function
 
CallBack Function DlgProc() As Long
   If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
      Control Set Text hDlg, 110, Str$(FlipCoin(10))      'here, the function FlipCoin() displays a value of 0-10
   End If
   If CB.Msg = %WM_Command AND CB.Ctl = 120 AND CB.Ctlmsg = %BN_Clicked Then
      hWait = PleaseWait (hDlg, "Please Wait ...")       'displays a centered, popup window with "Please Wait"
      Sleep 2000
      Dialog End hWait
   End If
End Function
 
'gbs_00317
'Date: 03-10-2012


created by gbSnippets
http://www.garybeene.com/sw/gbsnippets.htm