Solved

Finding a class in a dll

Posted on 1998-10-22
5
232 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Database Solutions Engineer FAQs

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller single-server environments.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

617 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