Exemple #1
0
BOOL AFXAPI _AfxLoadObjectFromStreamedPropset(LPUNKNOWN lpUnknown, LPSTREAM lpStream)
{
	ASSERT_POINTER(lpUnknown, IUnknown);
	ASSERT_POINTER(lpStream, IStream);

	BOOL bSuccess = FALSE;
	LPDATAOBJECT pDataObj = NULL;

	if (SUCCEEDED(lpUnknown->QueryInterface(IID_IDataObject,
			(LPVOID*)&pDataObj)))
	{
		ASSERT_POINTER(pDataObj, IDataObject);

		// Set the persistent propset format on the object.

		FORMATETC formatEtc;
		STGMEDIUM stgMedium;
		formatEtc.cfFormat = _AfxGetClipboardFormatPersistPropset();
		formatEtc.ptd = NULL;
		formatEtc.dwAspect = DVASPECT_CONTENT;
		formatEtc.lindex = -1;
		formatEtc.tymed = TYMED_ISTREAM;

		stgMedium.tymed = TYMED_ISTREAM;
		stgMedium.pstm = lpStream;
		stgMedium.pUnkForRelease = NULL;

		bSuccess = SUCCEEDED(pDataObj->SetData(&formatEtc, &stgMedium, FALSE));

		pDataObj->Release();
	}

	return bSuccess;
}
Exemple #2
0
BOOL AFXAPI _AfxOleMatchPropsetClipFormat(CLIPFORMAT cfFormat, LPCLSID lpFmtID)
{
	if (cfFormat == _AfxGetClipboardFormatPersistPropset())
	{
		*lpFmtID = CLSID_PersistPropset;
		return TRUE;
	}

	if (cfFormat == _AfxGetClipboardFormatConvertVBX())
	{
		*lpFmtID = CLSID_ConvertVBX;
		return TRUE;
	}

	return FALSE;
}
Exemple #3
0
BOOL AFXAPI _AfxSaveObjectInPropset(LPUNKNOWN pUnk, CPropertySection& psec,
	DWORD dwPropID)
{
	if (pUnk == NULL)
		return FALSE;

	ASSERT_POINTER(pUnk, IUnknown);

	BOOL bSuccess = FALSE;
	LPDATAOBJECT pDataObj;

	if (SUCCEEDED(pUnk->QueryInterface(IID_IDataObject,
			(LPVOID*)&pDataObj)))
	{
		// Get the persistent propset format from object.

		FORMATETC formatEtc;
		STGMEDIUM stgMedium;
		formatEtc.cfFormat = _AfxGetClipboardFormatPersistPropset();
		formatEtc.ptd = NULL;
		formatEtc.dwAspect = DVASPECT_CONTENT;
		formatEtc.lindex = -1;
		formatEtc.tymed = TYMED_ISTREAM;

		stgMedium.tymed = TYMED_NULL;
		stgMedium.pUnkForRelease = NULL;

		if (SUCCEEDED(pDataObj->GetData(&formatEtc, &stgMedium)))
		{
			if (stgMedium.tymed == TYMED_ISTREAM)
			{
				LPSTREAM pstm = stgMedium.pstm;

				// Seek to start of stream.
				if (SUCCEEDED(pstm->Seek(_afxLargeZero, STREAM_SEEK_SET, NULL)))
				{
					// Create a "blobbed" propset from the stream
					bSuccess = _AfxSaveStreamDataAsBlobProp(stgMedium.pstm,
						psec, dwPropID, VT_BLOB_PROPSET);
				}
			}

			// Cleanup
			ReleaseStgMedium(&stgMedium);
		}

		pDataObj->Release();
	}

	LPPERSISTSTREAM pPersStm = NULL;

	if ((!bSuccess) &&
		SUCCEEDED(pUnk->QueryInterface(IID_IPersistStream,
			(LPVOID*)&pPersStm)))
	{
		// Get the object to save itself into a stream, then store that
		// streamed data as a blob.

		ASSERT_POINTER(pPersStm, IPersistStream);
		LPSTREAM pstm = _AfxCreateMemoryStream();
		if (pstm != NULL)
		{
			if (SUCCEEDED(::OleSaveToStream(pPersStm, pstm)) &&
				SUCCEEDED(pstm->Seek(_afxLargeZero, STREAM_SEEK_SET, NULL)))
			{
				bSuccess = _AfxSaveStreamDataAsBlobProp(pstm, psec,
					dwPropID, VT_BLOB);
			}

			pstm->Release();
		}

		pPersStm->Release();
	}

	return bSuccess;
}