Skip to main content
Email Password   helpLost your password?

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.

// in your header...


class __declspec(dllexport) CDllTest
{
public:  
  CDllTest(){}
  ~CDllTest(){}

public:
  void SayHello();
};

// in your cpp...


void CDllTest::SayHello()
{
 printf(_T("Hello C++"));
}

That's it! The sample code and project are pretty self explanatory. Enjoy.

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralUsing dll Pin
s_t_r_e_a_m_e_r
2:19 18 Nov '07  
QuestionHow can I use a class exported from a DLL by using LoadLibrary function Pin
zhoujinjun0858
5:22 27 Aug '07  
AnswerRe: How can I use a class exported from a DLL by using LoadLibrary function Pin
afriza
17:44 2 Dec '08  
GeneralGreat! Pin
docrob1
18:48 25 Jan '07  
Generaldelete cuases access violation Pin
tom cruz
3:35 18 Aug '05  
GeneralRe: delete cuases access violation Pin
Igen1
8:14 9 Mar '09  
Generalqn Pin
From_Nepal
9:00 6 Jan '05  
GeneralLoad at runtime Pin
Verifier
5:30 16 Apr '04  
GeneralRe: Load at runtime Pin
ThatsAlok
23:32 20 Apr '06  
GeneralHow to create DllTest.dll and DllTest.lib in VC7.0 Pin
Sctt H. Chang
11:11 31 Mar '04  
GeneralRe: How to create DllTest.dll and DllTest.lib in VC7.0 Pin
Anonymous
0:26 18 Apr '04  
Generalis it mean that regular DLL can replace extension DLL every time? Pin
dalink
7:00 6 Mar '04  
GeneralA slight correction and enhancement Pin
David Pritchard
8:31 29 May '03  
Generalhow to insert a class from MFC to C# Pin
mosgeorge
4:49 13 Apr '03  
GeneralRe: how to insert a class from MFC to C# Pin
Tanzim Husain
21:54 23 Apr '03  
GeneralRe: how to insert a class from MFC to C# Pin
Takeru Koushirou
22:31 27 Jun '04  
GeneralRe: how to insert a class from MFC to C# Pin
charnos
7:49 13 Aug '04  
Generalany Info about Proxy DLL (Trojan DLL) Pin
bfadi
11:24 5 Mar '03  
GeneralRe: any Info about Proxy DLL (Trojan DLL) Pin
Tanzim Husain
22:14 23 Apr '03  
GeneralRe: any Info about Proxy DLL (Trojan DLL) Pin
gypsySUN
19:11 17 Oct '03  
GeneralRe: any Info about Proxy DLL (Trojan DLL) Pin
bfadi
21:42 18 Oct '03  
GeneralRe: any Info about Proxy DLL (Trojan DLL) Pin
gypsySUN
6:27 21 Oct '03  
GeneralRe: any Info about Proxy DLL (Trojan DLL) Pin
bfadi
20:57 21 Oct '03  
GeneralIs your linking truly dynamic, or static? Pin
Lewis McCarthy
11:12 20 Sep '02  
GeneralRe: Is your linking truly dynamic, or static? Pin
Jonte
4:29 23 Oct '02  


Last Updated 5 Jun 2002 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009