The part 2 of DLL Tutorial explains how to create a regular MFC dll and use it in a client application.
Creating a Regular MFC Dll
Create Skeleton of the Dll
Use MFC AppWizard to create a dll's skeleton.

Select Regular DLL using shared MFC DLL

Click Finish.
Examine the Files
| File |
Description |
| mcRegSrvr.cpp |
WinApp derived class's implementation file |
| mcRegSrvr.h |
Header definition file |
| mcRegSrvr.def |
A definition file |
Adding Functions to the DLL
I will add two functions to the mcRegSrvr.cpp class. It really doesn't matter where you add these functions because these functions are global functions. Function declaration must be in this format:
// Your function
extern "C" __declspec(dllexport) returnValue MyFunctionName( parameters)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// normal function body here
}
AFX_MANAGE_STATE macro is a must.
// AddTwoNumbers function adds two numbers and returns sum of them
extern "C" __declspec(dllexport) long AddTwoNumbers( long num1, long num2)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// normal function body here
return num1 + num2;
}
// MultiplyTwoNumbers function multiplies two numbers and returns the value
extern "C" __declspec(dllexport) long MultiplyTwoNumbers( long num1, long num2)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// normal function body here
return num1 * num2;
}
That's it. Your dll is ready with two functions. Now build and use this dll.
Build the Project and Copy the Dll
Now compile and build the project and copy mcRegSrvr.dll from your Debug directory to the Winnt\System32 ( Windwos\System for Windows 98 ) directory.
A DLL Test Client Program
1. Link to the Library. Copy mcRegSrvr.lib from your Dll's Release ( or Debug ) directory to your test project directory. Or if you don't want to copy the lib file then enter your lib file with the path in Object/library modules text box.
2. Import functions. Import functions using __declspec. Write this code in the beginning of your cpp file.
extern "C" __declspec(dllimport) long AddTwoNumbers( long val1, long val2);
extern "C" __declspec(dllimport) long MultiplyTwoNumbers( long val1, long val2);
3. Call Functions.
int lSum = AddTwoNumbers( 12, 65 );
int lMultiplyRes = MultiplyTwoNumbers(12, 65) ;