Jump to content
  • Advertisement
Sign in to follow this  
Muncher

share a class among multiple dll's

This topic is 4667 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

I have a main application project that defines class A. And i have several DLL projects (that will link to the main application) that make use of class A. How does A get shared among projects? Currently im just adding the class into each dll project workspace (Project->Add Existing Item->A.h A.cpp) - but im sure this is not correct. Does a have to be recompiled and linked for each dll?

Share this post


Link to post
Share on other sites
Advertisement
Hello,

First off I apologize if I am misunderstanding your question, but here is what I think you are looking for. (I assume you are using VC)

In any projects that are going to use the DLL define the following:
(Use a better naming convention as this is just an example)

#if defined(SOME_API)
#define CAPI __declspec(dllexport)
#else
#define CAPI __declspec(dllimport)
#endif




For the main DLL (The one with Class 'A') go to Project->Settings and click the C/C++ tab. Under "Preprocessor Definitions" add "SOME_API" to the list. This will use __declspec(dllexport) which will allow you to export the class. (Note that this needs done for both debug and release builds)

Where you define class 'A' define it like the following:

class CAPI A
{
...
};




Then compile the DLL.

Now that you have your DLL just include the "a.h" to any project you want to use the DLL in. Do not add anything to the preprocessor definitions so it will use __declspec(dllimport) and inport the class.

That's the whole thing in a nut shell. I have a meeting in a few minutes or I would explain a little better.

Best of luck.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!