Exemplo n.º 1
0
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();
        }
    }
}
Exemplo n.º 2
0
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();
		}
	}
}
Exemplo n.º 3
0
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);
}
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 );
		}
	}
}
Exemplo n.º 5
0
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);
}
Exemplo n.º 6
0
//////////////////////////////////////////////////////////////////////////////
// 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;
}
Exemplo n.º 7
0
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;
    }
}
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);
            }
        }
    }
Exemplo n.º 9
0
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);
	}
}
Exemplo n.º 10
0
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;
}
Exemplo n.º 11
0
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
}
Exemplo n.º 12
0
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() );
		}
	}
}
Exemplo n.º 13
0
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;
}
Exemplo n.º 14
0
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;
}
Exemplo n.º 15
0
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();
}
int CEncryptedStreamSocket::SendNegotiatingData(const void* lpBuf, uint32_t nBufLen, uint32_t nStartCryptFromByte, bool bDelaySend){	
	ASSERT( m_StreamCryptState == ECS_NEGOTIATING || m_StreamCryptState == ECS_ENCRYPTING );
	ASSERT( nStartCryptFromByte <= nBufLen );
	ASSERT( m_NegotiatingState == ONS_BASIC_SERVER_DELAYEDSENDING || !bDelaySend );

	BYTE* pBuffer = NULL;
	bool bProcess = false;
	if (lpBuf != NULL){
		pBuffer = (BYTE*)malloc(nBufLen);
		if (pBuffer == NULL)
			AfxThrowMemoryException();
		if (nStartCryptFromByte > 0)
			memcpy(pBuffer, lpBuf, nStartCryptFromByte);
		if (nBufLen > nStartCryptFromByte)
			RC4Crypt((uchar*)lpBuf + nStartCryptFromByte, pBuffer + nStartCryptFromByte, nBufLen - nStartCryptFromByte, m_pRC4SendKey);
		if (m_pfiSendBuffer != NULL){
			// we already have data pending. Attach it and try to send
			if (m_NegotiatingState == ONS_BASIC_SERVER_DELAYEDSENDING)
				m_NegotiatingState = ONS_COMPLETE;
			else
				ASSERT( false );
			m_pfiSendBuffer->SeekToEnd();
			m_pfiSendBuffer->Write(pBuffer, nBufLen);
			free(pBuffer);
			pBuffer = NULL;
			nStartCryptFromByte = 0;
			bProcess = true; // we want to try to send it right now
		}
	}
	if (lpBuf == NULL || bProcess){
		// this call is for processing pending data
		if (m_pfiSendBuffer == NULL || nStartCryptFromByte != 0){
			ASSERT( false );
			return 0;							// or not
		}
		nBufLen = (uint32_t)m_pfiSendBuffer->GetLength();
		pBuffer = m_pfiSendBuffer->Detach();
		delete m_pfiSendBuffer;
		m_pfiSendBuffer = NULL;
	}
    ASSERT( m_pfiSendBuffer == NULL );
	uint32_t result = 0;	
	if (!bDelaySend)
		result = CAsyncSocketEx::Send(pBuffer, nBufLen);
	if (result == (uint32_t)SOCKET_ERROR || bDelaySend){
		m_pfiSendBuffer = new CSafeMemFile(128);
		m_pfiSendBuffer->Write(pBuffer, nBufLen);
		free(pBuffer);
		return result;
    }
	else {
		if (result < nBufLen){
			m_pfiSendBuffer = new CSafeMemFile(128);
			m_pfiSendBuffer->Write(pBuffer + result, nBufLen - result);			
		}
		free(pBuffer);
		return result;
	}
}
Exemplo n.º 17
0
BSTR CString::AllocSysString()
{
	BSTR bstr = ::SysAllocStringLen(m_pchData, m_nDataLength);
	if (bstr == NULL)
		AfxThrowMemoryException();

	return bstr;
}
Exemplo n.º 18
0
BSTR CString::AllocSysString() const
{
#if defined(_UNICODE) || defined(OLE2ANSI)
	BSTR bstr = ::SysAllocStringLen(m_pchData, GetData()->nDataLength);
	if (bstr == NULL)
		AfxThrowMemoryException();
#else
	int nLen = MultiByteToWideChar(CP_ACP, 0, m_pchData,
		GetData()->nDataLength, NULL, NULL);
	BSTR bstr = ::SysAllocStringLen(NULL, nLen);
	if (bstr == NULL)
		AfxThrowMemoryException();
	MultiByteToWideChar(CP_ACP, 0, m_pchData, GetData()->nDataLength,
		bstr, nLen);
#endif

	return bstr;
}
Exemplo n.º 19
0
BSTR CString::SetSysString(BSTR* pbstr)
{
	ASSERT(AfxIsValidAddress(pbstr, sizeof(BSTR)));

	if (!::SysReAllocStringLen(pbstr, m_pchData, m_nDataLength))
		AfxThrowMemoryException();

	ASSERT(*pbstr != NULL);
	return *pbstr;
}
Exemplo n.º 20
0
BSTR CString::SetSysString(BSTR* pbstr) const
{
	ASSERT(AfxIsValidAddress(pbstr, sizeof(BSTR)));

#if defined(_UNICODE) || defined(OLE2ANSI)
	if (!::SysReAllocStringLen(pbstr, m_pchData, GetData()->nDataLength))
		AfxThrowMemoryException();
#else
	int nLen = MultiByteToWideChar(CP_ACP, 0, m_pchData,
		GetData()->nDataLength, NULL, NULL);
	if (!::SysReAllocStringLen(pbstr, NULL, nLen))
		AfxThrowMemoryException();
	MultiByteToWideChar(CP_ACP, 0, m_pchData, GetData()->nDataLength,
		*pbstr, nLen);
#endif

	ASSERT(*pbstr != NULL);
	return *pbstr;
}
Exemplo n.º 21
0
void CDemoMFCDlg::OnMFCException()
{
	try
	{
		AfxThrowMemoryException();
	}
	catch (CMemoryException *exc)
	{
		MOD_ASSERT(rbEXCEPTION(*exc));
	}
}
Exemplo n.º 22
0
void CLATEDView::OnAddDestLink() 
{
    HTREEITEM hItem;
    CLCBase* pBase = NULL;
    CLCLink* pLink = NULL;
    CLCDestLink* pDest = NULL;
    CLCConfig* pConfig = NULL;

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

    CTreeCtrl& rTree = GetTreeCtrl();
    hItem = rTree.GetSelectedItem();
    if(hItem == NULL) {
        return;
    }

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

        pConfig->ActualizeLinks();

        pBase = GetNode(hItem);
        if(!pBase) {
            return;
        }

        pLink = dynamic_cast<CLCLink*>(pBase);
        if(!pLink) {
            return;
        }

        pDest = new CLCDestLink();
        if(!pDest) {
            AfxThrowMemoryException();
        }

    }

    CDialogTarget dialog(pConfig,pLink,pDest,false,IDS_INSERT_DESTLINK, this,0);
	switch(dialog.DoModal()) {
	    case IDOK:
            pConfig->AddDestLink(pLink,pDest);
            SetModified();                                    
            break;
        case IDCANCEL:
        default:
            pDest->Release();
            break;
    }

}
Exemplo n.º 23
0
CMiniDockFrameWnd* CFrameWnd::CreateFloatingFrame(DWORD dwStyle)
{
	CMiniDockFrameWnd* pFrame = NULL;
	ASSERT(m_pFloatingFrameClass != NULL);
	pFrame = (CMiniDockFrameWnd*)m_pFloatingFrameClass->CreateObject();
	if (pFrame == NULL)
		AfxThrowMemoryException();
	ASSERT_KINDOF(CMiniDockFrameWnd, pFrame);
	if (!pFrame->Create(this, dwStyle))
		AfxThrowResourceException();
	return pFrame;
}
Exemplo n.º 24
0
BOOL COleServerItem::GetLinkSourceData(LPSTGMEDIUM lpStgMedium)
{
	ASSERT_VALID(this);
	ASSERT(AfxIsValidAddress(lpStgMedium, sizeof(STGMEDIUM)));

	LPOLEOBJECT lpOleObject = GetOleObject();
	ASSERT(lpOleObject != NULL);

	// get moniker from ole object
	LPMONIKER lpMoniker;
	SCODE sc = lpOleObject->GetMoniker(OLEGETMONIKER_TEMPFORUSER,
		OLEWHICHMK_OBJFULL, &lpMoniker);
	if (sc != S_OK)
	{
		TRACE0("Warning: unable to get moniker for object.\n");
		return FALSE;
	}
	ASSERT(lpMoniker != NULL);

	// create a memory based stream to write the moniker to
	LPSTREAM lpStream;
	if (::CreateStreamOnHGlobal(NULL, TRUE, &lpStream) != S_OK)
	{
		lpMoniker->Release();
		AfxThrowMemoryException();
	}
	ASSERT(lpStream != NULL);

	// write the moniker to the stream, and add it to the clipboard
	sc = ::OleSaveToStream(lpMoniker, lpStream);
	lpMoniker->Release();
	if (sc != S_OK)
	{
		lpStream->Release();
		AfxThrowOleException(sc);
	}

	// write the class ID of the document to the stream as well
	COleLinkingDoc* pDoc = GetDocument();
	ASSERT(pDoc->m_pFactory != NULL);
	sc = WriteClassStm(lpStream, pDoc->m_pFactory->GetClassID());
	if (sc != S_OK)
	{
		lpStream->Release();
		AfxThrowOleException(sc);
	}

	// setup the STGMEDIUM
	lpStgMedium->tymed = TYMED_ISTREAM;
	lpStgMedium->pstm = lpStream;
	lpStgMedium->pUnkForRelease = NULL;
	return TRUE;
}
void CDiscoverMDIView::OnInsertObject()
{
	// Invoke the standard Insert Object dialog box to obtain information
	//  for new CDiscoverMDICntrItem object.
	COleInsertDialog dlg;
	if (dlg.DoModal() != IDOK)
		return;

	BeginWaitCursor();

	CDiscoverMDICntrItem* pItem = NULL;
	TRY
	{
		// Create new item connected to this document.
		CDiscoverMDIDoc* pDoc = GetDocument();
		ASSERT_VALID(pDoc);
		pItem = new CDiscoverMDICntrItem(pDoc);
		ASSERT_VALID(pItem);

		// Initialize the item from the dialog data.
		if (!dlg.CreateItem(pItem))
			AfxThrowMemoryException();  // any exception will do
		ASSERT_VALID(pItem);

		// If item created from class list (not from file) then launch
		//  the server to edit the item.
		if (dlg.GetSelectionType() == COleInsertDialog::createNewItem)
			pItem->DoVerb(OLEIVERB_SHOW, this);

		ASSERT_VALID(pItem);

		// As an arbitrary user interface design, this sets the selection
		//  to the last item inserted.

		// TODO: reimplement selection as appropriate for your application

		m_pSelection = pItem;   // set selection to last inserted item
		pDoc->UpdateAllViews(NULL);
	}
	CATCH(CException, e)
	{
		if (pItem != NULL)
		{
			ASSERT_VALID(pItem);
			pItem->Delete();
		}
		AfxMessageBox(IDP_FAILED_TO_CREATE);
	}
	END_CATCH

	EndWaitCursor();
}
Exemplo n.º 26
0
void CDrawView::OnInsertObject()
{
	// Invoke the standard Insert Object dialog box to obtain information
	//  for new CDrawItem object.
	COleInsertDialog dlg;
	if (dlg.DoModal() != IDOK)
		return;

	BeginWaitCursor();

	// First create the C++ object
	CDrawOleObj* pObj = new CDrawOleObj(GetInitialPosition());
	ASSERT_VALID(pObj);
	CDrawItem* pItem = new CDrawItem(GetDocument(), pObj);
	ASSERT_VALID(pItem);
	pObj->m_pClientItem = pItem;

	// Now create the OLE object/item
	TRY
	{
		if (!dlg.CreateItem(pObj->m_pClientItem))
			AfxThrowMemoryException();

		// add the object to the document
		/*GetDocument()->*/g_pGuiManager->AddBack(pObj);
		pObj->m_pDocument = GetDocument();
		GetDocument()->SetModifiedFlag();

		// try to get initial presentation data
		pItem->UpdateLink();
		pItem->UpdateExtent();

		// if insert new object -- initially show the object
		if (dlg.GetSelectionType() == COleInsertDialog::createNewItem)
			pItem->DoVerb(OLEIVERB_SHOW, this);
	}
	CATCH_ALL(e)
	{
		// clean up item
		pItem->Delete();
		pObj->m_pClientItem = NULL;
		/*GetDocument()->*/g_pGuiManager->Remove(pObj);
		GetDocument()->SetModifiedFlag(TRUE);
		pObj->Remove();

		AfxMessageBox(IDP_FAILED_TO_CREATE);
	}
	END_CATCH_ALL

	EndWaitCursor();
}
Exemplo n.º 27
0
void COleServerItem::GetObjectDescriptorData(
	LPPOINT lpOffset, LPSIZE lpSize, LPSTGMEDIUM lpStgMedium)
{
	ASSERT_VALID(this);
	ASSERT(AfxIsValidAddress(lpStgMedium, sizeof(STGMEDIUM)));
	ASSERT(lpOffset == NULL ||
		AfxIsValidAddress(lpOffset, sizeof(POINT), FALSE));

	LPOLEOBJECT lpOleObject = GetOleObject();
	ASSERT(lpOleObject != NULL);

	// get the object descriptor for the IOleObject
	POINTL pointl = { 0, 0 };
	if (lpOffset != NULL)
	{
		CSize ptOffset(lpOffset->x, lpOffset->y);
#ifndef _MAC
		((CDC*)NULL)->DPtoHIMETRIC(&ptOffset);
#endif
		pointl.x = ptOffset.cx;
		pointl.y = ptOffset.cy;
	}
	SIZEL sizel;
	if (lpSize != NULL)
	{
		sizel.cx = lpSize->cx;
		sizel.cy = lpSize->cy;
#ifndef _MAC
		((CDC*)NULL)->DPtoHIMETRIC(&sizel);
#endif
	}
	else
	{
		sizel.cx = 0;
		sizel.cy = 0;
	}

	InterlockedIncrement(&m_dwRef);  // protect against destruction during this call
	HGLOBAL hGlobal = _AfxOleGetObjectDescriptorData(
		lpOleObject, NULL, DVASPECT_CONTENT, pointl, &sizel);
	InterlockedDecrement(&m_dwRef);

	if (hGlobal == NULL)
		AfxThrowMemoryException();

	// setup the STGMEDIUM
	lpStgMedium->tymed = TYMED_HGLOBAL;
	lpStgMedium->hGlobal = hGlobal;
	lpStgMedium->pUnkForRelease = NULL;
}
Exemplo n.º 28
0
CDrawObj* CDrawOleObj::Clone(CDrawDoc* pDoc)
{
	ASSERT_VALID(this);

	AfxGetApp()->BeginWaitCursor();

	CDrawOleObj* pClone = NULL;
	CDrawItem* pItem = NULL;
	TRY
	{
		// perform a "deep copy" -- need to copy CDrawOleObj and the CDrawItem
		//  that it points to.
		pClone = new CDrawOleObj(m_position);
//#pragma warning(suppress:6014)
		pItem = new CDrawItem(m_pDocument, pClone);
		if (!pItem->CreateCloneFrom(m_pClientItem))
		{
			AfxThrowMemoryException();
		}

		pClone->m_pClientItem = pItem;
		pClone->m_bPen = m_bPen;
		pClone->m_logpen = m_logpen;
		pClone->m_bBrush = m_bBrush;
		pClone->m_logbrush = m_logbrush;
		ASSERT_VALID(pClone);

		if (pDoc != NULL)
			pDoc->Add(pClone);
	}
	CATCH_ALL(e)
	{
		if(pItem)
			pItem->Delete();

		if(pClone)
		{
			pClone->m_pClientItem = NULL;
			pClone->Remove();
		}
		AfxGetApp()->EndWaitCursor();

		THROW_LAST();
	}
	END_CATCH_ALL

	AfxGetApp()->EndWaitCursor();
	return pClone;
}
void CABMOfficeSystemcppView::OnInsertObject()
{
	// Invoke the standard Insert Object dialog box to obtain information
	//  for new CABMOfficeSystemcppCntrItem object
	COleInsertDialog dlg;
	if (dlg.DoModal(COleInsertDialog::DocObjectsOnly) != IDOK)
		return;

	BeginWaitCursor();

	CABMOfficeSystemcppCntrItem* pItem = NULL;
	TRY
	{
		// Create new item connected to this document
		CABMOfficeSystemcppDoc* pDoc = GetDocument();
		ASSERT_VALID(pDoc);
		pItem = new CABMOfficeSystemcppCntrItem(pDoc);
		ASSERT_VALID(pItem);

		// Initialize the item from the dialog data
		if (!dlg.CreateItem(pItem))
			AfxThrowMemoryException();  // any exception will do
		ASSERT_VALID(pItem);
		
		pItem->DoVerb(OLEIVERB_SHOW, this);

		ASSERT_VALID(pItem);
		// As an arbitrary user interface design, this sets the selection
		//  to the last item inserted

		// TODO: reimplement selection as appropriate for your application
		m_pSelection = pItem;   // set selection to last inserted item
		pDoc->UpdateAllViews(NULL);
	}
	CATCH(CException, e)
	{
		if (pItem != NULL)
		{
			ASSERT_VALID(pItem);
			pItem->Delete();
		}
		AfxMessageBox(IDP_FAILED_TO_CREATE);
	}
	END_CATCH

	EndWaitCursor();
}
Exemplo n.º 30
0
void CClientView::OnInsertObject()
{
	// 调用标准的“插入对象”对话框以获得有关
	//  新 CClientCntrItem 对象的信息
	COleInsertDialog dlg;
	if (dlg.DoModal(COleInsertDialog::DocObjectsOnly) != IDOK)
		return;

	BeginWaitCursor();

	CClientCntrItem* pItem = NULL;
	TRY
	{
		// 创建与此文档相连接的新项
		CClientDoc* pDoc = GetDocument();
		ASSERT_VALID(pDoc);
		pItem = new CClientCntrItem(pDoc);
		ASSERT_VALID(pItem);

		// 通过对话框数据初始化该项
		if (!dlg.CreateItem(pItem))
			AfxThrowMemoryException();  // 任何异常都将导致该结果
		ASSERT_VALID(pItem);
		
		pItem->DoVerb(OLEIVERB_SHOW, this);

		ASSERT_VALID(pItem);
		// 作为任意用户界面设计,这会将选定内容
		//  设置为插入的最后一项

		// TODO: 重新实现选定内容,使其适合于您的应用程序
		m_pSelection = pItem;   // 将选定内容设置为插入的最后一项
		pDoc->UpdateAllViews(NULL);
	}
	CATCH(CException, e)
	{
		if (pItem != NULL)
		{
			ASSERT_VALID(pItem);
			pItem->Delete();
		}
		AfxMessageBox(IDP_FAILED_TO_CREATE);
	}
	END_CATCH

	EndWaitCursor();
}