Пример #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;
}
Пример #2
0
bool data::compare_by_time_user(const void* ppData1, const void* ppData2)
{
	const SData *pData1 = (const SData*) ppData1;
	const SData *pData2 = (const SData*) ppData2;

	ASSERT_POINTER(pData1, SData);
	ASSERT_POINTER(pData2, SData);

	if (pData1 == pData2)
	{
		return false;
	}

	CString sx = pData1->time + " " + pData1->user;
	CString sy = pData2->time + " " + pData2->user;
	
	if (sx == sy)
	{
		return false;
	}

	if (-1 != sx.CompareNoCase(sy))
	{
		return false;
	}

	return true;
}
Пример #3
0
LPFONT AFXAPI _AfxCreateFontFromStream(LPSTREAM pstm)
{
	BOOL bSuccess = FALSE;
	LPFONT pFont = NULL;
	LPPERSISTSTREAM pPersStm = NULL;
	CLSID clsid;

	if (SUCCEEDED(pstm->Read(&clsid, sizeof(CLSID), NULL)))
	{
		HRESULT hr;

		if (IsEqualCLSID(clsid, CLSID_StdFont) ||
			IsEqualCLSID(clsid, _afx_CLSID_StdFont_V1))
		{
			// We know this kind of font; create it using the API.
			hr = ::OleCreateFontIndirect((LPFONTDESC)&_afxFontDescHelv, IID_IFont,
					(LPVOID*)&pFont);
		}
		else
		{
			// Some other implementation of IFont.
			hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, IID_IFont,
					(LPVOID*)&pFont);
		}

		if (SUCCEEDED(hr))
		{
			// Successfully created font, now get its IPersistStream interface.

			ASSERT_POINTER(pFont, IFont);

			if (SUCCEEDED(pFont->QueryInterface(IID_IPersistStream,
					(LPVOID*)&pPersStm)))
			{
				ASSERT_POINTER(pPersStm, IPersistStream);
			}
		}

		if (pPersStm != NULL)
		{
			// Load the font.

			ASSERT_POINTER(pFont, IFont);
			bSuccess = SUCCEEDED(pPersStm->Load(pstm));
			pPersStm->Release();
		}
	}

	// If we failed for any reason, clean up the font.
	if (!bSuccess && pFont != NULL)
	{
		pFont->Release();
		pFont = NULL;
	}

	return pFont;
}
Пример #4
0
BOOL AFXAPI AfxOleRegisterTypeLib(HINSTANCE hInstance, REFGUID tlid,
	LPCTSTR pszFileName, LPCTSTR pszHelpDir)
{
	USES_CONVERSION;

	BOOL bSuccess = FALSE;
	CString strPathName;
	TCHAR *szPathName = strPathName.GetBuffer(_MAX_PATH);
	::GetModuleFileName(hInstance, szPathName, _MAX_PATH);
	strPathName.ReleaseBuffer();
	LPTYPELIB ptlib = NULL;

	// If a filename was specified, replace final component of path with it.
	if (pszFileName != NULL)
	{
		int iBackslash = strPathName.ReverseFind('\\');
		if (iBackslash != -1)
			strPathName = strPathName.Left(iBackslash+1);
		strPathName += pszFileName;
	}

	if (SUCCEEDED(LoadTypeLib(T2COLE(strPathName), &ptlib)))
	{
		ASSERT_POINTER(ptlib, ITypeLib);

		LPTLIBATTR pAttr;
		GUID tlidActual = GUID_NULL;

		if (SUCCEEDED(ptlib->GetLibAttr(&pAttr)))
		{
			ASSERT_POINTER(pAttr, TLIBATTR);
			tlidActual = pAttr->guid;
			ptlib->ReleaseTLibAttr(pAttr);
		}

		// Check that the guid of the loaded type library matches
		// the tlid parameter.
		ASSERT(IsEqualGUID(tlid, tlidActual));

		if (IsEqualGUID(tlid, tlidActual))
		{
			// Register the type library.
			if (SUCCEEDED(RegisterTypeLib(ptlib,
					T2OLE((LPTSTR)(LPCTSTR)strPathName), T2OLE((LPTSTR)pszHelpDir))))
				bSuccess = TRUE;
		}

		RELEASE(ptlib);
	}
	else
	{
		TRACE1("Warning: Could not load type library from %s\n", (LPCTSTR)strPathName);
	}

	return bSuccess;
}
Пример #5
0
int GvSetFieldConnection::OnTrigger(GvField *fromField) 
{ 
	//connectionsTriggeredCnt++;
	ASSERT_POINTER(fromField,GvField);	
	ASSERT_POINTER(toField,GvField);	
	ASSERT(fromField->getFieldType() == toField->getFieldType());

	
//	TRACE("GvSetFieldConnection::OnTrigger %s %d \n",from->ClassName(),connectionsTriggeredCnt);

    return( toField->set(fromField));
}
Пример #6
0
BOOL CMonthCalCtrl::SetSelRange(const LPSYSTEMTIME pMinRange,
                                const LPSYSTEMTIME pMaxRange)
{
    ASSERT(m_hWnd != NULL);
    ASSERT((GetStyle() & MCS_MULTISELECT));

    ASSERT_POINTER(pMinRange, SYSTEMTIME);
    ASSERT_POINTER(pMaxRange, SYSTEMTIME);

    SYSTEMTIME sysTimes[2];
    sysTimes[0] = *pMinRange;
    sysTimes[1] = *pMaxRange;

    return (BOOL) ::SendMessage(m_hWnd, MCM_SETSELRANGE,
                                0, (LPARAM) sysTimes);
}
Пример #7
0
LPSTREAM AFXAPI _AfxCreateMemoryStream()
{
	LPSTREAM lpStream = NULL;

	// Create a stream object on a memory block.
	HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE|GMEM_SHARE, 0);
	if (hGlobal != NULL)
	{
		if (FAILED(CreateStreamOnHGlobal(hGlobal, TRUE, &lpStream)))
		{
			TRACE0("CreateStreamOnHGlobal failed.\n");
			GlobalFree(hGlobal);
			return NULL;
		}

		ASSERT_POINTER(lpStream, IStream);
	}
	else
	{
		TRACE0("Failed to allocate memory for stream.\n");
		return NULL;
	}

	return lpStream;
}
Пример #8
0
int CMonthCalCtrl::GetMonthRange(LPSYSTEMTIME pMinRange,
                                 LPSYSTEMTIME pMaxRange, DWORD dwFlags) const
{
    ASSERT(::IsWindow(m_hWnd));
    ASSERT_POINTER(pMinRange, SYSTEMTIME);
    ASSERT_POINTER(pMaxRange, SYSTEMTIME);

    SYSTEMTIME sysTimes[2];

    int nCount = (int) ::SendMessage(m_hWnd, MCM_GETMONTHRANGE,
                                     (WPARAM) dwFlags, (LPARAM) sysTimes);

    *pMinRange = sysTimes[0];
    *pMaxRange = sysTimes[1];

    return nCount;
}
Пример #9
0
// Handle the tooltip messages.  Returns true to mean message was handled.
BOOL MyGraph::OnNeedText(UINT /*uiId*/, NMHDR* pNMHDR, LRESULT* pResult)
{
	_ASSERTE(pNMHDR  &&  "Bad parameter passed");
	_ASSERTE(pResult  &&  "Bad parameter passed");

	bool bReturn(false);
	UINT_PTR uiID(pNMHDR->idFrom);

	// Notification in NT from automatically created tooltip.
	if (0U != uiID) {
		bReturn = true;

		// Need to handle both ANSI and UNICODE versions of the message.
		TOOLTIPTEXTA* pTTTA = reinterpret_cast<TOOLTIPTEXTA*> (pNMHDR);
		ASSERT_POINTER(pTTTA, TOOLTIPTEXTA);

		TOOLTIPTEXTW* pTTTW = reinterpret_cast<TOOLTIPTEXTW*> (pNMHDR);
		ASSERT_POINTER(pTTTW, TOOLTIPTEXTW);

		CString sTipText(GetTipText());

#ifndef _UNICODE
		if (TTN_NEEDTEXTA == pNMHDR->code) {
			lstrcpyn(pTTTA->szText, sTipText, _countof(pTTTA->szText));
		}
		else {
			_mbstowcsz(pTTTW->szText, sTipText, _countof(pTTTA->szText));
		}
#else
		if (pNMHDR->code == TTN_NEEDTEXTA) {
			_wcstombsz(pTTTA->szText, sTipText, _countof(pTTTA->szText));
		}
		else {
			lstrcpyn(pTTTW->szText, sTipText, _countof(pTTTA->szText));
		}
#endif

		*pResult = 0;
	}

	return bReturn;
}
Пример #10
0
CPropsetPropExchange::CPropsetPropExchange(CPropertySection& psec,
		LPSTORAGE lpStorage, BOOL bLoading) :
	m_psec(psec),
	m_lpStorage(lpStorage),
	m_dwPropID(255)
{
	ASSERT_POINTER(&psec, CPropertySection);
	ASSERT_NULL_OR_POINTER(lpStorage, IStorage);

	m_bLoading = bLoading;
}
Пример #11
0
BOOL CMonthCalCtrl::GetSelRange(LPSYSTEMTIME pMinRange,
                                LPSYSTEMTIME pMaxRange) const
{
    ASSERT(m_hWnd != NULL);
    ASSERT((GetStyle() & MCS_MULTISELECT));

    ASSERT_POINTER(pMinRange, SYSTEMTIME);
    ASSERT_POINTER(pMaxRange, SYSTEMTIME);

    SYSTEMTIME sysTimes[2];
    BOOL bReturn = (BOOL) ::SendMessage(m_hWnd, MCM_GETSELRANGE,
                                        0, (LPARAM) sysTimes);

    if (bReturn)
    {
        *pMinRange = sysTimes[0];
        *pMaxRange = sysTimes[1];
    }

    return bReturn;
}
Пример #12
0
GvRouteToConnection::~GvRouteToConnection()
{
	if (to) {
		//TRACE("GvRouteToConnection::~ Removing outgoing route %p to node %p\n",this,to);
		ASSERT_POINTER(to,GvNode);
		GvNode *tmpTo= to;
		to = NULL; 
		if (!tmpTo->removeConnection(PredRouteFrom,this)) {
			//TRACE("~GvRouteToConnection::~ corresponding routeFrom not found %p\n",this);
		}	
	}	
	//TRACE("GvRouteToConnection::~ %p\n",this);		
}
Пример #13
0
int CXQuestObjective::OnKill( _uint32 hSource, long_ptr lParam )
{
	CGameActor *pActor = static_cast< CGameActor* >( CXObjectPool::GetInstance().GetObj( (_uint32)lParam, TypeGameActor ) );
	if( pActor )
	{
		_lpctstr name = pActor->GetStrAttrib( _T("name") );
		ASSERT_POINTER( name );
		if( name && m_strName == name && Increment() )
		{
			// 任务完成则将触发器摘除
			ThisTriggerMgr()->DismissTrigger( hSource, 0, this, &CXQuestObjective::OnKill );
		}
	}
	return false;
}
Пример #14
0
//-----------------------------------------------------------------------------
// static member function - the controlling function for the worker thread
// pParam: DOWNLOADPARAM *
//		   {
//			   HWND hWnd - IN				the window handle to display status
//			   HANDLE hEventStop - IN		the event object to signal to stop
//			   CString strURL - IN			the URL of the file to be downloaded
//			   CString strFileName - OUT	the filename of the downloaded file
//		   }
// return value: not used
UINT AsyncDownloader::Download(LPVOID pParam)
{
	DOWNLOADPARAM *const pDownloadParam = static_cast<DOWNLOADPARAM *>(pParam);
	ASSERT_POINTER(pDownloadParam, DOWNLOADPARAM);

	ASSERT(::IsWindow(pDownloadParam->hWnd));

	/*
		URLDownloadToCacheFile is a blocking function. Even though the data is
		downloaded asynchronously the function does not return until all the
		data is downloaded. If complete asynchronous downloading is desired,
		one of the other UOS functions, such as URLOpenStream, or perhaps
		general URL monikers would be more appropriate.
	*/

	::DeleteUrlCacheEntry(pDownloadParam->strURL);

	CBSCallbackImpl bsc(pDownloadParam->hWnd, pDownloadParam->hEventStop);

	const HRESULT hr = ::URLDownloadToCacheFile(NULL,
												pDownloadParam->strURL,
												pDownloadParam->strFileName.
													GetBuffer(MAX_PATH),
												URLOSTRM_GETNEWESTVERSION,
												0,
												&bsc);

	/*
		The resource from the cache is used for the second and subsequent
		calls to URLDownloadToCacheFile during the session of the program
		unless the following setting is selected, in which case, every call
		to URLDownloadToCacheFile downloads the resource from the Internet.

		Control Panel/Internet/General/Temporary Internet files/Settings/
		Check for newer versions of stored pages -> Every visit to the page
	*/

	// empty the filename string if failed or canceled
	pDownloadParam->strFileName.ReleaseBuffer(SUCCEEDED(hr) ? -1 : 0);

	TRACE(_T("URLDownloadToCacheFile ends: 0x%08lX\nCache file name: %s\n"),
		  hr, pDownloadParam->strFileName);

	// let the dialog box know it is done
	VERIFY(::PostMessage(pDownloadParam->hWnd, WM_USER_ENDDOWNLOAD, 0, 0));

	return 0;
}
Пример #15
0
// find a specific connection filtered by predicate function
GvConnection* 
GvField::findConnection(GvBool (*Pred)(GvConnection *c, void *data),void *data)
{
    GvConnection *c = connections;
    while (c!= NULL) {
		
		ASSERT_POINTER(c,GvConnection);

        GvConnection *next =  c->next;
        if (Pred(c,data)) {
            return(c);
        }
        c = next;
    }
    return(NULL);

}
Пример #16
0
void CDialogTemplate::GetSizeInDialogUnits(SIZE* pSize) const
{
	ASSERT(m_hTemplate != NULL);
	ASSERT_POINTER(pSize, SIZE);

	DLGTEMPLATE* pTemplate = (DLGTEMPLATE*)GlobalLock(m_hTemplate);

	if (IsDialogEx(pTemplate))
	{
		pSize->cx = ((DLGTEMPLATEEX*)pTemplate)->cx;
		pSize->cy = ((DLGTEMPLATEEX*)pTemplate)->cy;
	}
	else
	{
		pSize->cx = pTemplate->cx;
		pSize->cy = pTemplate->cy;
	}

	GlobalUnlock(m_hTemplate);
}
Пример #17
0
GvBool GvField::removeConnection(GvBool (*Pred)(GvConnection *c, void *data),void *data)
{
    GvConnection ** prev = &connections;
    GvConnection *c = connections;
    while (c!= NULL) {
		
		ASSERT_POINTER(c,GvConnection);

        GvConnection *next =  c->next;
        if (Pred(c,data)) {
            *prev = next;
            delete c;
            return(TRUE);
        }
        prev = &c->next;
        c = next;
    }
    return(FALSE);

}
Пример #18
0
void CDataVectGrouping::operator () (SData* pData)
{
	ASSERT_POINTER(pData, SData);

	const CString sLastUser = (NULL != m_pLastGroupData) ? m_pLastGroupData->user : "";
	const CString sLastTime = (NULL != m_pLastGroupData) ? m_pLastGroupData->time : "";
	const CString sLastDate = sLastTime.Left(10);
	const CString sThisDate = pData->time.Left(10);
	

	if (sLastUser != pData->user || sLastDate != sThisDate)
	{
		ValidateLastGroup();
		m_group_vect.push_back(m_pLastGroupData = new SGroupData);
	}

	ASSERT(NULL != m_pLastGroupData->data_vect);
	
	m_pLastGroupData->time = pData->time;
	m_pLastGroupData->user = pData->user;
	m_pLastGroupData->data_vect->push_back(pData);
}
Пример #19
0
// remove a specific connection
// if found connection is deleted, only first is searched 
GvBool GvField::removeConnection(GvConnection *connection)
{
    GvConnection ** prev = &connections;
    GvConnection *c = connections;
    
    while (c!= NULL) {


		ASSERT_POINTER(c,GvConnection);

        GvConnection *next =  c->next;
        if (c == connection) {
            *prev = next;
            delete c;
            return(TRUE);
        }
        prev = &c->next;
        c = next;
    }
    return(FALSE);

}
Пример #20
0
DWORD WINAPI CBusyThread::InnerThreadProc(LPVOID lpThisParam)
{
    ULONG ulResult = -1;

    int nRetCode = false;
    CBusyThread *pThis = (CBusyThread *)lpThisParam;

    ASSERT_POINTER(pThis, CBusyThread);

    if (NULL == pThis)
        goto Exit0;

    nRetCode = pThis->PreExecution();
    if (!nRetCode)
        goto Exit0;

    ulResult = pThis->MainExecution();
    pThis->PostExecution();

Exit0:
    return ulResult;
}
Пример #21
0
void CDialogTemplate::GetSizeInPixels(SIZE* pSize) const
{
	ASSERT(m_hTemplate != NULL);
	ASSERT_POINTER(pSize, SIZE);

	if (m_bSystemFont)
	{
		GetSizeInDialogUnits(pSize);
		DWORD dwDLU = GetDialogBaseUnits();
		pSize->cx = (pSize->cx * LOWORD(dwDLU)) / 4;
		pSize->cy = (pSize->cy * HIWORD(dwDLU)) / 8;
	}
	else
	{
		CString strFace;
		WORD wSize = 10;
		GetFont(strFace, wSize);

		SIZE size;
		GetSizeInDialogUnits(&size);
		_AfxConvertDialogUnitsToPixels(strFace, wSize, size.cx, size.cy, pSize);
	}
}
Пример #22
0
// trigger all outgoing connections 
int GvField::OnTrigger() 
{
    GvConnection *c = connections;
	if (!c) return 0;
	
	if (container != (GvNode*) NULL)
		container->ref();

    int ret=0;
    while (c!=NULL) {
		  
		  ASSERT_POINTER(c,GvConnection);
		  
		  GvConnection *next = c->next;
		  
          ret=c->OnTrigger(this);
          c = next;
    }
	if (container != (GvNode*) NULL)
		 container->unrefNoDelete();
	

    return(ret);
}
Пример #23
0
// delete all connections
int GvField::deleteConnections()
{
    GvConnection *c = connections;
	GvConnection *next;

	connections = NULL;


    while (c!= NULL) {

	
		ASSERT_POINTER(c,GvConnection);
        
		next =  c->next;

        delete c;

        c= next;
    }
	

    return(0);

}
Пример #24
0
BOOL CPropsetPropExchange::ExchangePersistentProp(LPCTSTR pszPropName,
		LPUNKNOWN* ppUnk, REFIID iid, LPUNKNOWN pUnkDefault)
{
	ASSERT(AfxIsValidString(pszPropName));
	ASSERT_POINTER(ppUnk, LPUNKNOWN);
	ASSERT_NULL_OR_POINTER(pUnkDefault, IUnknown);

	BOOL bSuccess = FALSE;

	if (m_bLoading)
	{
		RELEASE(*ppUnk);
		*ppUnk = NULL;

		DWORD vtType;
		LPSTREAM pstm = _AfxLoadStreamFromPropset(m_psec, pszPropName, vtType);

		if (pstm != NULL)
		{
			CLSID clsid;

			switch(vtType)
			{
			case VT_BLOB:
				if (_AfxPeekAtClassIDInStream(pstm, &clsid))
				{
					if (IsEqualCLSID(clsid, CLSID_StdPicture) ||
						IsEqualCLSID(clsid, _afx_CLSID_StdPicture_V1))
					{
						// Special case: load the picture directly.
						bSuccess = SUCCEEDED(::ReadClassStm(pstm, &clsid)) &&
							SUCCEEDED(::OleLoadPicture(pstm, 0, FALSE, iid,
							(LPVOID*)ppUnk));
					}
					else
					{
						// Load the object.
						bSuccess = SUCCEEDED(::OleLoadFromStream(pstm, iid,
							(LPVOID*)ppUnk));
					}
				}
				break;

			case VT_BLOB_PROPSET:
				*ppUnk = _AfxCreateObjectFromStreamedPropset(pstm, iid);
				break;

			default:
				break;
			}

			pstm->Release();
		}

		if (!bSuccess && (pUnkDefault != NULL))
		{
			bSuccess = SUCCEEDED(pUnkDefault->QueryInterface(iid,
				(LPVOID*)ppUnk));
		}
	}
	else
	{
		if ((*ppUnk == NULL) ||
			_AfxIsSameUnknownObject(iid, *ppUnk, pUnkDefault))
		{
			bSuccess = TRUE;
		}
		else
		{
			++m_dwPropID;

			bSuccess = m_psec.SetName(m_dwPropID, pszPropName) &&
				_AfxSaveObjectInPropset(*ppUnk, m_psec, m_dwPropID);
		}
	}

	return bSuccess;
}
Пример #25
0
BOOL COleControl::SetPropsetData(LPFORMATETC lpFormatEtc,
		LPSTGMEDIUM lpStgMedium, REFCLSID fmtid)
{
	UNUSED(lpFormatEtc); // unused in release builds

	ASSERT_VALID(this);
	ASSERT(AfxIsValidAddress(lpFormatEtc, sizeof(FORMATETC), FALSE));
	ASSERT(AfxIsValidAddress(lpStgMedium, sizeof(STGMEDIUM)));

	// Get the stream that contains the property set.

	LPSTORAGE lpStorage = NULL;
	LPSTREAM lpStream = NULL;

	switch (lpStgMedium->tymed)
	{
	case TYMED_ISTORAGE:
		{
			lpStorage = lpStgMedium->pstg;
			ASSERT_POINTER(lpStorage, IStorage);
			if (FAILED(lpStorage->OpenStream(OLESTR("Contents"), 0,
					STGM_SHARE_EXCLUSIVE|STGM_READ, 0, &lpStream)))
			{
				TRACE0("Failed to open content stream.\n");
				return FALSE;
			}
		}
		break;

	case TYMED_ISTREAM:
		lpStorage = NULL;
		lpStream = lpStgMedium->pstm;
		break;

	default:
		TRACE0("Propset only supported for stream or storage.\n");
		return FALSE;
	}

	ASSERT_POINTER(lpStream, IStream);

	// Read the property set from the stream.

	CPropertySet pset;
	if (!pset.ReadFromStream(lpStream))
	{
		TRACE0("CPropertySet::ReadFromStream failed.\n");
		return FALSE;
	}

	CPropertySection* ppsec = pset.GetSection(fmtid);
	if (ppsec == NULL)
	{
		TRACE0("CLSID_PersistPropset section not found in property set.\n");
		return FALSE;
	}

	// Detect whether we're converting a VBX
	m_bConvertVBX = (BYTE)IsEqualGUID(fmtid, CLSID_ConvertVBX);

	// Parse the property set.

	CPropsetPropExchange propx(*ppsec, lpStorage, TRUE);

	BOOL bPropExchange = FALSE;
	TRY
	{
		DoPropExchange(&propx);
		bPropExchange = TRUE;
	}
	END_TRY

	// Properties have probably changed
	BoundPropertyChanged(DISPID_UNKNOWN);
	InvalidateControl();

	m_bConvertVBX = FALSE;

	// Clear the modified flag.
	m_bModified = FALSE;

	// Unless IOleObject::SetClientSite is called after this, we can
	// count on ambient properties being available while loading.
	m_bCountOnAmbients = TRUE;

	// Properties have been initialized
	m_bInitialized = TRUE;

	// Cleanup.
	if (lpStorage != NULL)      // If we called OpenStream(), release now.
		lpStream->Release();

	BoundPropertyChanged(DISPID_UNKNOWN);
	return bPropExchange;
}
Пример #26
0
BOOL COleControl::GetPropsetData(LPFORMATETC lpFormatEtc,
		LPSTGMEDIUM lpStgMedium, REFCLSID fmtid)
{
	ASSERT_VALID(this);
	ASSERT(AfxIsValidAddress(lpFormatEtc, sizeof(FORMATETC), FALSE));
	ASSERT(AfxIsValidAddress(lpStgMedium, sizeof(STGMEDIUM)));

	BOOL bGetDataHere = (lpStgMedium->tymed != TYMED_NULL);

	// Allow IStream or IStorage as the storage medium.

	if (!(lpFormatEtc->tymed & (TYMED_ISTREAM|TYMED_ISTORAGE)))
	{
		TRACE0("Propset only supported for stream or storage.\n");
		return FALSE;
	}

	LPSTORAGE lpStorage = NULL;
	LPSTREAM lpStream = NULL;

	if (lpFormatEtc->tymed & TYMED_ISTORAGE)
	{
		// Caller wants propset data in a storage object.

		if (bGetDataHere)
		{
			// Use the caller-supplied storage object.
			lpStorage = lpStgMedium->pstg;
		}
		else
		{
			// Create a storage object on a memory ILockBytes implementation.
			LPLOCKBYTES lpLockBytes = NULL;

			if (FAILED(CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes)))
			{
				TRACE0("CreateILockBytesOnHGlobal failed.\n");
				return FALSE;
			}

			ASSERT_POINTER(lpLockBytes, ILockBytes);

			if (FAILED(StgCreateDocfileOnILockBytes(lpLockBytes,
					STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0,
					&lpStorage)))
			{
				TRACE0("StgCreateDocfileOnILockBytes failed.\n");
				lpLockBytes->Release();
				return FALSE;
			}

			// Docfile now has reference to ILockBytes, so release ours.
			lpLockBytes->Release();
		}

		ASSERT_POINTER(lpStorage, IStorage);

		// Create a stream within the storage.
		if (FAILED(lpStorage->CreateStream(OLESTR("Contents"),
				STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, 0,
				&lpStream)))
		{
			TRACE0("IStorage::CreateStream failed.\n");
			if (!bGetDataHere)
				lpStorage->Release();
			return FALSE;
		}
	}
	else
	{
		// Caller wants propset data in a stream object.

		if (bGetDataHere)
		{
			// Use the caller-supplied stream object
			lpStream = lpStgMedium->pstm;
		}
		else
		{
			lpStream = _AfxCreateMemoryStream();
			if (lpStream == NULL)
				return FALSE;
		}
	}

	ASSERT_POINTER(lpStream, IStream);

	// Create the property set.

	CLSID clsid;
	GetClassID(&clsid);
	CPropertySet pset(clsid);
	pset.SetOSVersion(MAKELONG(LOWORD(GetVersion()), OSTYPE));
	CPropertySection* ppsec = pset.AddSection(fmtid);
	if (ppsec == NULL)
	{
		TRACE0("CPropertySet::AddSection failed.\n");
		lpStream->Release();
		lpStorage->Release();
		return FALSE;
	}

	// Set the name, based on the ambient display name (from the container).
	ppsec->SetSectionName(AmbientDisplayName());

	CPropsetPropExchange propx(*ppsec, lpStorage, FALSE);

	BOOL bPropExchange = FALSE;
	TRY
	{
		DoPropExchange(&propx);
		bPropExchange = TRUE;
	}
	END_TRY

	if (!bPropExchange)
	{
		TRACE0("DoPropExchange failed.\n");
		lpStream->Release();
		lpStorage->Release();
		return FALSE;
	}

	// Store the property set in the stream.

	if (FAILED(pset.WriteToStream(lpStream)))
	{
		TRACE0("CPropertySet::WriteToStream failed.\n");
		lpStream->Release();
		lpStorage->Release();
		return FALSE;
	}

	// Return the property set in the requested medium.

	if (lpFormatEtc->tymed & TYMED_ISTORAGE)
	{
		// Return as a storage object.

		ASSERT_POINTER(lpStorage, IStorage);
		lpStream->Release();
		lpStgMedium->pstg = lpStorage;
		lpStgMedium->tymed = TYMED_ISTORAGE;
		lpStgMedium->pUnkForRelease = NULL;
	}
	else
	{
		// Return as a stream.

		ASSERT_POINTER(lpStream, IStream);
		lpStgMedium->pstm = lpStream;
		lpStgMedium->tymed = TYMED_ISTREAM;
		lpStgMedium->pUnkForRelease = NULL;
	}

	return TRUE;
}
Пример #27
0
BOOL CPropsetPropExchange::ExchangeBlobProp(LPCTSTR pszPropName,
	HGLOBAL* phBlob, HGLOBAL hBlobDefault)
{
	ASSERT(AfxIsValidString(pszPropName));
	ASSERT_POINTER(phBlob, HGLOBAL);

	BOOL bSuccess = FALSE;
	ULONG cb = 0;
	void* pvBlob = NULL;

	if (m_bLoading)
	{
		if (*phBlob != NULL)
		{
			GlobalFree(*phBlob);
			*phBlob = NULL;
		}

		DWORD dwPropID;
		LPVOID pvData;

		if (m_psec.GetID(pszPropName, &dwPropID) &&
			((pvData = m_psec.Get(dwPropID)) != NULL))
		{
			// Copy count and blob data

			cb = *(ULONG*)pvData;

			if (cb > 0)
			{
				bSuccess = _AfxInitBlob(phBlob, pvData);
			}
			else
			{
				bSuccess = (cb == 0);
			}
		}

		if (!bSuccess)
		{
			// Failed.  Use default values.

			if (hBlobDefault != NULL)
				_AfxCopyBlob(phBlob, hBlobDefault);

			bSuccess = TRUE;
		}
	}
	else
	{
		++m_dwPropID;

		pvBlob = NULL;
		if (*phBlob != NULL)
			pvBlob = GlobalLock(*phBlob);

		ULONG lZero = 0;
		void* pvBlobSave = (pvBlob != NULL) ? pvBlob : &lZero;

		bSuccess = m_psec.SetName(m_dwPropID, pszPropName) &&
			m_psec.Set(m_dwPropID, pvBlobSave, VT_BLOB);

		if ((*phBlob != NULL) && (pvBlob != NULL))
			GlobalUnlock(*phBlob);
	}

	return bSuccess;
}
Пример #28
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;
}
Пример #29
0
BOOL CPropsetPropExchange::ExchangeFontProp(LPCTSTR pszPropName,
		CFontHolder& font, const FONTDESC* pFontDesc,
		LPFONTDISP pFontDispAmbient)
{
	ASSERT(AfxIsValidString(pszPropName));
	ASSERT_POINTER(&font, CFontHolder);
	ASSERT_NULL_OR_POINTER(pFontDesc, FONTDESC);
	ASSERT_NULL_OR_POINTER(pFontDispAmbient, IFontDisp);

	BOOL bSuccess = FALSE;

	if (m_bLoading)
	{
		DWORD vtType;
		LPSTREAM pstm = _AfxLoadStreamFromPropset(m_psec, pszPropName, vtType);

		if (pstm != NULL)
		{
			LPFONT pFont;

			switch(vtType)
			{
			case VT_BLOB:
				pFont = _AfxCreateFontFromStream(pstm);
				break;

			case VT_BLOB_PROPSET:
				pFont = (LPFONT)_AfxCreateObjectFromStreamedPropset(pstm,
					IID_IFont);
				break;

			default:
				pFont = NULL;
			}

			if (pFont != NULL)
			{
				font.SetFont(pFont);
				bSuccess = TRUE;
			}

			pstm->Release();
		}

		if (!bSuccess)
		{
			// Initialize font to its default state
			font.InitializeFont(pFontDesc, pFontDispAmbient);
		}
	}
	else
	{
		if ((font.m_pFont == NULL) ||
			_AfxIsSameFont(font, pFontDesc, pFontDispAmbient))
		{
			bSuccess = TRUE;
		}
		else
		{
			++m_dwPropID;

			bSuccess = m_psec.SetName(m_dwPropID, pszPropName) &&
				_AfxSaveObjectInPropset(font.m_pFont, m_psec, m_dwPropID);
		}
	}

	return bSuccess;
}