Introduction
DLLs are a great way of sharing common pieces of code data between applications. When it comes down to exporting C++ classes from DLLs most of us go for MFC extension DLLs where we can use the AFX_EXT_CLASS
macro to export an entire class. Unfortunately, MFC is no lean and mean class architecture, which means that distributing MFC extension DLLs mean that you have to include the big MFC runtime not to mention the fact that your DLL can only be linked to MFC applications exclusively. What's the solution then? Enter standard Win32 DLLs.
Details
I couldn't believe my eyes on how easily one can export C++ classes directly from a plain vanilla Win32 DLL. Just make one and insert your classes into the DLL. Now simply put __declspec(dllexport)
in between the class keyword and the class name, i.e.
class __declspec(dllexport) CDllTest
{
public:
CDllTest(){}
~CDllTest(){}
public:
void SayHello();
};
void CDllTest::SayHello()
{
printf(_T("Hello C++"));
}
That's it! The sample code and project are pretty self explanatory. Enjoy.