Solved

Q: class in a DLL

Posted on 1998-09-13
8
232 Views
Last Modified: 2013-11-20
How do I make a dll with a class in it that I can access in another MFC app?  I have been using _declspec(dllexport) and (dllimport) but for some reason when I link the project to test the class, it has unresolved externals to the imported (from the dll) class's functions.

How to I get a memory pointer to the class (that resides in the dll) so I can use class whatever in my test application?

Thanks,
Mike
0
Comment
Question by:brosoft
8 Comments
 

Author Comment

by:brosoft
ID: 1322113
PS. I would love some project code for making a DLL with a class and then accessing it from another project with LoadLibrary() etc...  Thanks again.
0
 

Accepted Solution

by:
fjsen earned 100 total points
ID: 1322114
Try linking with the .lib file generated by the first application.

Jose.

0
 

Author Comment

by:brosoft
ID: 1322115
If I link with the .lib, what is the point of having a dll?
0
 

Expert Comment

by:fjsen
ID: 1322116
If you change the DLL code without change the interface, you don't need to recompile the client project.

Jose.

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Expert Comment

by:jayaramb
ID: 1322117
Use that dll as extension dll and export the class in this way.

class AFX_EXT_CLASS CMyClass : public CDialog
{



}

, then link this .lib with that calling application. then compile the application.
U won't get any errors.
0
 

Author Comment

by:brosoft
ID: 1322118
So what is the point of a dll then?  If I just have to link the lib, then having a DLL is pointless.  I could just use a .lib file instead and statically link it to every file that I compile that needs the dll.  

I am trying to cut down on repetitive code and use one dll for all my programs to use the common functions.  Just using a lib would make it pointless... :(

0
 
LVL 2

Expert Comment

by:eelko
ID: 1322119
When creating a dll you will get a lib as well. This lib will hold the code to use the dll. Once you have linked your MFC app with this library who will be able to change the code of your dll without linking your app again. The only thing you have to keep in mind is that the names of the entry points, such as your class and its methods, should not be changed.
0
 

Author Comment

by:brosoft
ID: 1322120
thanks, I figured it out.  Explicit DLL's are what we are talking about here, linking with the .lib and all that.

Implicit ones are the one's I wanted.  Where you grab a ptr to the function or class and then don't have to link with the .lib.

Thanks,
Mike
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now