Solved

Finding a class in a dll

Posted on 1998-10-22
5
226 Views
Last Modified: 2013-11-20
I'm doing a flowchart type program. Each shape is drawn in a class derived from a base class called CShape. I would like to put this derived classes in DLL's and load them at run time, getting the names of the dll's that contain shapes in the registry.

Here is my question: How do open the dll's (LoadLibary I know) retrive the Shape classes for use? Remember I do not know anything about the classes at compile/link time, only registry entries for the DLL file names.

Thanks
Thomas

PS: is COM a solution?
0
Comment
Question by:SirThomas
5 Comments
 
LVL 2

Expert Comment

by:Belgarat
ID: 1323725
You can enumerate a functions exported from the DLL, but you'll have to strip decoration added by the C++ compiler to the names.
The second approach is to create a special function like EnumSupportedClasses() in the DLL, that returns array of class names.
However, you CAN'T specify class name as a variable in some variable declaration, so this information will be useless to you anyway. If your DLL classes are descendants of some CShape, you can export function CreateShape(char *pShapeName) that returns a pointer to a new allocated instance of the requested shape class. If you use virtual functions in the CShape class, you'll be able to call the descendant's implementations through them.

0
 
LVL 2

Expert Comment

by:cyrilbdt
ID: 1323726
create dll project and put all classes you want. use __declspec for classes
you want to be available from this dll.
when the ptoject is compiled in debug/release directory ther is a some.lib file.
Add this file to your project and make sure that there is path to some.dll

file.h
*************
class __declspec(dllexport) CMyClass{
public:
      .....
};
************


0
 

Author Comment

by:SirThomas
ID: 1323727
I need to get this information at run time not compile/link time. If this user creates DLL for my app, in his office in china, I do not want to recompile my program to add his dll to my project, in the US. I need this more dynamic.
0
 

Accepted Solution

by:
Maizlish earned 100 total points
ID: 1323728
Yes COM is a solution.
I can suggest something that resembles COM if you do not want to mess with it only for
classes information.
You can decide that each dll that will participate in your application ( every dll that will be retreived from the registry ) MUST have class ( lets call it CEnumerator ) and this class
has function ( lets call it GetClass(es) ) . This way you can get classes hidden in the DLL
If you word some more on this CEnumerator you can make it give some more usefull information

this is very much like COM's ideas of interfaces , but there is no need to add COM to your application just for this reason

Hope it helps ,
Oleg
0
 
LVL 2

Expert Comment

by:cyrilbdt
ID: 1323729
Sorry, I don't read to question correctly. Shure this will not help.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

13 Experts available now in Live!

Get 1:1 Help Now