It's recommended to understand the
Static Link Library's Tutorial.
As explained in the
Static Link Library's Tutorial as Library can store alot
of information in 1 file and so i won't go further into this, Let's focus on DLL's instead.
DLL's are the same as SLL's but DLL's are called upon during Run-Time instead of Compile-Time,
This means the user will always have to have the DLL's used in the program to run it.
The main advantage of DLL's are that you can replace them with newer versions and thus update your
program without having to re-release it.
Creating DLL's with VC++ 6.0:
Quote:
Create a new Project, Select the Project Type as DLL Dynamic Link Library.
|
Creating DLL's with VC++ .NET:
Quote:
Create a new Project, Select "Win32 Application" as the Project Type, Select "Application Settings",
Select "DLL" under "Application Type", Select "Empty Project" as "Additional Options".
|
Now creating a DLL, We will create 2 DLL's to demonstrate how you can replace one with another to
update your Application.
First DLL:
Code:
#include <iostream> // Include the newest input-output stream header
using namespace std; // So we won't have to specify this namespace to use it's functions
__declspec(dllexport)void HelloMessage(void) /* Here we define the function, Notice what's before it's definition, This way
The compiler knows this function is going to be exported by means of a DLL*/
{
cout << "Hello World!" << endl; // A nice message
}
Second DLL:
Code:
#include <iostream> // Include the newest input-output stream header
using namespace std; // So we won't have to specify this namespace to use it's functions
__declspec(dllexport)void HelloMessage(void) /* Here we define the function, Notice what's before it's definition, This way
The compiler knows this function is going to be exported by means of a DLL*/
{
cout << "Hello You!" << endl; // Another nice message
}
The Console test Program:
Code:
#pragma comment(lib,"test.lib") /* We need to include the produced library that came along with the DLL because
the compiler needs the info of the function's at Compile-Time */
#include <iostream> // Include the newest input-output stream header
#include <conio.h>
using namespace std; // So we won't have to specify this namespace to use it's functions
__declspec(dllexport)void HelloMessage(void); /* The function that is stored in the DLL, We need to define that
because the program won't know this function until Linking-Time */
int main(void) // The program's entry point
{
HelloMessage();
getch(); // Prevent the program from exiting premature
return 0; // Return succes
}
Now i've excuted the test program first the first DLL in the same directory wich produced "Hello World!" and then the
second wich produced "Hello You!".
Now DLL's are quite compiler specific so it might be that some compilers don't support it or don't work with this
tutorial, The code in this Tutorial has been tested with VC++ 6.0 and VC++ .NET, Feel free to ask any question about the
tutorial or DLL's.