Hi guys,
I've got a problem with extended Dlls. First of all, I have to use extended Dlls because I exchange objects between Dlls, with return statements usually.
Ok, here is a brief description of the app. The software manages several hardware components, each of them with its own settings. Each of this hardware component "lives" in its associated dll, which manages it. But some operations are common to all components, so I thought I create a base class for all of them. And I implemented this class in an extended Dll which every other dlls link with.
And here is the problem I've got. The objects have to be serializable, but adding the serialization macros makes the compiler throwing errors at link time. I've got no idea why. I've been using serialization for quite a while, never in that peculiar situation however.
So first, here is the declaration for the base object, defined in an extended dll.
"#ifndef ____VTI_HARDWARECOMPONENT_H__
#define ____VTI_HARDWARECOMPONENT_H__
class AFX_EXT_CLASS CVHardwareComponentLabel : public CObject
{
public:
DECLARE_SERIAL(CVHardwareComponentLabel)
// constructor
CVHardwareComponentLabel();
// destructorsa0
virtual ~CVHardwareComponentLabel();
// copy contructor
CVHardwareComponentLabel(const CVHardwareComponentLabel& l);
// assignment operator
CVHardwareComponentLabel& operator=(const CVHardwareComponentLabel& l);
// serialization management
virtual void Serialize(CArchive& ar);
};
#endif"
few comments: AFX_EXT_CLASS in order to be able to exchange objects between dlls. The corresponding code is not included, but every single method is totally empty, no code at all (except the assignment operator, which returns *this obviously).
That code compiled fine. And I then created another extended dll, which manages a hardware component. The object defined in this dll is thus derived from the base class. Here is the declaration:
"class AFX_EXT_CLASS CVAOTFLabels : public CVHardwareComponentLabel
{
public: // public methods
DECLARE_SERIAL(CVAOTFLabels)
// constructor
CVAOTFLabels();
// destructor
virtual ~CVAOTFLabels();
// copy contructor
CVAOTFLabels::CVAOTFLabels(const CVAOTFLabels& l);
// assignment operator
CVAOTFLabels& CVAOTFLabels:perator = (const CVAOTFLabels& l);
// serialization
virtual void Serialize(CArchive& Archive);
public: // public member data
// laser intensity
long percentage[VTI_AOTF_MAX_LINE];
};"
same comment as before, the code is once again empty. But when I try to compile this new extended dll, I get a link error : "VAOTF.obj : error LNK2001: unresolved external symbol "public: static struct CRuntimeClass CVHardwareComponentLabel::classCVHardwareComponentLabel" (?classCVHardwareComponentLabel@CVHardwareComponentLabel@@2UCRuntimeClass@@A)". If I remove the two serialization macros, it compiles fine. Obviously, the dll (.lib)containing the base class implementation is added in the project settings so the compiler can find it at link time. And it does find it, because some other classes work fine.
Now I might have a clue of what this is. In the MSDN, for the article describing IMPLEMENT_SERIAL, it is said :"Use the IMPLEMENT_SERIAL macro in a .CPP module; then link the resulting object code only once.". The important bit is only once. Does it mean that if I define a serializable class in a Dll, I can only use it in a .exe, and not in another .dll? Or maybe thats not related at all?
Do you have any ideas? Any comments welcome!
Thanks a lot
Alexis
I've got a problem with extended Dlls. First of all, I have to use extended Dlls because I exchange objects between Dlls, with return statements usually.
Ok, here is a brief description of the app. The software manages several hardware components, each of them with its own settings. Each of this hardware component "lives" in its associated dll, which manages it. But some operations are common to all components, so I thought I create a base class for all of them. And I implemented this class in an extended Dll which every other dlls link with.
And here is the problem I've got. The objects have to be serializable, but adding the serialization macros makes the compiler throwing errors at link time. I've got no idea why. I've been using serialization for quite a while, never in that peculiar situation however.
So first, here is the declaration for the base object, defined in an extended dll.
"#ifndef ____VTI_HARDWARECOMPONENT_H__
#define ____VTI_HARDWARECOMPONENT_H__
class AFX_EXT_CLASS CVHardwareComponentLabel : public CObject
{
public:
DECLARE_SERIAL(CVHardwareComponentLabel)
// constructor
CVHardwareComponentLabel();
// destructorsa0
virtual ~CVHardwareComponentLabel();
// copy contructor
CVHardwareComponentLabel(const CVHardwareComponentLabel& l);
// assignment operator
CVHardwareComponentLabel& operator=(const CVHardwareComponentLabel& l);
// serialization management
virtual void Serialize(CArchive& ar);
};
#endif"
few comments: AFX_EXT_CLASS in order to be able to exchange objects between dlls. The corresponding code is not included, but every single method is totally empty, no code at all (except the assignment operator, which returns *this obviously).
That code compiled fine. And I then created another extended dll, which manages a hardware component. The object defined in this dll is thus derived from the base class. Here is the declaration:
"class AFX_EXT_CLASS CVAOTFLabels : public CVHardwareComponentLabel
{
public: // public methods
DECLARE_SERIAL(CVAOTFLabels)
// constructor
CVAOTFLabels();
// destructor
virtual ~CVAOTFLabels();
// copy contructor
CVAOTFLabels::CVAOTFLabels(const CVAOTFLabels& l);
// assignment operator
CVAOTFLabels& CVAOTFLabels:perator = (const CVAOTFLabels& l);
// serialization
virtual void Serialize(CArchive& Archive);
public: // public member data
// laser intensity
long percentage[VTI_AOTF_MAX_LINE];
};"
same comment as before, the code is once again empty. But when I try to compile this new extended dll, I get a link error : "VAOTF.obj : error LNK2001: unresolved external symbol "public: static struct CRuntimeClass CVHardwareComponentLabel::classCVHardwareComponentLabel" (?classCVHardwareComponentLabel@CVHardwareComponentLabel@@2UCRuntimeClass@@A)". If I remove the two serialization macros, it compiles fine. Obviously, the dll (.lib)containing the base class implementation is added in the project settings so the compiler can find it at link time. And it does find it, because some other classes work fine.
Now I might have a clue of what this is. In the MSDN, for the article describing IMPLEMENT_SERIAL, it is said :"Use the IMPLEMENT_SERIAL macro in a .CPP module; then link the resulting object code only once.". The important bit is only once. Does it mean that if I define a serializable class in a Dll, I can only use it in a .exe, and not in another .dll? Or maybe thats not related at all?
Do you have any ideas? Any comments welcome!
Thanks a lot
Alexis