继承COleControl的控件类,如何从新实现IPersistStorage接口,因此在ColeControl里实现的接口方法不能实现功能
描述:
要求控件在持久化时,在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;
}