void CDrawView::PasteNative(COleDataObject& dataObject) { // get file refering to clipboard data CFile* pFile = dataObject.GetFileData(m_cfDraw); if (pFile == NULL) return; // connect the file to the archive CArchive ar(pFile, CArchive::load); TRY { ar.m_pDocument = GetDocument(); // set back-pointer in archive // read the selection m_selection.Serialize(ar); } CATCH_ALL(e) { ar.Close(); delete pFile; THROW_LAST(); } END_CATCH_ALL ar.Close(); delete pFile; }
void CMsregPacketCatalogOrderLineItem::WriteDataToFile(CFile& cfFile, DWORD& dwChecksum) { CString csCollection; TRY { // Write the category name. CMsregPacket::WriteString(cfFile, m_csCategory, dwChecksum); // Write the quantity. CMsregPacket::WriteDword(cfFile, m_dwQuantity, dwChecksum); // Write the cost. CMsregPacket::WriteDword(cfFile, m_dwCost, dwChecksum); // Write the field count. CMsregPacket::WriteDword(cfFile, CollectionCount(), dwChecksum); // Write collection names. for (int i = 0; i < CollectionCount(); i++) { GetCollection(i, csCollection); CMsregPacket::WriteString(cfFile, csCollection, dwChecksum); } } CATCH_ALL(e) { csCollection.Empty(); THROW_LAST(); } END_CATCH_ALL }
void CInstallDiskSpaceDialog::UpdateDiskSpace(void) { CString csFormat; CString csMessage; CString csAdditional; TRY { LoadConfigurationString(IDS_NotEnoughDiskSpaceFormat1, csFormat); wsprintf(csMessage.GetBuffer(1024), csFormat, (LPCSTR)m_csDrive); csMessage.ReleaseBuffer(); SetDlgItemText(IDC_NOT_ENOUGH_DISK_SPACE_1, csMessage); LoadConfigurationString(IDS_NotEnoughDiskSpaceFormat2, csFormat); Util::FormatDouble(MAKE_DOUBLE(m_dwNeededSize-m_dwAvailableSize), 2, csAdditional); wsprintf(csMessage.GetBuffer(1024), csFormat, (LPCSTR)csAdditional, (LPCSTR)m_csDrive); csMessage.ReleaseBuffer(); SetDlgItemText(IDC_NOT_ENOUGH_DISK_SPACE_2, csMessage); } CATCH_ALL(e) { csFormat.Empty(); csMessage.Empty(); csAdditional.Empty(); THROW_LAST(); } END_CATCH_ALL }
void COleServerItem::OnSaveEmbedding(LPSTORAGE lpStorage) { ASSERT(lpStorage != NULL); // always (logically) a "File.Save Copy As" operation COleServerDoc* pDoc = GetDocument(); LPSTORAGE lpOrigStg = pDoc->m_lpRootStg; pDoc->m_lpRootStg = lpStorage; TRY { ASSERT(pDoc->m_lpRootStg != NULL); pDoc->SaveToStorage(this); // use helper to serialize to storage } CATCH_ALL(e) { // save as failed: re-attach original storage pDoc->m_lpRootStg = lpOrigStg; THROW_LAST(); } END_CATCH_ALL // re-attach original storage pDoc->m_lpRootStg = lpOrigStg; }
void CMsregPacketCatalogOrderLineItemArray::ReadDataFromFile(CFile& cfFile, DWORD& dwChecksum) { CMsregPacketCatalogOrderLineItem* pLineItem = NULL; TRY { // Remove any current line items. RemoveAll(); // Read the line item count. DWORD dwLineItems = CMsregPacket::ReadDword(cfFile, dwChecksum); // Read the line items. for (DWORD i = 0; i < dwLineItems; i++) { pLineItem = new CMsregPacketCatalogOrderLineItem; pLineItem->ReadDataFromFile(cfFile, dwChecksum); Add(pLineItem); pLineItem = NULL; } } CATCH_ALL(e) { delete pLineItem; THROW_LAST(); } END_CATCH_ALL }
DWORD COXCheckBase::CalculateFile(CFile* pFile, DWORD nCount /*= 0xFFFFFFFF*/, DWORD nBufferLength /*= 2048*/) { LPBYTE pBuffer; DWORD nLengthRead; DWORD nOldCheck32 = m_nCheck32; if (nCount < nBufferLength) nBufferLength = nCount; pBuffer = new BYTE[nBufferLength]; do { TRY { nLengthRead = pFile->Read(pBuffer, nBufferLength); } CATCH(CFileException, e) { m_nCheck32 = nOldCheck32; delete[] pBuffer; THROW_LAST(); } END_CATCH m_nCheck32 = CalculateBlock(pBuffer, nLengthRead, m_nCheck32); nCount -= nLengthRead; if (nCount < nBufferLength) nBufferLength = nCount; }
void CMsregPacketRegistrationRequest::WriteDataToFile(CFile& cfFile, DWORD& dwChecksum) { CString csKey; CString csValue; TRY { // Write inherited data. CMsregPacket::WriteDataToFile(cfFile, dwChecksum); // Write the product name. WriteString(cfFile, m_csProductName, dwChecksum); // Write the field count. WriteDword(cfFile, FieldCount(), dwChecksum); // Write Fields. for (int i = 0; i < FieldCount(); i++) { GetField(i, csKey, csValue); WriteString(cfFile, csKey, dwChecksum); WriteString(cfFile, csValue, dwChecksum); } } CATCH_ALL(e) { csKey.Empty(); csValue.Empty(); THROW_LAST(); } END_CATCH_ALL }
void CMsregPacketCatalogOrderLineItem::ReadDataFromFile(CFile& cfFile, DWORD& dwChecksum) { CString csCollection; TRY { // Read the category name. m_csCategory = CMsregPacket::ReadString(cfFile, dwChecksum); // Read the quantity. m_dwQuantity = CMsregPacket::ReadDword(cfFile, dwChecksum); // Write the cost. m_dwCost = CMsregPacket::ReadDword(cfFile, dwChecksum); // Read the collection count. DWORD dwCollections = CMsregPacket::ReadDword(cfFile, dwChecksum); // Read Collections. DeleteAllCollections(); for (DWORD i = 0; i < dwCollections; i++) { csCollection = CMsregPacket::ReadString(cfFile, dwChecksum); AddCollection(csCollection); } } CATCH_ALL(e) { csCollection.Empty(); THROW_LAST(); } END_CATCH_ALL }
CString CMsregPacket::ReadString(CFile& cfFile, DWORD& dwChecksum) { CString csResult; TRY { DWORD dwLength = ReadStringLength(cfFile, dwChecksum); if (dwLength == 0) { csResult.Empty(); } else { ReadData(cfFile, csResult.GetBuffer((int)dwLength), (UINT)dwLength, dwChecksum); csResult.ReleaseBuffer(); } } CATCH_ALL(e) { csResult.Empty(); THROW_LAST(); } END_CATCH_ALL return csResult; }
void CMsregPacketRegistrationRequest::ReadDataFromFile(CFile& cfFile, DWORD& dwChecksum) { CString csKey; CString csValue; TRY { // Read inherited data. CMsregPacket::ReadDataFromFile(cfFile, dwChecksum); // Read the product name. m_csProductName = ReadString(cfFile, dwChecksum); // Read the field count. DWORD dwFields = ReadDword(cfFile, dwChecksum); // Read Fields. DeleteAllFields(); for (DWORD i = 0; i < dwFields; i++) { csKey = ReadString(cfFile, dwChecksum); csValue = ReadString(cfFile, dwChecksum); AddField(csKey, csValue); } } CATCH_ALL(e) { csKey.Empty(); csValue.Empty(); THROW_LAST(); } END_CATCH_ALL }
LPUNKNOWN CStringCollect::GetNewEnum() { #pragma warning (suppress: 6211) CEnumVariant* pEnum = new CEnumVariant; int nCount = (int)m_strArray.GetSize(); #pragma warning (suppress: 6211) VARIANT* pContents = new VARIANT[nCount]; int i; TRY { for (i = 0; i < nCount; ++i) { VariantInit(&pContents[i]); pContents[i].bstrVal = m_strArray.ElementAt(i).AllocSysString(); pContents[i].vt = VT_BSTR; } } CATCH_ALL(e) { while (--i >= 0) VariantClear(&pContents[i]); delete [] pContents; THROW_LAST(); } END_CATCH_ALL pEnum->SetContents(pContents, nCount); return pEnum->GetInterface(&IID_IUnknown); }
void CChooseDirectoryDialog::OnLBSelChangedNotify(UINT nIDBox, UINT iCurSel, UINT nCode) { /* // The directory selection has changed, copy the directory to our edit control. */ CString csDirectory; TRY { if (m_fFirstChangeNotification) { m_fFirstChangeNotification = FALSE; csDirectory = m_csDirectory; } else { GetDlgItemText(IDC_CHOOSE_DIRECTORY_BUFFER, csDirectory.GetBuffer(256), 256); csDirectory.ReleaseBuffer(); } SetDlgItemText(IDC_CHOOSE_DIRECTORY_NAME, csDirectory); } CATCH_ALL(e) { csDirectory.Empty(); THROW_LAST(); } END_CATCH_ALL }
int CChooseDirectoryDialog::DirectoryMessageBox(CWnd *pcwParent, const CString &csDirectory, int nFormatID, int nTitleID, UINT nType, WORD wFlags /* = 0 */, int nDefaultResult /* = IDOK */) { int nResult = nDefaultResult; if ((wFlags & OPTION_quiet) == 0) { CString csTitle; CString csFormat; CString csMessage; TRY { LoadConfigurationString(nTitleID, csTitle); LoadConfigurationString(nFormatID, csFormat); wsprintf(csMessage.GetBuffer(1024), csFormat, (LPCSTR)csDirectory); csMessage.ReleaseBuffer(); } CATCH_ALL(e) { csTitle.Empty(); csFormat.Empty(); csMessage.Empty(); THROW_LAST(); } END_CATCH_ALL nResult = pcwParent->MessageBox(csMessage, csTitle, nType); }
void CUIDesignerView::OnEditCopy() { ASSERT(m_cfUI != NULL); TiXmlDocument xmlDoc; TiXmlDeclaration Declaration("1.0","utf-8","yes"); xmlDoc.InsertEndChild(Declaration); TiXmlElement* pCopyElm = new TiXmlElement("UICopy"); CopyUI(pCopyElm); xmlDoc.InsertEndChild(*pCopyElm); TiXmlPrinter printer; xmlDoc.Accept(&printer); delete pCopyElm; CSharedFile file(GMEM_MOVEABLE, printer.Size() + 1); file.Write(printer.CStr(), printer.Size()); file.Write("\0", 1); COleDataSource* pDataSource = NULL; TRY { pDataSource = new COleDataSource; pDataSource->CacheGlobalData(m_cfUI, file.Detach()); pDataSource->SetClipboard(); } CATCH_ALL(e) { delete pDataSource; THROW_LAST(); } END_CATCH_ALL }
DROPEFFECT COleServerItem::DoDragDrop(LPCRECT lpItemRect, CPoint ptOffset, BOOL bIncludeLink, DWORD dwEffects, LPCRECT lpRectStartDrag) { ASSERT(AfxIsValidAddress(lpItemRect, sizeof(RECT))); ASSERT_VALID(this); ASSERT_VALID(this); DROPEFFECT dropEffect = DROPEFFECT_NONE; COleDataSource *pDataSource = NULL; TRY { // get clipboard data for this item CSize sizeItem( lpItemRect->right - lpItemRect->left, lpItemRect->bottom - lpItemRect->top); pDataSource = OnGetClipboardData(bIncludeLink, &ptOffset, &sizeItem); // add DROPEFFECT_LINK if link source is available LPDATAOBJECT lpDataObject = (LPDATAOBJECT) pDataSource->GetInterface(&IID_IDataObject); ASSERT(lpDataObject != NULL); FORMATETC formatEtc; formatEtc.cfFormat = (CLIPFORMAT)_oleData.cfLinkSource; formatEtc.ptd = NULL; formatEtc.dwAspect = DVASPECT_CONTENT; formatEtc.lindex = -1; formatEtc.tymed = (TYMED)-1; if (lpDataObject->QueryGetData(&formatEtc) == S_OK) dwEffects |= DROPEFFECT_LINK; // calculate default sensitivity rectangle CRect rectDrag; if (lpRectStartDrag == NULL) { rectDrag.SetRect(lpItemRect->left, lpItemRect->top, lpItemRect->left, lpItemRect->top); lpRectStartDrag = &rectDrag; } // do drag drop operation dropEffect = pDataSource->DoDragDrop(dwEffects, lpRectStartDrag); pDataSource->InternalRelease(); } CATCH_ALL(e) { if (pDataSource != NULL) pDataSource->InternalRelease(); THROW_LAST(); } END_CATCH_ALL return dropEffect; }
void CMsregPacketCatalogOrderRequest::ReadDataFromFile(CFile& cfFile, DWORD& dwChecksum) { CString csKey; CString csValue; TRY { // Read inherited data. CMsregPacket::ReadDataFromFile(cfFile, dwChecksum); // Read the product name. m_csProductName = ReadString(cfFile, dwChecksum); // Read the field count. DWORD dwFields = ReadDword(cfFile, dwChecksum); // Read Fields. DeleteAllFields(); for (DWORD i = 0; i < dwFields; i++) { csKey = ReadString(cfFile, dwChecksum); csValue = ReadString(cfFile, dwChecksum); AddField(csKey, csValue); } // Read the tax. m_dwTax = ReadDword(cfFile, dwChecksum); // Read the shipping. m_dwShipping = ReadDword(cfFile, dwChecksum); // Read the total. m_dwTotal = ReadDword(cfFile, dwChecksum); // Read the offer code. m_csOfferCode = ReadString(cfFile, dwChecksum); // Read the request code. m_csRequestCode = ReadString(cfFile, dwChecksum); // Read the line items. m_LineItems.ReadDataFromFile(cfFile, dwChecksum); } CATCH_ALL(e) { csKey.Empty(); csValue.Empty(); THROW_LAST(); } END_CATCH_ALL }
void COleServerItem::GetEmbedSourceData(LPSTGMEDIUM lpStgMedium) { ASSERT_VALID(this); ASSERT(AfxIsValidAddress(lpStgMedium, sizeof(STGMEDIUM))); LPLOCKBYTES lpLockBytes; SCODE sc = ::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes); if (sc != S_OK) AfxThrowOleException(sc); ASSERT(lpLockBytes != NULL); LPSTORAGE lpStorage; sc = ::StgCreateDocfileOnILockBytes(lpLockBytes, STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &lpStorage); if (sc != S_OK) { VERIFY(lpLockBytes->Release() == 0); AfxThrowOleException(sc); } ASSERT(lpStorage != NULL); // setup for save copy as COleServerDoc* pDoc = GetDocument(); pDoc->m_bSameAsLoad = FALSE; pDoc->m_bRemember = FALSE; TRY { OnSaveEmbedding(lpStorage); pDoc->CommitItems(FALSE); } CATCH_ALL(e) { // release storage and lock bytes VERIFY(lpStorage->Release() == 0); VERIFY(lpLockBytes->Release() == 0); pDoc->m_bSameAsLoad = TRUE; pDoc->m_bRemember = TRUE; THROW_LAST(); } END_CATCH_ALL pDoc->m_bSameAsLoad = TRUE; pDoc->m_bRemember = TRUE; lpLockBytes->Release(); // add it to the data source lpStgMedium->tymed = TYMED_ISTORAGE; lpStgMedium->pstg = lpStorage; lpStgMedium->pUnkForRelease = NULL; }
void CmdwEditorDoc::Serialize(CArchive& ar) { POSITION pos = this->GetFirstViewPosition(); CView* cv = NULL; CEditView* pEv = NULL; do { cv = this->GetNextView(pos); if( cv != NULL && cv->IsKindOf(RUNTIME_CLASS(CEditView))) { pEv = (CEditView*)cv; break; } } while(cv != NULL); if(pEv == NULL) return; //CString htmlpath; CFile *pCF = ar.GetFile(); //if(pCF != NULL) // htmlpath = pCF->GetFilePath() + _T(".html"); if (ar.IsStoring()) { // TODO: add storing code here /** unicode data 修改後儲存時轉換回 utf-8 再由sundown 轉換成 html,通知 HtmlView 顯示 */ LPCTSTR lpszText = pEv->LockBuffer(); ASSERT(lpszText != NULL); UINT nLen = pEv->GetBufferLength(); TRY { //ar.Write(lpszText, nLen*sizeof(TCHAR)); getEditText(lpszText, nLen); pCF->SeekToBegin(); pCF->Write(mib_utf8->data, mib_utf8->size); m_bHtmlExisted = convMd2Html((LPCTSTR)m_htmlPath, m_cssPath); this->UpdateAllViews(NULL, (LPARAM)(LPCTSTR)m_htmlPath, NULL); } CATCH_ALL(e) { pEv->UnlockBuffer(); THROW_LAST(); } END_CATCH_ALL pEv->UnlockBuffer(); }
void CMsregPacketCatalogOrderRequest::WriteDataToFile(CFile& cfFile, DWORD& dwChecksum) { CString csKey; CString csValue; TRY { // Write inherited data. CMsregPacket::WriteDataToFile(cfFile, dwChecksum); // Write the product name. WriteString(cfFile, m_csProductName, dwChecksum); // Write the field count. WriteDword(cfFile, FieldCount(), dwChecksum); // Write Fields. for (int i = 0; i < FieldCount(); i++) { GetField(i, csKey, csValue); WriteString(cfFile, csKey, dwChecksum); WriteString(cfFile, csValue, dwChecksum); } // Write the tax. WriteDword(cfFile, m_dwTax, dwChecksum); // Write the shipping. WriteDword(cfFile, m_dwShipping, dwChecksum); // Write the total. WriteDword(cfFile, m_dwTotal, dwChecksum); // Write the offer code. WriteString(cfFile, m_csOfferCode, dwChecksum); // Write the request code. WriteString(cfFile, m_csRequestCode, dwChecksum); // Write the line items. m_LineItems.WriteDataToFile(cfFile, dwChecksum); } CATCH_ALL(e) { csKey.Empty(); csValue.Empty(); THROW_LAST(); } END_CATCH_ALL }
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 CShareNotLoadedDialog::OnOK() { // The user wants PrintMaster to modify AUTOEXEC.BAT (ugh!) // Find AUTOEXEC.BAT and modify it. CAutoexecBatFile AutoexecBat; CString csLine; TRY { if (AutoexecBat.Locate()) { // We'll be adding the SHARE line to the start of AUTOEXEC.BAT. // Use the Windows OpenFile() function to search for SHARE.EXE. OFSTRUCT of; #ifdef WIN32 if (OpenFile("SHARE.EXE", &of, OF_EXIST|OF_READ|OF_SHARE_DENY_NONE) != HFILE_ERROR) #else if (OpenFile("SHARE.EXE", &of, OF_EXIST|OF_SEARCH|OF_READ|OF_SHARE_DENY_NONE) != HFILE_ERROR) #endif { TRACE("Found SHARE.EXE at '%s'\n", of.szPathName); // Create a new AUTOEXEC.BAT TRY { // JRO csLine = "REM *** The following SHARE line was added by PrintMaster Gold ***\n"; csLine = GET_PMWAPP()->GetResourceStringPointer (IDS_REM_AUTOEXEC); AutoexecBat.WriteLine(csLine); csLine = of.szPathName; csLine += '\n'; AutoexecBat.WriteLine(csLine); csLine = "\n"; AutoexecBat.WriteLine(csLine); AutoexecBat.CopyRestOfLines(); AutoexecBat.Done(TRUE, &m_csBackupName); m_fAutoexecBatModified = TRUE; } CATCH_ALL(e) { // JRO m_csReason = "Your hard disk or root directory may be full or the AUTOEXEC.BAT file may be write protected."; m_csReason = GET_PMWAPP()->GetResourceStringPointer (IDS_ROOT_FULL); THROW_LAST(); } END_CATCH_ALL } else {
void COleDocument::SaveToStorage(CObject* pObject) { ASSERT(m_lpRootStg != NULL); // create Contents stream COleStreamFile file; CFileException fe; if (!file.CreateStream(m_lpRootStg, _T("Contents"), CFile::modeReadWrite|CFile::shareExclusive|CFile::modeCreate, &fe)) { if (fe.m_cause == CFileException::fileNotFound) AfxThrowArchiveException(CArchiveException::badSchema); else AfxThrowFileException(fe.m_cause, fe.m_lOsError); } // save to Contents stream CArchive saveArchive(&file, CArchive::store | CArchive::bNoFlushOnDelete); saveArchive.m_pDocument = this; saveArchive.m_bForceFlat = FALSE; TRY { // save the contents if (pObject != NULL) pObject->Serialize(saveArchive); else Serialize(saveArchive); saveArchive.Close(); file.Close(); // commit the root storage SCODE sc = m_lpRootStg->Commit(STGC_ONLYIFCURRENT); if (sc != S_OK) AfxThrowOleException(sc); } CATCH_ALL(e) { file.Abort(); // will not throw an exception CommitItems(FALSE); // abort save in progress NO_CPP_EXCEPTION(saveArchive.Abort()); THROW_LAST(); } END_CATCH_ALL }
void CPrintSize::DoDataExchange(CDataExchange* pDX) { /* // Only used for shoving the initial data values into the // dialog. Input values are recorded as the fields are // validated when the user moves from field to field. */ if (!pDX->m_bSaveAndValidate) { CString csScale; CString csInchesTall; CString csInchesWide; TRY { CPmwDialog::DoDataExchange(pDX); limit_control(IDC_SHEETS_TALL, PRINT_SIZE_SHEETS_LIMIT); limit_control(IDC_SHEETS_WIDE, PRINT_SIZE_SHEETS_LIMIT); limit_control(IDC_INCHES_TALL, PRINT_SIZE_INCHES_LIMIT); limit_control(IDC_INCHES_WIDE, PRINT_SIZE_INCHES_LIMIT); limit_control(IDC_PRINT_SCALE, PRINT_SIZE_PERCENT_LIMIT); FormatDouble(m_scale, PRINT_SIZE_PERCENT_PRECISION, csScale); FormatDouble(m_inches_tall, PRINT_SIZE_INCHES_PRECISION, csInchesTall); FormatDouble(m_inches_wide, PRINT_SIZE_INCHES_PRECISION, csInchesWide); //{{AFX_DATA_MAP(CPrintSize) DDX_Control(pDX, IDC_SIZE_PREVIEW, m_preview); DDX_Text(pDX, IDC_SHEETS_TALL, m_sheets_tall); DDX_Text(pDX, IDC_SHEETS_WIDE, m_sheets_wide); DDX_Text(pDX, IDC_PRINT_SCALE, csScale); DDX_Text(pDX, IDC_INCHES_TALL, csInchesTall); DDX_Text(pDX, IDC_INCHES_WIDE, csInchesWide); //}}AFX_DATA_MAP } CATCH (CException, e) { csScale.Empty(); csInchesTall.Empty(); csInchesWide.Empty(); THROW_LAST(); }
CATCH(CSqlCsrException, e){ csqlSeeWhatHappened(e); // try rolling back cursor.. TRY{ con1.rollback(); }CATCH(CSqlCsrException, e){ // rollback failed... ::AfxMessageBox("Rollback failed...", MB_OK); // could try to perform further recovery... // we just throw it on to the MFC.. THROW_LAST(); }END_CATCH
void COleClientItem::CopyToClipboard(BOOL bIncludeLink) { ASSERT_VALID(this); ASSERT(m_lpObject != NULL); // get clipboard data for this item COleDataSource* pDataSource = OnGetClipboardData(bIncludeLink, NULL, NULL); TRY { // put it on the clipboard pDataSource->SetClipboard(); } CATCH_ALL(e) { delete pDataSource; THROW_LAST(); } END_CATCH_ALL }
bool CChordEaseDoc::UpdateSongText() { CString path; if (!theApp.GetTempFileName(path, TEMP_SONG_PREFIX)) return(FALSE); TRY { if (gEngine.WriteSong(path)) { // write song to temp file CFile file(path, CFile::modeRead); ReadSongText(file, m_SongText); } } CATCH_ALL(e) { DeleteFile(path); // delete temp file THROW_LAST(); // rethrow exception } END_CATCH_ALL; DeleteFile(path); // delete temp file return(TRUE); }
// CFeldInf --------------------------------------------------------- CFeldInf :: CFeldInf (const char *pName, const char *pType, long lLen) { // prüfe Parameter ASSERT (pName != NULL && AfxIsValidString (pName)); ASSERT (pType != NULL && AfxIsValidString (pType)); ASSERT (lLen >= 0); TRY { m_lLen = lLen; m_strName = pName; m_strType = pType; } CATCH (CMemoryException, me) { THROW_LAST (); } END_CATCH }
BOOL CImage::SaveBMP(LPCTSTR lpszFileName) { ///* CFile file; CFileException fe; BITMAPFILEHEADER bmfHdr; LPBITMAPINFOHEADER lpBI; DWORD dwDIBSize; if (!file.Open(lpszFileName, CFile::modeCreate | CFile::modeWrite | CFile::shareDenyWrite, &fe)) return FALSE; if (m_hImage == NULL) return FALSE; lpBI = (LPBITMAPINFOHEADER)::GlobalLock((HGLOBAL)m_hImage); if (lpBI == NULL) return FALSE; bmfHdr.bfType = DIB_HEADER_MARKER; // "BM" dwDIBSize = *(LPDWORD)lpBI + ::PaletteSize((LPSTR)lpBI); if((lpBI->biCompression==BI_RLE8) || (lpBI->biCompression==BI_RLE4)) dwDIBSize += lpBI->biSizeImage; else { DWORD dwBmBitsSize; // Size of Bitmap Bits only dwBmBitsSize = WIDTHBYTES((lpBI->biWidth)*((DWORD)lpBI->biBitCount)) * lpBI->biHeight; dwDIBSize += dwBmBitsSize; lpBI->biSizeImage = dwBmBitsSize; } bmfHdr.bfSize = dwDIBSize + sizeof(BITMAPFILEHEADER); bmfHdr.bfReserved1 = 0; bmfHdr.bfReserved2 = 0; bmfHdr.bfOffBits=(DWORD)sizeof(BITMAPFILEHEADER)+lpBI->biSize + PaletteSize((LPSTR)lpBI); TRY { file.Write((LPSTR)&bmfHdr, sizeof(BITMAPFILEHEADER)); //file.WriteHuge(lpBI, dwDIBSize); file.Write(lpBI, dwDIBSize); } CATCH (CFileException, e) { ::GlobalUnlock((HGLOBAL) m_hImage); THROW_LAST(); }
void CEditView::WriteToArchive(CArchive& ar) // Write just the text to an archive, no length prefix. { ASSERT_VALID(this); LPCTSTR lpszText = LockBuffer(); ASSERT(lpszText != NULL); UINT nLen = GetBufferLength(); TRY { ar.Write(lpszText, nLen*sizeof(TCHAR)); } CATCH_ALL(e) { UnlockBuffer(); THROW_LAST(); } END_CATCH_ALL UnlockBuffer(); ASSERT_VALID(this); }
COleDataSource* COleClientItem::OnGetClipboardData( BOOL bIncludeLink, LPPOINT lpOffset, LPSIZE lpSize) { ASSERT_VALID(this); COleDataSource* pDataSource = new COleDataSource; TRY { GetClipboardData(pDataSource, bIncludeLink, lpOffset, lpSize); } CATCH_ALL(e) { delete pDataSource; THROW_LAST(); } END_CATCH_ALL ASSERT_VALID(pDataSource); return pDataSource; }