Win32 Static DLL |
Introduction |
A Dynamic Link Library (DLL) is a program that holds one or more functions or some functionality that other programs can use (that's the shortest definition I could come up with...). As such, you can create one DLL and use it in many programs or even distribute it to other programmers (because a DLL is usually treated as an "executable" program, you cannot e-mail it to somebody as an attachment; most e-mail programs would not carry it). Most of the time, a DLL is just a file that has the extension .dll but it could also have another extension. The DLL we are going to create can be used in any program that uses MFC. Unfortunately, and based on my experience, you should not distribute it to people who are using other compilers such as Borland C++ Builder or Dev-C++. In reality you can. Because they will not be able to simply "plug" it in their programs, apparently there are some things they can do to make it work. I cannot cover that. In fact, the only reason I am writing this is because I can't believe how hard it is to find this information, whether in books or on the Internet; people who write books either assume that everybody knows how to create a DLL or they simply don't know, which is incredible considering, as you will see soon, how easy this thing is (I myself looked for it in many places, to no avail).
To start, we need a project that would carry the DLL.
|
|
Coding the DLL |
To make this project a little useful for our learning process, we will use two types of functions: those that are used internally by the DLL only, and those that can be used by external functions, that is, the other programs that will need this DLL.
|
Selecting the DLL |
At this time, the DLL is ready. Probably the easiest way to use a DLL you have created is to create a program in the same folder and test it. To make it more fun, we will use our DLL in a separate program on another folder. the technique we will use is the same you would use if you want to create a program in the same folder the DLL project was created.
|
Using the DLL in a Console Application |
The DLL we have created can be used in a Console application or an MFC program. We will start with a console application.
|
Using the DLL in an MFC Application |
We will proceed with the same ease to use our DLL in an MFC application.
|
|
||
Home | Copyright © 2002-2006 FunctionX | FunctionX |
|