
__PPS__ wrote:
Yes, there's no need to include
, it could be removed from the export.h, but it doesn't mean that my DLL code doesn't include archives' code. Inside implementation of this (de)serialize functions (somewhere inside export.cpp, or whatever) I include all the archives code etc. basicly, here's export.cpp ///// //all needed includes & using namespace ...
#include "export.h" session_record::~session_record(){} session_record::operator session_record *(){ return this; }
void serialize(session_record* derived, const char* file_name){ ofstream out(file_name); if(!out || !out.is_open()) throw std::runtime_error(std::string("failed to open \"")+file_name+'"'); text_oarchive oa(out, no_header | no_codecvt); oa & derived; } session_record* deserialize(const char* file_name){ ifstream in(file_name); text_iarchive ia(in, no_header | no_codecvt); session_record *derived; ia & derived; return derived; } /////////
then in another app, that links to export.dll I have: /// needed includes & using declarations ... #include "export.h"
class client_record : public virtual session_record { friend class boost::serialization::access; template<class Archive> void serialize(needed args...){ serialization::base_object
(*this); ar & name; ar & address; ar & amount; } virtual void print_on(std::ostream &os)const{ os << "client record: \n" "\tname: " << name << "\n"; //.... } public: std::string name, address; double amount; }; BOOST_CLASS_EXPORT(client_record); main()try{
client_record x; x.name = "John Doe"; x.amount = 129.99; x.address = "2080 Wellington, apt. 13"; serialize(&x, "xxx.txt");
}catch (const exception &e) { cout << "error: " << e.what() << endl; }
/////////
I get unregistered class exception. I use vc71 and if I now in settings for the export.dll change project type from Dll to static library, and recompile my test program, everything works as expected. and this error I get is from serializing from base pointer, not from deserializing...
one other thing...
inside section "Runtime casting" there's 2nd method for registering
derived class:
boost::serialization::void_cast_register