I'm looking at some DLL code and have a question.
I can use PBLibMain or LibMain in a DLL, each having code that will run when the DLL loads and unloads (compilable examples below).
I can see in general that LibMain provides some additional information, but not having written many DLLs, it is not obvious that PBLibMain is to be avoided. On the other hand, I see very little use of PBLibMain in the forums and none at all in the distributed samples, so it appears to be avoided somewhat.
Other than the additional information provided by LibMain, Is there any particular reason to avoid using PBLibMain?
PBLibMain:
LibMain
Executable code (works on both)
I can use PBLibMain or LibMain in a DLL, each having code that will run when the DLL loads and unloads (compilable examples below).
I can see in general that LibMain provides some additional information, but not having written many DLLs, it is not obvious that PBLibMain is to be avoided. On the other hand, I see very little use of PBLibMain in the forums and none at all in the distributed samples, so it appears to be avoided somewhat.
Other than the additional information provided by LibMain, Is there any particular reason to avoid using PBLibMain?
PBLibMain:
Code:
#Compile DLL Function PBLibMain Static i as Long If i Then MsgBox "UnLoading ..." Else MsgBox "Loading ..." End If Incr i Function = 1 End Function Function FlipCoin ALIAS "FlipCoin" (uLimit&) EXPORT As Long Function = Rnd(0,uLimit&) End Function
Code:
#Compile DLL #Include "Win32API.inc" Function LibMain (ByVal hInstance&, ByVal fwdReason&, ByVal lpvReserved&) As Long Select Case fwdReason& Case %DLL_PROCESS_ATTACH MsgBox "loading ..." Function = 1 Case %DLL_PROCESS_DETACH MsgBox "unloading ..." Function = 1 End Select End Function Function FlipCoin ALIAS "FlipCoin" (uLimit&) EXPORT As Long Function = Rnd(0,uLimit&) End Function
Code:
'Compilable Example: #Compile Exe #Dim All Declare Function FlipCoin Lib "gbsnippets_temp.dll" Alias "FlipCoin" (uLimit As Long) As Long Global hDlg 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 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() returns a value of 0-10 End If End Function
Comment