Solved

Finding a class in a dll

Posted on 1998-10-22
5
228 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Detect CR LF to each line 12 162
countEvens challenge 2 103
either24  challenge 19 97
NotAlone Challenge 20 84
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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

821 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