5,446,823 members and growing! (17,577 online)
Email Password   helpLost your password?
General Programming » DLLs & Assemblies » Beginners     Beginner

Exporting C++ classes without using MFC extension DLL

By Tanzim Husain

This article describes the process of exporting regular C++ classes without using MFC extension DLLs
VC6, VC7, C++Windows, Win2K, WinXPVS6, Visual Studio, Dev

Posted: 5 Jun 2002
Updated: 5 Jun 2002
Views: 134,440
Bookmarked: 36 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
47 votes for this Article.
Popularity: 5.15 Rating: 3.08 out of 5
10 votes, 29.4%
1
1 vote, 2.9%
2
2 votes, 5.9%
3
9 votes, 26.5%
4
12 votes, 35.3%
5

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



Occupation: Web Developer
Location: United States United States

Other popular DLLs & Assemblies articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 35 (Total in Forum: 35) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralUsing dllmembers_t_r_e_a_m_e_r2:19 18 Nov '07  
QuestionHow can I use a class exported from a DLL by using LoadLibrary functionmemberzhoujinjun08585:22 27 Aug '07  
GeneralGreat!memberdocrob118:48 25 Jan '07  
Generaldelete cuases access violationmembertom cruz3:35 18 Aug '05  
GeneralqnsussFrom_Nepal9:00 6 Jan '05  
GeneralLoad at runtimememberVerifier5:30 16 Apr '04  
GeneralRe: Load at runtimememberThatsAlok23:32 20 Apr '06  
GeneralHow to create DllTest.dll and DllTest.lib in VC7.0memberSctt H. Chang11:11 31 Mar '04  
GeneralRe: How to create DllTest.dll and DllTest.lib in VC7.0sussAnonymous0:26 18 Apr '04  
Generalis it mean that regular DLL can replace extension DLL every time?memberdalink7:00 6 Mar '04  
GeneralA slight correction and enhancementmemberDavid Pritchard8:31 29 May '03  
Generalhow to insert a class from MFC to C#membermosgeorge4:49 13 Apr '03  
GeneralRe: how to insert a class from MFC to C#memberTanzim Husain21:54 23 Apr '03  
GeneralRe: how to insert a class from MFC to C#memberTakeru Koushirou22:31 27 Jun '04  
GeneralRe: how to insert a class from MFC to C#membercharnos7:49 13 Aug '04  
Generalany Info about Proxy DLL (Trojan DLL)memberbfadi11:24 5 Mar '03  
GeneralRe: any Info about Proxy DLL (Trojan DLL)memberTanzim Husain22:14 23 Apr '03  
GeneralRe: any Info about Proxy DLL (Trojan DLL)membergypsySUN19:11 17 Oct '03  
GeneralRe: any Info about Proxy DLL (Trojan DLL)memberbfadi21:42 18 Oct '03  
GeneralRe: any Info about Proxy DLL (Trojan DLL)membergypsySUN6:27 21 Oct '03  
GeneralRe: any Info about Proxy DLL (Trojan DLL)memberbfadi20:57 21 Oct '03  
GeneralIs your linking truly dynamic, or static?sussLewis McCarthy11:12 20 Sep '02  
GeneralRe: Is your linking truly dynamic, or static?memberJonte4:29 23 Oct '02  
GeneralRe: Is your linking truly dynamic, or static?memberTakeru Koushirou22:39 27 Jun '04  
GeneralMultiple ClassesmemberGWG1:17 11 Jun '02  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 5 Jun 2002
Editor: Nishant Sivakumar
Copyright 2002 by Tanzim Husain
Everything else Copyright © CodeProject, 1999-2008
Web16 | Advertise on the Code Project