Sign in to follow this  

share a class among multiple dll's

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

This topic is 4356 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this