sloppycode.net
Using windows native DLLs
Static and dynamic loading of a DLL


This example uses the DLL made in the 'Creating a DLL' snippet. It shows how to use both static and dynamic loading of a DLL. Static loading of a DLL means that the DLL is loaded when the application is executed. This is the easier option to dynamic loading, as you'll see, however it means that if the DLL is missing, your program will not run. The external keyword can import procedures and functions in 3 different ways - by actual name, by a numerical value, by renaming. In the example below the procedure is imported using its original name, although the comments show you how to use the other 2 methods. The declaration of the procedure, as you can see in the code, goes after the type declaration. Its also worth noting that the procedures *ARE* case sensitive when you import them - unlike the normal rules of Object Pascal.

Dynamic loading of a DLL load the DLL in your application when it is needed and unload it once you its work is done. It requires more code to use, however it more resource friendly than static loading. The second section of code below shows you how to dynamically load the DLL created in the 'Creating a DLL' snippet. Both bits of code assume that you have done File>New>Application. Both require a single button, the procedure for this is where the 'demoProcedure' procedure is called, in the case of dynamic loading, this is also where the DLL is loaded in, and unloaded.


› Home
› C#
› Snippets
› Articles
› Tools
› Taglines
› ASP
› Dictionary Object
› FSO
› Unix cheat sheet
› Gaming
› CSS
› Yak
› Umbraco
› About
› Contact
› Privacy
› Projects
› Search