要求控件在持久化时,在Contents流中保持属性,另外创建一个流,保持一份二进制数据。注意,这是要求。别要在CONTENTS流里保持二进制数据。我从新写了这个接口,但是遇到一些问题。请指教STDMETHODIMP CGABSignatureOfficeCtrl::XPersistStorage::Load(LPSTORAGE pStg)
{
ASSERT(pStg != NULL);
METHOD_PROLOGUE_EX(CGABSignatureOfficeCtrl, PersistStorage) CLIPFORMAT cf;
HRESULT hr;
CLSID fmtid; hr = ::ReadFmtUserTypeStg(pStg, &cf, NULL); if (SUCCEEDED(hr) /*&& _AfxOleMatchPropsetClipFormat(cf, &fmtid)*/)
{
// Load the property set data
//FORMATETC formatEtc;
//STGMEDIUM stgMedium;
//formatEtc.cfFormat = cf;
//formatEtc.ptd = NULL;
//formatEtc.dwAspect = DVASPECT_CONTENT;
//formatEtc.lindex = -1;
//formatEtc.tymed = TYMED_ISTORAGE;
//stgMedium.tymed = TYMED_ISTORAGE;
//stgMedium.pstg = pStg;
//stgMedium.pUnkForRelease = NULL;
//hr = pThis->SetPropsetData(&formatEtc, &stgMedium, fmtid) ?
// S_OK : E_FAIL;
}
else
{
// Open the "Contents" stream of the supplied storage object, and
// then delegate to same implementation as IPersistStreamInit::Load.
LPSTREAM pStm = NULL; hr = pStg->OpenStream(OLESTR("Contents"), NULL,
STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &pStm); ASSERT(FAILED(hr) || pStm != NULL); if (pStm != NULL)
{
//置状态量
pThis->SetStgState(false);
// Delegate to LoadState.
hr = pThis->LoadState(pStm);
pStm->Release();
} if (pThis->m_pDefIPersistStorage == NULL)
pThis->m_pDefIPersistStorage =
(LPPERSISTSTORAGE)pThis->QueryDefHandler(IID_IPersistStorage); // Delegate to default handler (for cache).
pThis->m_pDefIPersistStorage->Load(pStg);
hr = pStg->OpenStream(OLESTR("GABSIGNATURE"), NULL,
STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &pStm); ASSERT(FAILED(hr) || pStm != NULL); if (pStm != NULL)
{
//置状态量
pThis->SetStgState(true);
// Delegate to LoadState.
hr = pThis->LoadState(pStm);
pStm->Release();
} } if (pThis->m_pDefIPersistStorage == NULL)
pThis->m_pDefIPersistStorage =
(LPPERSISTSTORAGE)pThis->QueryDefHandler(IID_IPersistStorage); // Delegate to default handler (for cache).
pThis->m_pDefIPersistStorage->Load(pStg);
return hr;
}

解决方案 »

  1.   

    What is your problem? Forgot to add interface maps?
    Remember to fail all other IPersist* calls.
      

  2.   

    我的问题是 COleControl 中的IPersistStorage接口的方法,SAVE,LOAD不能满足需要。我现在想在重写这个接口的方法。
      

  3.   

    具体是这样的问题。COleControl 有接口IPersistStorage. 并且MFC定义的IPersistorage。但是问题是, 我想在控件持久化时,保存两个数据流ISTREAM. 因此要重写IPersistStorage LOAD 和 SAVE方法。 指教。