Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've got this one particular class that I wish to share between two DLL projects under the same solution.

Currently, I copied the file into the two project folders and included both a #pragma once and #ifndef guard.

I was wondering if there is a better solution for it.
The only difference in the both codes is that they both use different #define for the
_declspec(dllexport)
.

Just to give you a rough idea what both looks like:

C++
#pragma once
#ifndef ITEM_H

class CItem
{
public:
DLL1_API CItem(void);
DLL1_API ~CItem(void);

DLL1_API int getValue(void) const;
DLL1_API void setValue(int value);

/*
Remaining methods with the similar signatures.
*/
}


C++
#pragma once
#ifndef ITEM_H
class CItem
{
public:
DLL2_API CItem(void);
DLL2_API ~CItem(void);
DLL2_API int getValue(void) const;
DLL2_API void setValue(int value);
/*
Remaining methods with the similar signatures.
*/
}


Both DLL1_API and DLL2_API are current set to
_declspec(dllexport)
Posted
Comments
Argonia 28-Nov-12 4:04am    
I faced similar problem but with more classes and functions. I can offer you to consider moving the class in a different DLL , which will be called when the class is needed in the other DLLs. The other solution i see is to call the one dll containing the class definition into the other but not always this is a good idea
amsga 28-Nov-12 21:09pm    
The first solution sounds nice but seems a bit of an overkill just for one class to be placed within a dll. I'll give it a try and see how things turn out.

I was originally thinking of the second idea but I want to decouple the two projects just in case in the future, I need to deploy them seperately.

1 solution

Use a single source file which you can add to each project. Then create a unique header for each project that you can include into the dll source which will contain any unique defines that you may use in it. So instead of using DLL1_API or DLL2_API, you would use DLL_API which is uniquely defined in the appropriate header.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900