Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ DLL
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:
 
#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.
*/
}
 
#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 27-Nov-12 21:51pm
amsga570
Comments
Argonia at 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 at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.141015.1 | Last Updated 28 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100