Date: 02-16-2022
Return to Index
created by gbSnippets
'Sometimes an application may not find a DLL it needs on the user's
'system, so the programmer would like so loading of the DLL to be
'optional.
'Primary Code:
'Using GetProceAddress/LoadLibrary plus the PBWIN10 Import Addr methods
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile Exe
#Dim All
%Unicode=1
#Include "Win32API.inc"
'Declare Function WinMsg LIB "WINMSG.DLL" ALIAS "WindowMessageA" (ByVal MsgNum As Long) AS String
Declare Function WinMsg (ByVal MsgNum As Long) As String 'take out LIB and ALIAS sections
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
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
Local hLib, procAddress As Dword, Result As String
'New PowerBASIC statement
Import Addr "WindowMessageA", "winmsg.dll" To procAddress, hLib
If (procAddress And hLib) Then
Call Dword procAddress Using WinMsg(%WM_InitDialog) To Result
Import Close hLib
? result
End If
'GetProcAddress Approach
hLib = LoadLibrary("winmsg.dll")
If hLib Then
procAddress = GetProcAddress(hLib, "WindowMessageA") 'use ALIAS
If procAddress Then
Call Dword procAddress Using WinMsg(%WM_InitDialog) To Result 'use Declared name
FreeLibrary hLib
? result
End If
End If
'2nd GetProcAddress Approach
hLib = LoadLibrary("winmsg.dll")
procAddress = GetProcAddress(hLib, "WindowMessageA") 'use ALIAS
If (hLib And procAddress) Then
Call Dword procAddress Using WinMsg(%WM_InitDialog) To Result 'use Declared name
FreeLibrary hLib
? result
End If
End If
End Function
'gbs_00412
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm