Windows API

Where are they?

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.

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Walking on water and developing software from a specification are easy if both are frozen.” - Edward V Berard