Click here to Skip to main content
14,455,761 members

Exporting C++ classes without using MFC extension DLL

Rate this:
3.72 (37 votes)
Please Sign up or sign in to vote.
3.72 (37 votes)
5 Jun 2002
This article describes the process of exporting regular C++ classes without using MFC extension DLLs

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Tanzim Husain
Web Developer
United States United States
No Biography provided

Comments and Discussions

 
Questiondll Pin
mouass29-Mar-15 23:42
Membermouass29-Mar-15 23:42 
QuestionI got lilnker error LN2019 Pin
Vivek_Mendse10-Nov-11 19:52
MemberVivek_Mendse10-Nov-11 19:52 
QuestionReally - that simple? Pin
Vaclav_4-Feb-11 9:48
MemberVaclav_4-Feb-11 9:48 
GeneralUsing dll Pin
s_t_r_e_a_m_e_r18-Nov-07 2:19
Members_t_r_e_a_m_e_r18-Nov-07 2:19 
QuestionHow can I use a class exported from a DLL by using LoadLibrary function Pin
zhoujinjun085827-Aug-07 5:22
Memberzhoujinjun085827-Aug-07 5:22 
AnswerRe: How can I use a class exported from a DLL by using LoadLibrary function Pin
afriza2-Dec-08 17:44
Memberafriza2-Dec-08 17:44 
GeneralGreat! Pin
docrob125-Jan-07 18:48
Memberdocrob125-Jan-07 18:48 
Generaldelete cuases access violation Pin
Member 134871718-Aug-05 3:35
MemberMember 134871718-Aug-05 3:35 
GeneralRe: delete cuases access violation Pin
Igen19-Mar-09 8:14
MemberIgen19-Mar-09 8:14 
Generalqn Pin
From_Nepal6-Jan-05 9:00
sussFrom_Nepal6-Jan-05 9:00 
GeneralLoad at runtime Pin
jgauffin16-Apr-04 5:30
Memberjgauffin16-Apr-04 5:30 
GeneralRe: Load at runtime Pin
ThatsAlok20-Apr-06 23:32
MemberThatsAlok20-Apr-06 23:32 
QuestionHow to create DllTest.dll and DllTest.lib in VC7.0 Pin
Sctt H. Chang31-Mar-04 11:11
MemberSctt H. Chang31-Mar-04 11:11 
AnswerRe: How to create DllTest.dll and DllTest.lib in VC7.0 Pin
anonymous1218-Apr-04 0:26
Memberanonymous1218-Apr-04 0:26 
Questionis it mean that regular DLL can replace extension DLL every time? Pin
dalink6-Mar-04 7:00
Memberdalink6-Mar-04 7:00 
GeneralA slight correction and enhancement Pin
David Pritchard29-May-03 8:31
MemberDavid Pritchard29-May-03 8:31 
Questionhow to insert a class from MFC to C# Pin
mosgeorge13-Apr-03 4:49
Membermosgeorge13-Apr-03 4:49 
AnswerRe: how to insert a class from MFC to C# Pin
Tanzim Husain23-Apr-03 21:54
MemberTanzim Husain23-Apr-03 21:54 
AnswerRe: how to insert a class from MFC to C# Pin
Takeru Koushirou27-Jun-04 22:31
MemberTakeru Koushirou27-Jun-04 22:31 
GeneralRe: how to insert a class from MFC to C# Pin
charnos13-Aug-04 7:49
Membercharnos13-Aug-04 7:49 
Generalany Info about Proxy DLL (Trojan DLL) Pin
Fad B5-Mar-03 11:24
MemberFad B5-Mar-03 11:24 
GeneralRe: any Info about Proxy DLL (Trojan DLL) Pin
Tanzim Husain23-Apr-03 22:14
MemberTanzim Husain23-Apr-03 22:14 
GeneralRe: any Info about Proxy DLL (Trojan DLL) Pin
gypsySUN17-Oct-03 19:11
MembergypsySUN17-Oct-03 19:11 
GeneralRe: any Info about Proxy DLL (Trojan DLL) Pin
Fad B18-Oct-03 21:42
MemberFad B18-Oct-03 21:42 
GeneralRe: any Info about Proxy DLL (Trojan DLL) Pin
gypsySUN21-Oct-03 6:27
MembergypsySUN21-Oct-03 6:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Article
Posted 5 Jun 2002

Stats

237.7K views
5K downloads
50 bookmarked