This article shows a step-by-step technique to create your first DLL with VC++.
Steps to Create Your First DLL
- Create a Win32 Dynamic Link Library project, adding a *.cpp and a *.h file.
- In the *.cpp file, create a class instantiated from the
# include <stdafx.h>
# include "SourceFile.h"
class CDllApp : public CWinApp
- In the *.h file (here it is SourceFile.h), define the functions to be used. Also specify the
dllexport value for the
extern "C" _declspec(dllexport) int Calc(char no1,char no2)
result = no1 + no2;
- Then compile the DLL.
- Create a normal Win32 Application with a *.cpp file and a *.h file.
- In the *.h file, (here it is AppHeader.h ), declare the function with the
dllimport value of
extern "C" _declspec(dllimport) Calc(int FirstValue,
- In the *.cpp file, use the function.
# include "AFXWIN.H"
# include "AppHeader.h"
class MainFrame : public CFrameWnd
void OnLButtonDown(UINT nFlags,CPoint point)
res = Calc(998,226);
- In the Link tab of the "Project->Settings" dialog, go to the text box labeled "Object / Library Modules" and specify the path of the DLL file. Then copy the compiled DLL file to your current appliation path directory and run the program.
Some Things to Note
The DLL file may not be visible due to the File View options in the Windows folder. So, you can either go to the DOS prompt and copy the file or enable the setting "Show all files" in Windows Explorer to copy the file. To create a DLL that uses MFC, see the following example. Note that extern "C" has not been used and the macro
AFX_MANAGE_STATE(AfxGetStaticModuleState()); has been used to implement MFC.
_declspec(dllexport)CString Display(CString a,CString b)
Str = a + b;
That's all, folks. All luck and have a great time.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.