The GetDllExist() function checks if a Dll has already been loaded or not. If the DLL has been loaded, GetDllExist will return the Index of this dll, if not, then it returns a zero.
FACTS:
* You can only use GetDllExist() with standard DLLs. See NewAx for ActiveX/COM DLLs
Mini Tutorial #1:
This example uses the GetDllExist function to pre-screen if a dll has already been loaded into PlayBASIC's memory.
Filename$="user32.dll" ; Open This Dll once DllIndex1=OpenMyDll(Filename$) ; Open this Dll Twice DllIndex2=OpenMyDll(Filename$) ; Display the DLL indexes. Both indexes should be the same ; as previous we've tried to load the same dll twice Print DllIndex1 Print DllIndex2 ; Display the screen and wait for a key to be pressed Sync WaitKey ; This Function loads a dll into memory. ; before loading the DLL though, the Function uses ; GetDllExist to check if this dll has been previuosly ; loaded. If the DLL isn't currently loaded, ; it grabs a free index and loads the DLL, otherwise ; it just returns the previously loaded index. Function OpenMyDll(Filename$) DllIndex=GetDllExist(filename$) If DllIndex=0 DllIndex=LoadNewDll(Filename$ EndIf EndFunction DllIndex |
This example would output.
Mini Tutorial #2:
This example shows how to toggle the visibility of the mouse cursor using Windows' user32.dll.
Filename$="User32.dll" ; Check if the DLL file has been loaded ? If GetDllExist(Filename$) =0 Print "Loading DLL" ; Ask PlayBASIC for a currently Free DLL index. User32 = GetFreeDll() ; Use this index to load the user32.dll LoadDll "user32.dll", User32 EndIf ; Check if function "ShowCursor" exists in this DLL If GetDllCallExist(user32,"ShowCursor") = 1 Print "Calling Function 'ShowCursor' from this dll" Print "" ; "ShowCursor" only expects one parameter: ; passing 1 will show the mouse, 0 will hide it Print "Hiding Mouse POinter" ; Hide the mouse cursor CallDll(user32,"ShowCursor",0) Print "Press any key to show the mouse pointer again" Sync WaitKey : WaitNoKey ; Show the mouse cursor CallDll(user32,"ShowCursor",1) Print "The mouse is back." Print "" Else Print "SOrry this function doesn't exist in this dll" EndIf Sync WaitKey ; Delete the DLL from memory DeleteDll user32 |
This example would output. Loading DLL Calling Function 'ShowCursor' from this dll Print "Hiding Mouse POinter" Print "Press any key to show the mouse pointer again" Print "The mouse is back." |
|