Standard Windows DLL's, such as Kernel32.dll and User32.dll are usually located in either the Windows directory, or the Windows System Directory. They are also sometimes installed in the same directory as your application. When you declare a Windows API function, windows will search in a number of places. The first is the Windows and System directory. If the specified DLL is not found there, then it looks in the same folder of your application. If it is not found there then it searches the current directory. You can see that windows tries very hard to find the DLL you have specified. However, if it does not find the required DLL, it will chuck up a nasty error when you first attempt to use it.
If the DLL is in none of the default locations, and you know where it is, then you can specify the path in the DLL Name parameter. In some circumstances, you will find that you do not know the location of the DLL until run time. If this is the case, there is one work around, using the fact that windows searches the current directory. You can use the following code:
'// save the current directory
strOldCurDir = CurDir$
'// change the current directory to the location of the DLL
'// in this case, the support folder, which is a sub folder of
'// the folder the application is installed in.
'// ie C:Program FilesAppNamesupport
ChDir (App.Path & "support")
'// call the DLL for the first time
lngResult = DLLName(Parameter1, Parameter2)
'// restore the current directory
ChDir (strOldCurDir)
You could write a simple function that automatically checks if the DLL has been called yet, and if not, then run the above code.
Comments