我将继续构建两个简单的进程,通过简单的(匿名)管道将类对象相互投掷(参见我的上一篇文章)。现在我为自己揭示了 boost::serialization (感谢回答的人),并试图通过 ::WriteFile::ReadFile 对某些类进行序列化。所以 - 我做错了什么?
1)我创建了一些类
#pragma once
#include "wtypes.h"
#include <boost\archive\binary_oarchive.hpp>
#include <boost\archive\binary_iarchive.hpp>
#include <boost\serialization\binary_object.hpp>
class CTextContainer
{
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & m_sText;
ar & m_dwCRC;
ar & m_dwSize;
}
public:
CTextContainer() : m_dwCRC(0), m_dwSize(0)
{
ZeroMemory(m_sText, sizeof(m_sText));
m_dwSize = sizeof(*this);
}
CTextContainer(LPCTSTR sText) : m_dwCRC(0), m_dwSize(0)
{
ZeroMemory(m_sText, sizeof(m_sText));
wcsncpy_s(m_sText, 1024, sText, wcslen(sText));
m_dwSize = sizeof(*this);
}
virtual ~CTextContainer(){}
LPTSTR GetText() const{return (LPTSTR) m_sText;}
protected:
DWORD m_dwCRC;
DWORD m_dwSize;
TCHAR m_sText[1024];
}; //end of class
2)现在我正试图从这个类中读取二进制存档并将其内容写入管道的一端......
boost::archive::binary_oarchive oa(ofs);
oa << tc;
::WriteFile(hPipe, &oa, dwRead, &dwWritten, NULL) == FALSE
它不会那样工作,对吧?那么,会如何呢?
3) 另一边的操作相同?