Solved

Finding a class in a dll

Posted on 1998-10-22
5
229 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 Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Separate into files by filename 12 87
MaxSpan challenge 9 104
Change to event 1 117
x-bar in Google Sheets 2 69
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

791 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