Click here to Skip to main content
Click here to Skip to main content

Exporting C++ classes without using MFC extension DLL

By , 5 Jun 2002
 

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

About the Author

Tanzim Husain
Web Developer
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionI got lilnker error LN2019memberVivek_Mendse10 Nov '11 - 18:52 
QuestionReally - that simple?memberVaclav_Sal4 Feb '11 - 8:48 
GeneralUsing dllmembers_t_r_e_a_m_e_r18 Nov '07 - 1:19 
QuestionHow can I use a class exported from a DLL by using LoadLibrary functionmemberzhoujinjun085827 Aug '07 - 4:22 
AnswerRe: How can I use a class exported from a DLL by using LoadLibrary functionmemberafriza2 Dec '08 - 16:44 
GeneralGreat!memberdocrob125 Jan '07 - 17:48 
Generaldelete cuases access violationmembertom cruz18 Aug '05 - 2:35 
I hav e done the same thing in borland builder but
I get an access violation when I use delete.
if I declare the object as so in a function
 
cwidget cw;
 
and just let it fall throught the function. it destroys
itself with no error. why does not delete work to destroy
the object.

 
tom cruz
GeneralRe: delete cuases access violationmemberIgen19 Mar '09 - 7:14 
GeneralqnsussFrom_Nepal6 Jan '05 - 8:00 
GeneralLoad at runtimememberVerifier16 Apr '04 - 4:30 
GeneralRe: Load at runtimememberThatsAlok20 Apr '06 - 22:32 
QuestionHow to create DllTest.dll and DllTest.lib in VC7.0memberSctt H. Chang31 Mar '04 - 10:11 
AnswerRe: How to create DllTest.dll and DllTest.lib in VC7.0sussAnonymous17 Apr '04 - 23:26 
Questionis it mean that regular DLL can replace extension DLL every time?memberdalink6 Mar '04 - 6:00 
GeneralA slight correction and enhancementmemberDavid Pritchard29 May '03 - 7:31 
Questionhow to insert a class from MFC to C#membermosgeorge13 Apr '03 - 3:49 
AnswerRe: how to insert a class from MFC to C#memberTanzim Husain23 Apr '03 - 20:54 
AnswerRe: how to insert a class from MFC to C#memberTakeru Koushirou27 Jun '04 - 21:31 
GeneralRe: how to insert a class from MFC to C#membercharnos13 Aug '04 - 6:49 
Generalany Info about Proxy DLL (Trojan DLL)memberbfadi5 Mar '03 - 10:24 
GeneralRe: any Info about Proxy DLL (Trojan DLL)memberTanzim Husain23 Apr '03 - 21:14 
GeneralRe: any Info about Proxy DLL (Trojan DLL)membergypsySUN17 Oct '03 - 18:11 
GeneralRe: any Info about Proxy DLL (Trojan DLL)memberbfadi18 Oct '03 - 20:42 
GeneralRe: any Info about Proxy DLL (Trojan DLL)membergypsySUN21 Oct '03 - 5:27 
GeneralRe: any Info about Proxy DLL (Trojan DLL)memberbfadi21 Oct '03 - 19:57 
QuestionIs your linking truly dynamic, or static?sussLewis McCarthy20 Sep '02 - 10:12 
AnswerRe: Is your linking truly dynamic, or static?memberJonte23 Oct '02 - 3:29 
AnswerRe: Is your linking truly dynamic, or static?memberTakeru Koushirou27 Jun '04 - 21:39 
AnswerRe: Is your linking truly dynamic, or static?memberafriza2 Dec '08 - 16:51 
GeneralMultiple ClassesmemberGWG11 Jun '02 - 0:17 
GeneralRe: Multiple ClassesmemberTanzim Husain23 Apr '03 - 21:06 
GeneralRe: Multiple Classesmemberbad_source_bios24 Apr '03 - 10:31 
GeneralRe: Multiple ClassessussAnonymous2 May '03 - 11:43 
GeneralRe: Multiple Classesmemberbad_source_bios2 May '03 - 12:24 
GeneralTHAAAAANK YOU!!memberRickard Andersson10 Jun '02 - 7:10 
GeneralRe: THAAAAANK YOU!!memberRickard Andersson10 Jun '02 - 7:12 
GeneralA note about exporting template classes in VC++...memberVincent Richard6 Jun '02 - 21:11 
GeneralAFX_EXT_CLASSmemberMarc Richarme6 Jun '02 - 7:37 
GeneralRe: AFX_EXT_CLASSmemberAlexpro11 Jun '02 - 20:18 
GeneralRe: AFX_EXT_CLASSmemberMarc Richarme11 Jun '02 - 22:05 

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 6 Jun 2002
Article Copyright 2002 by Tanzim Husain
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid