Optional DLL

Category: Apps/Dialogs

Date: 07-21-2011

Return to Index


 
'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:
 
 
 
'Compilable Example:
#Compile Exe
#Dim All
#Include "Win32API.inc"
'Declare Function WinMsg LIB "WINMSG.DLL" ALIAS "WindowMessageA" (BYVAL MsgNum AS LONG) AS String
Declare Function WinMsg (ByVal MsgNum As LongAs 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 As DWord, pAddress As DWord, Result As String
      If IsFile("winmsg.dll") Then
         hLib = LoadLibrary("winmsg.dll")
         pAddress = GetProcAddress(hLib, "WindowMessageA")    'use ALIAS
         Call DWord pAddress Using WinMsg(%WM_InitDialog) To Result  'use Declared name
         FreeLibrary hLib
         MsgBox Result
      End if
   End If
End Function
 
'gbs_00412


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