當前位置: 首頁>>代碼示例>>C++>>正文


C++ AfxThrowMemoryException函數代碼示例

本文整理匯總了C++中AfxThrowMemoryException函數的典型用法代碼示例。如果您正苦於以下問題:C++ AfxThrowMemoryException函數的具體用法?C++ AfxThrowMemoryException怎麽用?C++ AfxThrowMemoryException使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了AfxThrowMemoryException函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: ASSERT_VALID

void CListViewWalkerPropertySheet::InsertPage(int iIndex, CPropertyPage* pPage)
{
    ASSERT_VALID( this );
    ASSERT( pPage != NULL );
    ASSERT_KINDOF( CPropertyPage, pPage );
    ASSERT_VALID( pPage );

    m_pages.InsertAt(iIndex, pPage);
    BuildPropPageArray();

    if (m_hWnd != NULL)
    {
        PROPSHEETPAGE* ppsp = const_cast<PROPSHEETPAGE*>(m_psh.ppsp);
        for (UINT i = 0; i < m_psh.nPages; i++) {
            if (i == (UINT)iIndex)
                break;
            (BYTE*&)ppsp += ppsp->dwSize;
        }

        HPROPSHEETPAGE hPSP = CreatePropertySheetPage(ppsp);
        if (hPSP == NULL)
            AfxThrowMemoryException();

        if (!SendMessage(PSM_INSERTPAGE, iIndex, (LPARAM)hPSP)) {
            DestroyPropertySheetPage(hPSP);
            AfxThrowMemoryException();
        }
    }
}
開發者ID:acat,項目名稱:emule,代碼行數:29,代碼來源:ListViewWalkerPropertySheet.cpp

示例2: ASSERT_VALID

void CBasePropertySheet::AddPage(CPropertyPage* pPage)
{
	ASSERT_VALID(this);
	ASSERT(pPage != NULL);
	ASSERT_KINDOF(CPropertyPage, pPage);
	ASSERT_VALID(pPage);

	// add page to internal list
	m_pages.Add(pPage);

	// add page externally
	if (m_hWnd != NULL)
	{
		// build new prop page array
		AFX_OLDPROPSHEETPAGE *ppsp = new AFX_OLDPROPSHEETPAGE[m_pages.GetSize()];
		memcpy(ppsp, m_psh.ppsp, sizeof(AFX_OLDPROPSHEETPAGE) * (m_pages.GetSize()-1));
		delete[] (PROPSHEETPAGE*)m_psh.ppsp;
		m_psh.ppsp = (PROPSHEETPAGE*)ppsp;
		ppsp += m_pages.GetSize()-1;

		// copy processed PROPSHEETPAGE struct to end
		memcpy(ppsp, &pPage->m_psp, sizeof(pPage->m_psp));
//		pPage->PreProcessPageTemplate((PROPSHEETPAGE&)*ppsp, IsWizard());
		CPropertyPage_PreProcessPageTemplate((_CCPropertyPage*)pPage, (PROPSHEETPAGE&)*ppsp, IsWizard());
		HPROPSHEETPAGE hPSP = CreatePropertySheetPage((PROPSHEETPAGE*)ppsp);
		if (hPSP == NULL)
			AfxThrowMemoryException();

		if (!SendMessage(PSM_ADDPAGE, 0, (LPARAM)hPSP))
		{
			DestroyPropertySheetPage(hPSP);
			AfxThrowMemoryException();
		}
	}
}
開發者ID:hackshields,項目名稱:antivirus,代碼行數:35,代碼來源:BasePropertySheet.cpp

示例3: ASSERT_VALID

void CMemFile::GrowFile(DWORD dwNewLen)
{
	ASSERT_VALID(this);

	if (dwNewLen > m_nBufferSize)
	{
		// grow the buffer
		DWORD dwNewBufferSize = (DWORD)m_nBufferSize;

		// watch out for buffers which cannot be grown!
		ASSERT(m_nGrowBytes != 0);
		if (m_nGrowBytes == 0)
			AfxThrowMemoryException();

		// determine new buffer size
		while (dwNewBufferSize < dwNewLen)
			dwNewBufferSize += m_nGrowBytes;

		// allocate new buffer
		BYTE* lpNew;
		if (m_lpBuffer == NULL)
			lpNew = Alloc(dwNewBufferSize);
		else
			lpNew = Realloc(m_lpBuffer, dwNewBufferSize);

		if (lpNew == NULL)
			AfxThrowMemoryException();

		m_lpBuffer = lpNew;
		m_nBufferSize = dwNewBufferSize;
	}
	ASSERT_VALID(this);
}
開發者ID:anyue100,項目名稱:winscp,代碼行數:33,代碼來源:filemem.cpp

示例4: pLock

void CDownloadWithSources::Serialize(CArchive& ar, int nVersion)	// DOWNLOAD_SER_VERSION
{
	CDownloadBase::Serialize( ar, nVersion );

	CQuickLock pLock( Transfers.m_pSection );

	if ( ar.IsStoring() )
	{
		DWORD_PTR nSources = GetCount();
		if ( nSources > Settings.Downloads.SourcesWanted )
			nSources = Settings.Downloads.SourcesWanted;
		ar.WriteCount( nSources );

		for ( POSITION posSource = GetIterator() ; posSource && nSources ; nSources-- )
		{
			CDownloadSource* pSource = GetNext( posSource );

			pSource->Serialize( ar, nVersion );
		}

		ar.WriteCount( m_pXML != NULL ? 1 : 0 );
		if ( m_pXML ) m_pXML->Serialize( ar );
	}
	else // Loading
	{
		for ( DWORD_PTR nSources = ar.ReadCount() ; nSources ; nSources-- )
		{
			// Create new source
			//CDownloadSource* pSource = new CDownloadSource( (CDownload*)this );
			CAutoPtr< CDownloadSource > pSource( new CDownloadSource( static_cast< CDownload* >( this ) ) );
			if ( ! pSource )
				AfxThrowMemoryException();

			// Load details from disk
			pSource->Serialize( ar, nVersion );

			// Extract ed2k client ID from url (m_pAddress) because it wasn't saved
			if ( ! pSource->m_nPort && _tcsnicmp( pSource->m_sURL, _T("ed2kftp://"), 10 ) == 0 )
			{
				CString strURL = pSource->m_sURL.Mid(10);
				if ( ! strURL.IsEmpty() )
					_stscanf( strURL, _T("%lu"), &pSource->m_pAddress.S_un.S_addr );
			}

			InternalAdd( pSource.Detach() );
		}

		if ( ar.ReadCount() )
		{
			m_pXML = new CXMLElement();
			if ( ! m_pXML )
				AfxThrowMemoryException();

			m_pXML->Serialize( ar );
		}
	}
}
開發者ID:lemonxiao0,項目名稱:peerproject,代碼行數:57,代碼來源:DownloadWithSources.cpp

示例5: ASSERT_VALID

void CEditView::ReadFromArchive(CArchive& ar, UINT nLen)
	// Read certain amount of text from the file, assume at least nLen
	// characters (not bytes) are in the file.
{
	ASSERT_VALID(this);

	LPVOID hText = LocalAlloc(LMEM_MOVEABLE, (nLen+1)*sizeof(TCHAR));
	if (hText == NULL)
		AfxThrowMemoryException();

	LPTSTR lpszText = (LPTSTR)LocalLock(hText);
	ASSERT(lpszText != NULL);
	if (ar.Read(lpszText, nLen*sizeof(TCHAR)) != nLen*sizeof(TCHAR))
	{
		LocalUnlock(hText);
		LocalFree(hText);
		AfxThrowArchiveException(CArchiveException::endOfFile);
	}
	// Replace the editing edit buffer with the newly loaded data
	lpszText[nLen] = '\0';
#ifndef _UNICODE
	if (afxData.bWin32s)
	{
		// set the text with SetWindowText, then free
		BOOL bResult = ::SetWindowText(m_hWnd, lpszText);
		LocalUnlock(hText);
		LocalFree(hText);

		// make sure that SetWindowText was successful
		if (!bResult || ::GetWindowTextLength(m_hWnd) < (int)nLen)
			AfxThrowMemoryException();

		// remove old shadow buffer
		delete[] m_pShadowBuffer;
		m_pShadowBuffer = NULL;
		m_nShadowSize = 0;

		ASSERT_VALID(this);
		return;
	}
#endif
	LocalUnlock(hText);
	HLOCAL hOldText = GetEditCtrl().GetHandle();
	ASSERT(hOldText != NULL);
	LocalFree(hOldText);
	GetEditCtrl().SetHandle((HLOCAL)(UINT)(DWORD)hText);
	Invalidate();
	ASSERT_VALID(this);
}
開發者ID:rickerliang,項目名稱:OpenNT,代碼行數:49,代碼來源:viewedit.cpp

示例6: ThrowARSException

//////////////////////////////////////////////////////////////////////////////
// Fills up p_arsEntryId with the contents of EntryId
// IN: EntryId
// OUT: p_arsEntryId
// Returns: 0 - on error, 1 - on success
int CFieldValuePair::FillEntryId(CEntryId &EntryId, AREntryIdList *p_arsEntryId)
{
	// if EntryId is empty, throw an error
	if(EntryId.GetCount() == 0)
	{
		ThrowARSException(CREC_ENTRY_ID_EMPTY, "CFieldValuePair::FillEntryId()");
		return 0;
	}

	p_arsEntryId->numItems = EntryId.GetCount(); // store how many id's will make up this entry id list
	p_arsEntryId->entryIdList = (AREntryIdType*)malloc(sizeof(AREntryIdType) * EntryId.GetCount()); // allocated memory for entryId

	if(p_arsEntryId->entryIdList == NULL)	// ensure memory was allocated
	{
		p_arsEntryId->numItems = 0;
		AfxThrowMemoryException();
		return 0; // return empty entry id because of error
	}

	// now fill p_arsEntryId with the entry id's in the current CEntryId object
	AREntryIdType *pEntryId = p_arsEntryId->entryIdList;
	POSITION pos = EntryId.GetHeadPosition();
	for(unsigned int i=0;
		i<p_arsEntryId->numItems; 
		i++, pEntryId++)
	{
		// should make sure EntryId doesn't have any strings longer than pEntryId
		// can handle
		strcpy((char*)pEntryId, LPCSTR(EntryId.GetNext(pos)) );
	}
	
	// Don't call FreeAREntryIdList.  This should be called by the calling function
	return 1;
}
開發者ID:mellertson,項目名稱:ARExplorer,代碼行數:39,代碼來源:Record.cpp

示例7: GetConfig

void CLATEDView::OnAddlink() 
{
    CLCConfig* pConfig = NULL;
    CLCLink* pLink = NULL;

    pConfig = GetConfig();
    if(!pConfig) {
        return;
    }

    {   //do this in a block due to hourglass
        CHourglass glass;

        pConfig->ActualizeLinks();
    
        pLink = new CLCLink();
        if(!pLink) {
            AfxThrowMemoryException();        
        }
    }

    CDialogTarget dialog(pConfig,pLink,NULL,false,IDS_INSERT_LINK, this,0);
	switch(dialog.DoModal()) {
	    case IDOK:
            pConfig->AddLink(pLink);
            SetModified();
            break;
        case IDCANCEL:
        default:
            pLink->Release();
            break;
    }
}
開發者ID:LM25TTD,項目名稱:ATCMcontrol_Engineering,代碼行數:33,代碼來源:latedview.cpp

示例8: BrowseDir

void CWizBrowseDirectory::BrowseDir(CString& retStr, CWnd* pFromWnd, LPCTSTR
Title) {
    LPMALLOC pMalloc;
    /* Get's the Shell's default allocator */
    if (NOERROR != ::SHGetMalloc(&pMalloc)) AfxThrowMemoryException();

        BROWSEINFO   bi;
    TCHAR        pszBuffer[MAX_PATH];
    LPITEMIDLIST pidl;

    InitBrowseInfo(bi, pFromWnd, Title);
    bi.pszDisplayName = pszBuffer;

    // This next call issues the dialog box 
  __try {
                if ((pidl = ::SHBrowseForFolder(&bi)) != NULL) {
          __try {
                if (::SHGetPathFromIDList(pidl, pszBuffer)) { 
                    //At this point pszBuffer contains the selected path */
                    retStr = pszBuffer;
                                }
                        }
          __finally {
                                // Free the PIDL allocated by SHBrowseForFolder
                pMalloc->Free(pidl);
            }
        }
    }
開發者ID:KerwinMa,項目名稱:AerothFlyffSource,代碼行數:28,代碼來源:browsedirectory.cpp

示例9: ASSERT

void CSelNumberDlgUsage::Change (const CString &strTableName, UINT uiCaption, CString& strAktNummer, CSelectSet* pSelectSet)
{
	try
	{	
		if (!m_pNumberDlg)
		{
			ASSERT (NULL != pSelectSet);
			ASSERT (pSelectSet -> IsOpen ());
			ASSERT (!strTableName.IsEmpty ());
			m_pNumberDlg = new CSelNumberDlg (this, pSelectSet, uiCaption,
											  strTableName);
			if (!m_pNumberDlg -> Create (IDD_SEL_NUMMER))
				AfxThrowMemoryException ();
		}		

	//	aktuelle Selektion setzen
		m_pNumberDlg -> StoreSelection (strAktNummer);

	//	Fenster aktivieren
		m_pNumberDlg -> ShowWindow (SW_SHOWNORMAL);	
		m_pNumberDlg -> SetFocus ();
	}
	catch (CDaoException *e)
	{
		:: DisplayDaoException (e);
		e -> Delete ();
		DELETE_OBJ (m_pNumberDlg);
	}
	catch (CException* e)
	{
		e -> ReportError ();
		e -> Delete ();
		DELETE_OBJ (m_pNumberDlg);
	}
}
開發者ID:hkaiser,項目名稱:TRiAS,代碼行數:35,代碼來源:SelNumberDlgUsage.cpp

示例10: ASSERT

CSafeThread* CSafeThread::BeginThread(CRuntimeClass* pThreadClass,
		int nPriority, UINT nStackSize, DWORD dwCreateFlags,
		LPSECURITY_ATTRIBUTES lpSecurityAttrs)
{
	ASSERT(pThreadClass != NULL);
	ASSERT(pThreadClass->IsDerivedFrom(RUNTIME_CLASS(CSafeThread)));

	CSafeThread* pThread = (CSafeThread*)pThreadClass->CreateObject();
	if (pThread == NULL)
		AfxThrowMemoryException();
	ASSERT_VALID(pThread);

	pThread->m_pThreadParams = NULL;
	if (!pThread->CreateThread(dwCreateFlags|CREATE_SUSPENDED, nStackSize,
		lpSecurityAttrs))
	{
		pThread->Delete();
		return NULL;
	}
	VERIFY(pThread->SetThreadPriority(nPriority));
	if (!(dwCreateFlags & CREATE_SUSPENDED))
	{
		ENSURE(pThread->ResumeThread() != (DWORD)-1);
	}

	return pThread;
}
開發者ID:HackLinux,項目名稱:eMule-IS-Mod,代碼行數:27,代碼來源:SafeThread.cpp

示例11: GetClientRect

BOOL CPropertyChoiceDlg::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
// nichtmodalen CPropertySheet erzeugen
	TRY {
	CRect rcClient;

		GetClientRect(&rcClient);
		m_pSheet = new CChoiceParent (rcClient, m_strDesc.c_str()); 
		if (!m_pSheet -> Create(this, WS_VISIBLE|WS_CHILD|DS_CONTROL, 0))
			AfxThrowMemoryException();

	// geforderte Pages einhängen
		for (CPageList::iterator it = m_Pages.begin(); 
			 it != m_Pages.end(); it++) 
		{
			m_pSheet -> SendMessage (PSM_ADDPAGE, 0, LPARAM(HPROPSHEETPAGE(*it)));
		}

		m_pSheet -> CleanUp();		// DummyPage wieder entfernen

	} CATCH(CMemoryException, e) {
		return E_OUTOFMEMORY;
	} END_CATCH;

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
開發者ID:hkaiser,項目名稱:TRiAS,代碼行數:29,代碼來源:PropertyChoice.cpp

示例12: pFile

void CLibraryMaps::Serialize2(CArchive& ar, int nVersion)
{
	if ( nVersion < 18 ) return;

	if ( ar.IsStoring() )
	{
		ar.WriteCount( m_pDeleted.GetCount() );

		for ( POSITION pos = m_pDeleted.GetHeadPosition() ; pos ; )
		{
			m_pDeleted.GetNext( pos )->Serialize( ar, nVersion );
		}
	}
	else // Loading
	{
		for ( DWORD_PTR nCount = ar.ReadCount() ; nCount > 0 ; nCount-- )
		{
			//CLibraryFile* pFile = new CLibraryFile( NULL );
			CAutoPtr< CLibraryFile > pFile( new CLibraryFile( NULL ) );
			if ( ! pFile )
				AfxThrowMemoryException();

			pFile->Serialize( ar, nVersion );

			if ( ! LibraryMaps.LookupFileByHash( pFile ) )
				Library.AddFile( pFile.Detach() );
		}
	}
}
開發者ID:lemonxiao0,項目名稱:peerproject,代碼行數:29,代碼來源:LibraryMaps.cpp

示例13: AfxCriticalNewHandler

int AFX_CDECL AfxCriticalNewHandler(size_t nSize)
	// nSize is already rounded
{
	// called during critical memory allocation
	//  free up part of the app's safety cache
	TRACE0("Warning: Critical memory allocation failed!\n");
	_AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
	if (pThreadState != NULL && pThreadState->m_pSafetyPoolBuffer != NULL)
	{
		size_t nOldBufferSize = _msize(pThreadState->m_pSafetyPoolBuffer);
		if (nOldBufferSize <= nSize + MIN_MALLOC_OVERHEAD)
		{
			// give it all up
			TRACE0("Warning: Freeing application's memory safety pool!\n");
			free(pThreadState->m_pSafetyPoolBuffer);
			pThreadState->m_pSafetyPoolBuffer = NULL;
		}
		else
		{
			BOOL bEnable = AfxEnableMemoryTracking(FALSE);
			_expand(pThreadState->m_pSafetyPoolBuffer,
				nOldBufferSize - (nSize + MIN_MALLOC_OVERHEAD));
			AfxEnableMemoryTracking(bEnable);
			TRACE3("Warning: Shrinking safety pool from %d to %d to satisfy request of %d bytes.\n",
				 nOldBufferSize, _msize(pThreadState->m_pSafetyPoolBuffer), nSize);
		}
		return 1;       // retry it
	}

	TRACE0("ERROR: Critical memory allocation from safety pool failed!\n");
	AfxThrowMemoryException();      // oops
	return 0;
}
開發者ID:rickerliang,項目名稱:OpenNT,代碼行數:33,代碼來源:winutil.cpp

示例14: ASSERT

COleDataSource* CModuleWnd::PrepareDataSource()
{
	ASSERT(m_pCurrentDocument != NULL);
	
	int nSelectedObjects = GetListCtrl()->GetSelectedCount();
	if (nSelectedObjects < 1)
		return NULL;
	
	STGMEDIUM stgMedium;
	COleDataSource* pDataSource;
	
	pDataSource = new COleDataSource;
	if(pDataSource == NULL)
	{
		AfxThrowMemoryException();
	}
	
	if (!GetSelectModuleData(&stgMedium))
	{
		delete pDataSource;
		return NULL;
	}
	
	pDataSource->CacheData(CDevDoc::m_cfDocData, &stgMedium);
	
	GetDragInfoData(&stgMedium);
	pDataSource->CacheData(CLayoutView::m_cfDragInfo, &stgMedium);
	
	return pDataSource;
}
開發者ID:JackWangCUMT,項目名稱:SuperCxHMI,代碼行數:30,代碼來源:ModuleWnd.cpp

示例15: free

void CBasePropertySheet::BuildPropPageArray()
{
	// delete existing prop page array
	free((void*)m_psh.ppsp);
	m_psh.ppsp = NULL;

	// determine size of PROPSHEETPAGE array
	int i;
	int nBytes = 0;
	for (i = 0; i < m_pages.GetSize(); i++)
	{
		CPropertyPage* pPage = GetPage(i);
		nBytes += pPage->m_psp.dwSize;
	}

	// build new PROPSHEETPAGE array
	PROPSHEETPAGE* ppsp = (PROPSHEETPAGE*)malloc(nBytes);
	BYTE* ppspOrigByte=reinterpret_cast<BYTE*>(ppsp);
	if (ppsp == NULL)
		AfxThrowMemoryException();
	BYTE* pPropSheetPagesArrEnd=ppspOrigByte + nBytes;
	ENSURE(pPropSheetPagesArrEnd >= ppspOrigByte);
	m_psh.ppsp = ppsp;
	BOOL bWizard = (m_psh.dwFlags & (PSH_WIZARD | PSH_WIZARD97));
	for (i = 0; i < m_pages.GetSize(); i++)
	{
		CPropertyPage* pPage = GetPage(i);
		BYTE* ppspByte=reinterpret_cast<BYTE*>(ppsp);		
		ENSURE_THROW(ppspByte >= ppspOrigByte && ppspByte <= pPropSheetPagesArrEnd,AfxThrowMemoryException());
		Checked::memcpy_s(ppsp, pPropSheetPagesArrEnd - reinterpret_cast<BYTE*>(ppsp), &pPage->m_psp, pPage->m_psp.dwSize);

		if (!((_CCPropertyPage*)pPage)->m_strHeaderTitle.IsEmpty())
		{
			ppsp->pszHeaderTitle = ((_CCPropertyPage*)pPage)->m_strHeaderTitle;
			ppsp->dwFlags |= PSP_USEHEADERTITLE;
		}
		if (!((_CCPropertyPage*)pPage)->m_strHeaderSubTitle.IsEmpty())
		{
			ppsp->pszHeaderSubTitle = ((_CCPropertyPage*)pPage)->m_strHeaderSubTitle;
			ppsp->dwFlags |= PSP_USEHEADERSUBTITLE;
		}
//		pPage->PreProcessPageTemplate(*ppsp, bWizard);
		CPropertyPage_PreProcessPageTemplate((_CCPropertyPage*)pPage, *ppsp, bWizard);
		(BYTE*&)ppsp += ppsp->dwSize;
	}
	m_psh.nPages = (int)m_pages.GetSize();
}
開發者ID:hackshields,項目名稱:antivirus,代碼行數:47,代碼來源:BasePropertySheet.cpp


注:本文中的AfxThrowMemoryException函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。