|
-
May 11th, 1999, 08:49 AM
#1
Use class from DLL?
Hiya!
I want in my main program use a class that is in a DLL. Is that possible?
What kind of dll should my class be and how do I use it from the main program?
I would like to do something like this.
myClassFromDll myClass;
myClass.SomeMethod();
Thanks
Magnus
-
May 11th, 1999, 10:29 AM
#2
Re: Use class from DLL?
If you are using an MFC entension DLl declare your class as follows:class AFX_EXT_CLASS CMyClassInDll
{
....
};
If a normal dll use:class _declspec(dllexport) CMyClassInDll
{
....
};
-
May 11th, 1999, 10:32 AM
#3
Re: Use class from DLL?
Essentially you need to declare your class with the __declspec( dllexport ) modifier.
This is what I do:
//header file for class
#ifdef MYCLASS_DLL_BUILD
#define EXPORTED_DLL __declspec( dllexport )
#else
#define EXPORTED_DLL
#endif
class EXPORTED_DLL MyClass
{
//class declaration etc
};
I put the header file in a central location. I make sure that MYCLASS_DLL_BUILD is defined in the project where I build the .dll file and make sure that is not defined in the project where I actually use an insance of the class.
Hope this helps
Andrew
-
May 12th, 1999, 02:32 AM
#4
Re: Use class from DLL?
Okej thanks!
But how do I use this class from my main program? Shall I link the obj file?
/Magnus
-
May 12th, 1999, 02:57 AM
#5
Re: Use class from DLL?
You will need to include the header file for the class and also link your application with the .lib file created when you compiled your dll. (See VC help on linking to lib's)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|