Archived

This topic is now archived and is closed to further replies.

exporting a class in a dll file..

This topic is 5095 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Sorry if my question is kind of vague but I don't know how to put it, I want to have a class in a dll file and be able to use that class from my program Thanks. [edit]whooops messed up the writing[/edit] [edited by - NullPointer33 on January 6, 2004 8:37:42 PM]

Share this post


Link to post
Share on other sites
There are some really good articles on this site about that.

To my knowledge (please tell me if I''m wrong), you can''t export classes in a DLL without some little doo-dad in VC++ under Win32. (Right?) But you can export interface structures. You have a C struct with pointers to the functions that you want to export, as well as data members that you want public.

struct blah
{
void (*doBlah)( int i );
void (*dontBlah)( int y );
} Blah;


Ahhh. Blah.



==================
Benjamin Heath
==================

Share this post


Link to post
Share on other sites
to export a class from a dll, you need to do the following:

#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */

Then for each class that needs to be exported:

class DLLIMPORT CSprite
{
...

};

Now, when you build the dll, make sure that BUILDING_DLL is defined. And when you are just linking to the dll, you include the header file, but BUILDING_DLL is not defined, which will prepare class for import.

For more info, check out msdn for import/export and def files.

Share this post


Link to post
Share on other sites
quote:
Original post by Benjamin Heath
There are some really good articles on this site about that.

To my knowledge (please tell me if I''m wrong), you can''t export classes in a DLL without some little doo-dad in VC++ under Win32. (Right?) But you can export interface structures. You have a C struct with pointers to the functions that you want to export, as well as data members that you want public.

struct blah
{
void (*doBlah)( int i );
void (*dontBlah)( int y );
} Blah;


Ahhh. Blah.



CORRECTION! (Why am I correcting myself? That''s your job.)

You can export classes from a DLL in Win32. (I''m so silly!) But it is done DIFFERENTLY on different compilers.

pjcast got it right for DLLs in VC++, but if you or some friend of yours wants to compile your code under MingW, you''ve gotta do this:


#if BUILDING_DLL
# ifdef WIN32
# define APIENTRY __declspec(dllexport)
# else
# define APIENTRY extern
#else
# ifdef WIN32
# define APIENTRY __declspec(dllimport)
# else
# define APIENTRY
#endif

class APIENTRY someclass
{
};


Whoops!



==================
Benjamin Heath
==================

Share this post


Link to post
Share on other sites