This article shows a step by step technique to create your first DLL with VC++.
Steps to create your first DLL
Steps to create your first DLL
- Create a Win32 Dynamic Link Library project
- Go to the workspace explorer. If its not visible in the GUI go to the View menu and click on WorkSpace or use Alt + 0 shortcut to make it visible.
- Go the FileView tab and add a source file (Dll.cpp) and a header file(Dll.h).
- Add following into Dll.h
Code: CPP# include <afxwin.h>
class _declspec(dllexport) CDll
{
public:
void ATestMethod();
}; - Add following into Dll.cpp
Code: CPP#include "dll.h"
void CDll::ATestMethod()
{
AfxMessageBox("CDll::ATestMethod of a dll is invoked");
} - Now create a new Win32 Console application and create it in such a manner that the output folder of both them remains the same so that you dont need to link the dll manually through the lib. Easy way of doing this is create a blank dsp file and insert that into the current workspace. Then add the main.cpp file into the project.
- Add the following code into the main.cpp file
Code: cpp#include "dll.h"
void main()
{
CDll dll;
dll.ATestMethod();
} - Go to Project > Dependencies and set the Win32 console project is dependent on Win32 Dll project

