//***************************************************************************************
BOOL CBCGPXMLSettings::Write (LPCTSTR pszKey, CWordArray& wcArray)
{
	if (m_bReadOnly)
	{
		ASSERT (FALSE);
		return FALSE;
	}

	BOOL bRes = FALSE;
	try
	{
		CMemFile file;

		{
			CArchive ar (&file, CArchive::store);

			ar << (int)wcArray.GetSize ();
			for (int i = 0; i < wcArray.GetSize (); i ++)
			{
				ar << wcArray [i];
			}

			ar.Flush ();
		}

#if _MSC_VER >= 1300
		ULONGLONG dwDataSize = file.GetLength ();
#else
		DWORD dwDataSize = file.GetLength ();
#endif
		LPBYTE lpbData = file.Detach ();

		if (lpbData == NULL)
		{
			return FALSE;
		}

		bRes = Write (pszKey, lpbData, (UINT) dwDataSize);
		free (lpbData);
	}
	catch (CMemoryException* pEx)
	{
		pEx->Delete ();
		TRACE(_T("Memory exception in CBCGPXMLSettings::Write ()!\n"));
		return FALSE;
	}

	return bRes;
}
Exemplo n.º 2
0
BOOL CRegistry::Write(LPCTSTR lpszKey, CWnd *pWnd)
{
	ASSERT(lpszKey);
	ASSERT(pWnd);

	WINDOWPLACEMENT wp;
	wp.length = sizeof(WINDOWPLACEMENT);
	pWnd->GetWindowPlacement(&wp);

	CMemFile file;
	CArchive ar(&file, CArchive::store);

	ar << wp.flags
		 << wp.showCmd
		 << wp.ptMinPosition
		 << wp.ptMaxPosition
		 << wp.rcNormalPosition;
	ar.Close();

	DWORD dwSize = file.GetLength();
	BYTE* pByte = file.Detach();

	LONG lResult = RegSetValueEx(m_hKey, lpszKey, NULL, REG_BINARY, pByte, dwSize);

	if (pByte)
		free(pByte);

	if(lResult == ERROR_SUCCESS)
		return TRUE;
	
	return FALSE;
}
Exemplo n.º 3
0
/////////////////////////////////////////////////////////////////////////////
// serialization
void CGXGridCellData::SerializeEx(CArchive& ar, CString& strProperty )
{
	ASSERT_VALID(this);
	DWORD dwDataLen;
	if (ar.IsStoring())		// Write
	{
		CMemFile  memFile;
		CArchive  arMem(&memFile, CArchive::store );
		Serialize ( arMem );
		arMem.Flush();

		dwDataLen = memFile.GetLength();
		if ( dwDataLen > 0 )
		{
			BYTE *pTemp = new BYTE [dwDataLen+1];
			memFile.Seek(0, CFile::begin);
			memFile.Read(pTemp, dwDataLen );
		
			ar.Write(&dwDataLen, sizeof(DWORD));
			ar.Write(pTemp, dwDataLen);

			// Property Save CString
			strProperty = BinaryToStringEx ( pTemp, dwDataLen );

			if ( pTemp )
				delete []pTemp;
		}
	}
	else					// Read
	{
		ar >> dwDataLen;
		if ( dwDataLen > 0 )
		{
			BYTE *pTemp = new BYTE[dwDataLen+1];
			ar.Read(pTemp, dwDataLen );
			
			CMemFile memFile;
			memFile.Attach ( (BYTE*)pTemp, dwDataLen );

			CArchive arMem(&memFile, CArchive::load );
			Serialize ( arMem );

			// Property Save CString
			DWORD dwTotLen = 	dwDataLen + sizeof(DWORD);
			BYTE *pvData = new BYTE[dwTotLen];
			*(DWORD*)pvData = dwTotLen;
			memcpy ( pvData + sizeof(DWORD), pTemp, dwDataLen );
			
			if ( pTemp )
				delete[] pTemp;

			strProperty = BinaryToStringEx ( pvData, dwTotLen );
			if ( pvData )
				delete[] pvData;
		}
	}
}
Exemplo n.º 4
0
	CBeginGame::CBeginGame(CPeerData *pDoc) : CMessage(MSGID_BEGINGAME), m_nSize(0), m_pData(NULL)
	{
		ASSERT(pDoc);

		// Dokument serialisieren
		CMemFile memFile;
		CArchive ar(&memFile, CArchive::store);
		pDoc->SerializeBeginGameData(ar);
		ar.Flush();
		m_nSize = memFile.GetLength();
		m_pData = memFile.Detach();
	}
Exemplo n.º 5
0
	CEndOfRound::CEndOfRound(CPeerData *pDoc) : CMessage(MSGID_ENDOFROUND), m_nSize(0), m_pDeletableData(NULL),
		m_pElseData(NULL)
	{
		ASSERT(pDoc);

		// Dokument serialisieren
		CMemFile memFile;
		CArchive ar(&memFile, CArchive::store);
		pDoc->SerializeEndOfRoundData(ar, RACE_NONE);
		ar.Flush();
		m_nSize = memFile.GetLength();
		m_pElseData = memFile.Detach();
	}
//************************************************************************************************
BOOL CBCGPMouseManager::SaveState (LPCTSTR lpszProfileName)
{
	CString strProfileName = ::BCGPGetRegPath (strMouseProfile, lpszProfileName);

	BOOL bResult = FALSE;

	try
	{
		CMemFile file;

		{
			CArchive ar (&file, CArchive::store);

			Serialize (ar);
			ar.Flush ();
		}

		UINT uiDataSize = (UINT) file.GetLength ();
		LPBYTE lpbData = file.Detach ();

		if (lpbData != NULL)
		{
			CBCGPRegistrySP regSP;
			CBCGPRegistry& reg = regSP.Create (FALSE, FALSE);

			if (reg.CreateKey (strProfileName))
			{
				bResult = reg.Write (strRegEntryName, lpbData, uiDataSize);
			}

			free (lpbData);
		}
	}
	catch (CMemoryException* pEx)
	{
		pEx->Delete ();
		TRACE(_T("Memory exception in CBCGPMouseManager::SaveState ()!\n"));
	}
	catch (CArchiveException* pEx)
	{
		pEx->Delete ();
		TRACE(_T("CArchiveException exception in CBCGPMouseManager::SaveState ()!\n"));
	}

	return bResult;
}
DWORD SupFileSubtitleProvider::ThreadProc()
{
    CFile f;
    if (!f.Open(m_fname, CFile::modeRead|CFile::typeBinary|CFile::shareDenyNone)) {
        return 1;
    }

    f.SeekToBegin();

    CMemFile sub;
    sub.SetLength(f.GetLength());
    sub.SeekToBegin();

    int len;
    BYTE buff[65536];
    while ((len = f.Read(buff, sizeof(buff))) > 0) {
        sub.Write(buff, len);
    }
    sub.SeekToBegin();

    WORD sync              = 0;
    USHORT size            = 0;
    REFERENCE_TIME rtStart = 0;

    CAutoLock cAutoLock(&m_csCritSec);
    while (sub.GetPosition() < (sub.GetLength() - 10)) {
        sync = (WORD)ReadByte(&sub, 2);
        if (sync == 'PG') {
            rtStart = UINT64(ReadByte(&sub, 4) * (1000 / 9));
            sub.Seek(4 + 1, CFile::current); // rtStop + Segment type
            size = ReadByte(&sub, 2) + 3;    // Segment size
            sub.Seek(-3, CFile::current);
            sub.Read(buff, size);
            m_pSub->ParseSample(buff, size, rtStart, 0);
        } else {
            break;
        }
    }

    sub.Close();

    return 0;
}
Exemplo n.º 8
0
BOOL CRegistry::Write (LPCTSTR pszKey, CDWordArray& dwcArray)
{
	ASSERT (m_hKey != NULL);
	ASSERT (pszKey != NULL);

	if (m_bReadOnly)
	{
		ASSERT (FALSE);
		return FALSE;
	}

	BOOL bRes = FALSE;
	try
	{
		CMemFile file;

		{
			CArchive ar (&file, CArchive::store);
			dwcArray.Serialize(ar);
			ar.Flush ();
		}

		DWORD dwDataSize = (DWORD) file.GetLength ();
		LPBYTE lpbData = file.Detach ();

		if (lpbData == NULL)
		{
			return FALSE;
		}

		bRes = Write (pszKey, lpbData, (UINT) dwDataSize);
		free (lpbData);
	}
	catch (CMemoryException* pEx)
	{
		pEx->Delete ();
		TRACE(_T("Memory exception in CRegistry::Write ()!\n"));
		return FALSE;
	}

	return bRes;
}
Exemplo n.º 9
0
void CSortListCtrl::SaveColumnInfo()
{
	ASSERT( m_iNumColumns > 0 );

	CString strKey;
	strKey.Format( _T("%d"), GetDlgCtrlID() );

	CMemFile memFile;

	CArchive ar( &memFile, CArchive::store );
	m_ctlHeader.Serialize( ar );
	ar.Close();

	DWORD dwLen = memFile.GetLength();
	BYTE* buf = memFile.Detach();	

	VERIFY( AfxGetApp()->WriteProfileBinary( g_pszSection, strKey, buf, dwLen ) );

	free( buf );
}
Exemplo n.º 10
0
bool CPackets::WriteStripSnapshot(UINT JobID, UINT StripRows, CSnapshot& Snap)
{
	CMemFile	mf;
	FRAP_STRIP_SNAPSHOT_HDR	hdr;
	ZeroMemory(&hdr, sizeof(hdr));
	mf.Write(&hdr, sizeof(hdr));	// reserve space for header
	{
		CArchive	ar(&mf, CArchive::store);
		Snap.Serialize(ar);
	}
	DWORD	PktLen = static_cast<DWORD>(mf.GetLength());
	DWORD	SnapLen = PktLen - sizeof(FRAP_STRIP_SNAPSHOT_HDR);
	FRAP_STRIP_SNAPSHOT	*pp = (FRAP_STRIP_SNAPSHOT *)mf.Detach();
	InitHdr(*pp, PMID_STRIP_SNAPSHOT, PktLen);
	pp->JobID = JobID;
	pp->StripRows = StripRows;
	pp->SnapLen = SnapLen;
	bool	retc = Write(*pp, PktLen);
	delete pp;	// buffer detached from CMemFile
	return(retc);
}
Exemplo n.º 11
0
BOOL CBCGPRegistry::Write(LPCTSTR pszKey, const CRect& rect)
{
	if (m_bReadOnly)
	{
		ASSERT (FALSE);
		return FALSE;
	}

	BOOL bRes = FALSE;
	try
	{
		CMemFile file;

		{
			CArchive ar (&file, CArchive::store);

			ar << rect;
			ar.Flush ();
		}

		DWORD dwDataSize = (DWORD) file.GetLength ();
		LPBYTE lpbData = file.Detach ();

		if (lpbData == NULL)
		{
			return FALSE;
		}

		bRes = Write (pszKey, lpbData, (UINT) dwDataSize);
		free (lpbData);
	}
	catch (CMemoryException* pEx)
	{
		pEx->Delete ();
		TRACE(_T("Memory exception in CBCGPRegistry::Write ()!\n"));
		return FALSE;
	}

	return bRes;
}
Exemplo n.º 12
0
CString CGXGridCellData::GetMultiCaptionBlobDataChange ( )
{
	CString strProperty;

	ASSERT_VALID(this);

//	if ( !m_bSingleMode )
//		DeleteContents();

	CMemFile  memFile;
	CArchive arMem(&memFile, CArchive::store );
	Serialize ( arMem );
	arMem.Flush();

	DWORD dwDataLen = memFile.GetLength();
	if ( dwDataLen > 0 )
	{
		BYTE *pTemp = new BYTE [dwDataLen+1];
		memFile.Seek(0, CFile::begin);
		memFile.Read(pTemp, dwDataLen );

		DWORD dwTotLen = 	dwDataLen + sizeof(DWORD);
		BYTE *pvData = new BYTE[dwTotLen];
		*(DWORD*)pvData = dwTotLen;
		memcpy ( pvData + sizeof(DWORD), pTemp, dwDataLen );
		if ( pTemp )
			delete[] pTemp;

		// Property Save CString
		strProperty = BinaryToStringEx ( pvData, dwTotLen );
		if ( pvData )
			delete[] pvData;
	}	

	return strProperty;
}
Exemplo n.º 13
0
HRESULT CTCPropBagOnRegKey::_WriteVariant(CRegKey& key,
  const _bstr_t& strValueName, VARIANT* pVar)
{
  // Check for an array
  if (V_ISARRAY(pVar))
    return WriteSafeArray(key, strValueName, pVar);

  // Write the value to the registry based on the VARIANT type
  switch (V_VT(pVar))
  {
    // Empty variant is written as nothing
    case VT_EMPTY:
      key.DeleteValue(strValueName);
      key.RecurseDeleteKey(strValueName);
      break;

    // Integer types are written as a REG_DWORD value
    case VT_I1:
    case VT_I2:
    case VT_I4:
    case VT_UI1:
    case VT_UI2:
    case VT_ERROR:
    {
      // Coerce the value to a VT_UI4
      VariantChangeTypeEx(pVar, pVar, GetThreadLocale(), m_wChangeTypeFlags,
        VT_UI4);
      // Fall thru to next case
    }
    case VT_UI4:
    {
      // Write the REG_DWORD value to the registry
      key.RecurseDeleteKey(strValueName);
      key.WriteDWord(strValueName, V_UI4(pVar));
      break;
    }

    // BOOL's, float types and strings are written as a REG_SZ value
    case VT_R4:
    case VT_R8:
    case VT_CY:
    case VT_DATE:
    case VT_DECIMAL:
    case VT_BOOL:
    {
      // Coerce the value to a VT_BSTR
      VariantChangeTypeEx(pVar, pVar, GetThreadLocale(), m_wChangeTypeFlags,
        VT_BSTR);
      // Fall thru to next case
    }
    case VT_BSTR:
    {
      // Write the REG_SZ value to the registry
      key.RecurseDeleteKey(strValueName);
      key.WriteString(strValueName, V_BSTR(pVar));
      break;
    }

    // Objects written as REG_BINARY, if they don't support IPersistPropertyBag
    case VT_UNKNOWN:
    case VT_DISPATCH:
    {
      // Attempt first to save the object property using IPersistPropertyBag
      key.DeleteValue(strValueName);
      key.RecurseDeleteKey(strValueName);

      CComObjectStack<CTCPropBagOnRegKey> bag;
      bag.Init(key, _bstr_t(), this);
      HRESULT hr = bag.SaveObject(strValueName, V_UNKNOWN(pVar), FALSE, TRUE);
      if (FAILED(hr))
      {
        TRACE1("CTCPropBagOnRegKey::_WriteVariant: Saving object property \"%s\" as a binary value\n",
          strValueName);

        // Create a CArchive on a CMemFile
        CMemFile file;
        CArchive ar(&file, CArchive::store, 0);

        // Archive the variant to the CArchive and close it
        CComVariant v(pVar);
        ar << v;
        ar.Close();

        // Write the REG_BINARY value to the registry
        int cbData = file.GetLength();
        BYTE* pData = file.Detach();
        key.RecurseDeleteKey(strValueName);
        key.WriteBinary(strValueName, pData, cbData);
        file.Attach(pData, cbData);
      }
      break;
    }

    default:
      TRACE1("CTCPropBagOnRegKey::_WriteVariant(\"%ls\"): ", strValueName);
      TRACE2("Unsupported variant type 0x%02X (%d)\n", UINT(V_VT(pVar)),
        UINT(V_VT(pVar)));
      return E_FAIL;
  }

  // Indicate success
  return S_OK;
}
Exemplo n.º 14
0
void CGenPropertyPage::OnCopyItem() 
{

char * p = NULL;

try
  {
  CMemFile f;      // open memory file for writing
  CArchive ar(&f, CArchive::store);

  // in case we do more than one (one day) the header comes before the batch
  if (m_strObjectType == "alias")
    m_doc->Save_Header_XML (ar, "aliases", false);
  else
    m_doc->Save_Header_XML (ar, m_strObjectType + "s", false);   // timers, triggers etc.

  for (int nItem = -1;
        (nItem = m_ctlList->GetNextItem(nItem, LVNI_SELECTED)) != -1;)
    {

    // get the lower-case name of this item's object
    CString * pstrObjectName = (CString *) m_ctlList->GetItemData (nItem);
    ASSERT (pstrObjectName != NULL);

    CObject * pItem;

    // check object is still there (it might have gone while we looked at the list box)
    if (!m_ObjectMap->Lookup (*pstrObjectName, pItem))
      {
      CString strMsg;

      m_ctlList->DeleteItem (nItem);    // it's gone, so delete it from the list view
      m_ctlList->RedrawItems (0, m_ctlList->GetItemCount () - 1);    // redraw the list

      // in the case of one-shot timers, unnamed items might be removed from the list
      if (pstrObjectName->Left (1) == "*")
        strMsg = TFormat ("The %s you selected is no longer in the %s list",
                      (LPCTSTR) m_strObjectType,
                      (LPCTSTR) m_strObjectType);
      else
        strMsg = TFormat ("The %s named \"%s\" is no longer in the %s list",
                      (LPCTSTR) m_strObjectType,
                      (LPCTSTR) *pstrObjectName,
                      (LPCTSTR) m_strObjectType);

      ::UMessageBox (strMsg);

      delete pstrObjectName;                 // and get rid of its name string
      continue;
      }

    ASSERT_VALID (pItem);
    ASSERT( pItem->IsKindOf( RUNTIME_CLASS( CObject ) ) );

    // turn into XML

    if (m_strObjectType == "trigger")
      m_doc->Save_One_Trigger_XML (ar, (CTrigger *) pItem);
    else if (m_strObjectType == "alias")
      m_doc->Save_One_Alias_XML (ar, (CAlias *) pItem);
    else if (m_strObjectType == "timer")
      m_doc->Save_One_Timer_XML (ar, (CTimer *) pItem);
    else if (m_strObjectType == "variable")
      m_doc->Save_One_Variable_XML (ar, (CVariable *) pItem);

    }   // end of dealing with each selected item

  if (m_strObjectType == "alias")
    m_doc->Save_Footer_XML (ar, "aliases");
  else
    m_doc->Save_Footer_XML (ar, m_strObjectType + "s");   // timers, triggers etc.

  ar.Close();

  int nLength = f.GetLength ();
  p = (char *) f.Detach ();

  CString strXML (p, nLength);

  free (p);   // remove memory allocated in CMemFile
  p = NULL;

  putontoclipboard (strXML, m_doc->m_bUTF_8);

  }   // end of try block

catch (CException* e)
	{
  if (p)
    free (p);   // remove memory allocated in CMemFile
	e->ReportError();
	e->Delete();
	}

}   // end of CGenPropertyPage::OnCopyItem
Exemplo n.º 15
0
//*********************************************************************************
static void openSnapshotTestSectrion()
{
    CTBSection xCurrentUser;
    xCurrentUser.Open(&CTBSection::tbRootSection, "CurrentUser");

    CTBSection xSnapshotTest;
    xSnapshotTest.Open(&xCurrentUser, "SnapshotTest", TBOPEN_MODE_SNAPSHOT);
    
    CString strName;
    DWORD dwType = 0;
    int nTop = 0;

    BOOL more = xSnapshotTest.GetFirstItem(strName, dwType);
    while(more)
    {
        TEST_VERIFY((dwType == TBVTYPE_LONGBINARY) == (strName == "Blob1"));
        TEST_VERIFY((dwType == TBVTYPE_SECTION) == (strName == "Section1"));

        if(dwType != TBVTYPE_LONGBINARY && dwType != TBVTYPE_SECTION)
        {
            CTBValue value;
            CString prefix;
            long index = 0;
            sscanf(strName, "%s %d", prefix.GetBuffer(10), &index);

            if(prefix == "Name")
            {
                if(nTop < index) nTop = index;
                TEST_VERIFY(dwType == TBVTYPE_TEXT);
                xSnapshotTest.GetValue(strName, &value);
                TEST_VERIFY(strcmp(value.m_pValue->data.text, "Name") == 0);
            }
            else if(prefix == "Age")
            {
                if(nTop < index) nTop = index;
                TEST_VERIFY(dwType == TBVTYPE_INTEGER);
                xSnapshotTest.GetValue(strName, &value);
                TEST_VERIFY(value.m_pValue->data.int32 == index);
            }
        }
        more = xSnapshotTest.GetNextItem(strName, dwType);
    }

    TEST_VERIFY(nTop == 199);

    CTBSection xSection1;
    xSection1.Open(&xSnapshotTest, "Section1");
    xSection1.Close();

    //--------------------------------------------------------------
    CMemFile memFile;
    xSnapshotTest.GetLongBinary("Blob1", &memFile);
    memFile.SeekToBegin();

    for(int i = 0; i < 64; ++i)
    {
        BYTE buff[1024] = {0};
        BYTE buff2[1024] = {0};

        memset(buff2, i, sizeof(buff2));
        memFile.Read(buff, sizeof(buff));

        TEST_VERIFY(memcmp(buff, buff2, 1024) == 0);
    }
    //--------------------------------------------------------------
    TEST_VERIFY(memFile.GetPosition() == memFile.GetLength());

    xSnapshotTest.Close();
}
Exemplo n.º 16
0
//*********************************************************************************
BOOL CBCGPOutlookBar::SaveState (LPCTSTR lpszProfileName, int nIndex, UINT uiID)
{
	CBCGPBaseTabbedBar::SaveState (lpszProfileName, nIndex, uiID);

	for (POSITION pos = m_lstCustomPages.GetHeadPosition (); pos != NULL;)
	{
		CBCGPOutlookBarPane* pPage = (CBCGPOutlookBarPane*)m_lstCustomPages.GetNext (pos);
		ASSERT_VALID (pPage);
		int nID = pPage->GetDlgCtrlID ();
		pPage->SaveState (lpszProfileName, nID, nID);
	}

	CString strProfileName = ::BCGPGetRegPath (strOutlookBarProfile, lpszProfileName);

	if (nIndex == -1)
	{
		nIndex = GetDlgCtrlID ();
	}

	CString strSection;
	if (uiID == (UINT) -1)
	{
		strSection.Format (REG_SECTION_FMT, strProfileName, nIndex);
	}
	else
	{
		strSection.Format (REG_SECTION_FMT_EX, strProfileName, nIndex, uiID);
	}

	try
	{
		CMemFile file;

		{
			CArchive ar (&file, CArchive::store);

			ar << (int) m_lstCustomPages.GetCount ();
			for (POSITION pos = m_lstCustomPages.GetHeadPosition (); pos != NULL;)
			{
				CBCGPOutlookBarPane* pPage = (CBCGPOutlookBarPane*)m_lstCustomPages.GetNext (pos);
				ASSERT_VALID (pPage);

				ar << pPage->GetDlgCtrlID ();
				
				CString strName;
				if (pPage->IsTabbed ())
				{
					pPage->GetWindowText (strName);
				}
				else
				{
					pPage->GetParent ()->GetWindowText (strName);
				}

				ar << strName;
			}
			
			CBCGPOutlookWnd* pOutlookBar = (CBCGPOutlookWnd*) GetUnderlinedWindow ();
			if (pOutlookBar != NULL)
			{
				ar << pOutlookBar->GetVisiblePageButtons ();
			}
			else
			{
				ar << -1;
			}

			ar.Flush ();
		}

		UINT uiDataSize = (UINT) file.GetLength ();
		LPBYTE lpbData = file.Detach ();

		if (lpbData != NULL)
		{
			CBCGPRegistrySP regSP;
			CBCGPRegistry& reg = regSP.Create (FALSE, FALSE);

			if (reg.CreateKey (strSection))
			{
				reg.Write (strRegCustomPages, lpbData, uiDataSize);
			}

			free (lpbData);
		}
	}
	catch (CMemoryException* pEx)
	{
		pEx->Delete ();
		TRACE(_T("Memory exception in CBCGPOutlookBar::SaveState ()!\n"));
	}
	catch (CArchiveException* pEx)
	{
		pEx->Delete ();
		TRACE(_T("Archive exception in CBCGPOutlookBar::SaveState ()!\n"));
	}

	return TRUE;
}
Exemplo n.º 17
0
//****************************************************************************************
BOOL CBCGPGridSerializeManager::PrepareDataFromSelection ()
{
	ASSERT (m_pOwnerGrid != NULL);

	CleanUp ();

	if (m_pOwnerGrid != NULL)
	{
		m_nLastColumn = m_pOwnerGrid->GetColumnsInfo ().GetColumnCount (TRUE) - 1;
		m_nLastRow = m_pOwnerGrid->GetTotalRowCount () - 1;
	}

	if (m_ClipboardFormatType == CF_Rows)
	{
		if (!m_pOwnerGrid->NormalizeSelectionList ())
		{
			return FALSE;
		}
	}

	//---------------------
	// Calculate min offset
	//---------------------
	int i = 0;
	CBCGPGridItemID idOffset (-1, -1);
	for (i = 0; i < m_pOwnerGrid->GetSelectionCount (); i++)
	{
		CBCGPGridRange rangeIndex, rangeOrder;
		if (m_pOwnerGrid->GetSelection (i, rangeIndex) && 
			IndexToOrder (rangeIndex, rangeOrder))
		{
			const int nRow = (rangeOrder.m_nTop != -1) ? rangeOrder.m_nTop: 0;
			const int nCol = (rangeOrder.m_nLeft != -1) ? rangeOrder.m_nLeft: 0;
			
			if (idOffset.m_nRow == -1 || nRow <= idOffset.m_nRow)
			{
				idOffset.m_nRow = nRow;
			}
			
			if (idOffset.m_nColumn == -1 || nCol <= idOffset.m_nColumn)
			{
				idOffset.m_nColumn = nCol;
			}

			if (idOffset.m_nRow == -1 || 
				idOffset.m_nRow == 0 && idOffset.m_nRow == m_nLastRow)
			{
				m_bWholeColSelected = TRUE;
			}

			if (idOffset.m_nColumn == -1 || 
				idOffset.m_nColumn == 0 && idOffset.m_nColumn == m_nLastColumn)
			{
				m_bWholeRowSelected = TRUE;
			}
		}
	}
	
	if (idOffset.m_nRow == -1)
	{
		idOffset.m_nRow = 0;
	}
	if (idOffset.m_nColumn == -1)
	{
		idOffset.m_nColumn = 0;
	}

	ASSERT (idOffset.m_nRow >= 0);
	ASSERT (idOffset.m_nColumn >= 0);
	m_idRangesOffset = idOffset;

	//------------------------------
	// Prepare serialized selection:
	//------------------------------
	for (i = 0; i < m_pOwnerGrid->GetSelectionCount (); i++)
	{
		CBCGPGridRange rangeIndex, rangeOrder;
		if (m_pOwnerGrid->GetSelection (i, rangeIndex) &&
			IndexToOrder (rangeIndex, rangeOrder))
		{
			const int nRowOffset = (rangeOrder.m_nTop != -1) ? rangeOrder.m_nTop - m_idRangesOffset.m_nRow: 0;
			const int nColOffset = (rangeOrder.m_nLeft != -1) ? rangeOrder.m_nLeft - m_idRangesOffset.m_nColumn: 0;
		
			CBCGPGridRange rangeRelative (
				nColOffset, 
				nRowOffset, 
				nColOffset + (rangeOrder.m_nRight - rangeOrder.m_nLeft), 
				nRowOffset + (rangeOrder.m_nBottom - rangeOrder.m_nTop));

			try
			{
				CMemFile f;

				CArchive archive (&f, CArchive::store | CArchive::bNoFlushOnDelete);
				if (m_ClipboardFormatType == CF_Items)
				{
					WriteItemsToArchive (archive, rangeOrder);
				}
				else if (m_ClipboardFormatType == CF_Rows)
				{
					WriteRowsToArchive (archive, rangeOrder);
				}
				archive.Close ();

				if (f.GetLength () <= 0)
				{
					return FALSE;
				}
				
				UINT	cbSize = (UINT)f.GetLength ();
				BYTE*	pData = new BYTE[cbSize];
				
				if (NULL == pData)
				{
					delete [] pData;
					return FALSE;
				}
				
				f.SeekToBegin ();
				if (f.Read (pData, cbSize) != cbSize)
				{
					delete [] pData;
					return FALSE;
				}
				
				AddRange (rangeRelative, cbSize, pData);
			}
			catch (CFileException* pEx)
			{
				TRACE(_T("CBCGPGridSerializeManager::PrepareDataFromSelection. File exception\r\n"));
				pEx->Delete ();
				
				return FALSE;
			}
			catch (CException* e)
			{
				TRACE(_T("CBCGPGridSerializeManager::PrepareDataFromSelection. Exception\r\n"));
				e->Delete ();
				return FALSE;
			}
		}
	}

	return TRUE;
}
Exemplo n.º 18
0
BOOL CSampleGrabberCallback2::ImageConvert()
	{
	BYTE *pBuffer = m_CusBuffer.pBuffer0;
	long lwidth = m_CusBuffer.sizeBuf0.cx;
	long lheight = m_CusBuffer.sizeBuf0.cy;
	ULONG BufferLen = m_CusBuffer.ulBufLen0;
	BYTE *pImage = NULL;
	long lBitCount = 0;
	long lsize = 0;

	if(MEDIASUBTYPE_YUY2 == m_mtStillMediaType.subtype	
		|| MEDIASUBTYPE_I420 == m_mtStillMediaType.subtype
		|| MEDIASUBTYPE_RGB24 == m_mtStillMediaType.subtype 
		|| MEDIASUBTYPE_RGB32 == m_mtStillMediaType.subtype)
		{				
		if (MEDIASUBTYPE_YUY2 == m_mtStillMediaType.subtype)
			{
			lsize = lwidth * lheight * 3;
			pImage = new BYTE[lsize];
			if(NULL == pImage)
				{
				return FALSE;
				}
			CFormatConvertArithmetic::YUY2ToRGB24(pBuffer, pImage, lwidth, lheight);
			lBitCount = 24;					
			}
		else if (MEDIASUBTYPE_I420 == m_mtStillMediaType.subtype)
			{
			lsize = lwidth * lheight * 3;
			pImage = new BYTE[lsize];
			if(NULL == pImage)
				return FALSE;
			CFormatConvertArithmetic::I420ToRGB24(pBuffer, pImage, lwidth, lheight);
			lBitCount = 24;	
			}
		// MEDIASUBTYPE_RGB24 or MEDIASUBTYPE_RGB32
		else				
			{
			lsize	= BufferLen;
			pImage = new BYTE[lsize];
			memcpy(pImage, pBuffer, lsize);
			if(MEDIASUBTYPE_RGB24 == m_mtStillMediaType.subtype)
				lBitCount = 24;
			else
				lBitCount = 32;					
			}

		BITMAPFILEHEADER	hdr;
		hdr.bfType		= MAKEWORD('B', 'M');	// always is "BM"
		hdr.bfSize		= lsize + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
		hdr.bfReserved1 = 0;
		hdr.bfReserved2 = 0;
		hdr.bfOffBits	 = (DWORD) (sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER));

		BITMAPINFOHEADER bih; 
		ZeroMemory(&bih, sizeof(bih));
		bih.biSize = sizeof(BITMAPINFOHEADER); 
		bih.biWidth = lwidth; 
		bih.biHeight = lheight; 		
		bih.biBitCount = (unsigned short)lBitCount;
		bih.biPlanes = 1;
		bih.biCompression = BI_RGB;
		bih.biSizeImage = 0;		

		// 初始化Bitmap		
		g_lpBits = pImage;		
		g_fhdr = hdr;
		g_ihdr = bih;			

		}
	else if (MEDIASUBTYPE_MJPG == m_mtStillMediaType.subtype)
		{
		CPicConver PicConver;
		CMemFile bmpFile;
		CMemFile jpgFile;				
		long lBmpBufferLen = 0;

		jpgFile.Attach(pBuffer, BufferLen);
		PicConver.MBmpToMImage(jpgFile, bmpFile, _T("bmp"));
		jpgFile.Detach();				

		// JPG转换后的BMP图像文件的长度(此长度包含了BITMAPINFOHEADER以及图像数据)
		lBmpBufferLen = (long)bmpFile.GetLength();

		BYTE *pbyteBmp = NULL;				
		pbyteBmp = new BYTE[lBmpBufferLen];
		if (NULL == pbyteBmp)
			{
			return FALSE;
			}

		BYTE *pbyteBuffer = bmpFile.Detach();
		memcpy(pbyteBmp, pbyteBuffer, lBmpBufferLen);

		// MSDN中CMemFile自动分配的Buffer最后在析构函数中会被自动释放, 
		// 在实际测试中发现, CMemFile自动分配的Buffer, 但是如果调用了
		// Detach方法, 那么CMemFile不会自动释放原先分配的Buffer, 必需
		// 手动释放, 否则会出现内存泄露		
		SAFEDELETEARRAY(pbyteBuffer);


		// 获得BITMAPFILEHEADER			
		g_fhdr = *((BITMAPFILEHEADER *)pbyteBmp);


		// 获得BITMAPINFOHEADER			
		g_ihdr = *((BITMAPINFOHEADER *)(pbyteBmp+sizeof(BITMAPFILEHEADER)));


		// 获得除BITMAPFILEHEADER, BITMAPINFOHEADER之外的图像数据长度
		long lDestLen = lBmpBufferLen - sizeof(BITMAPFILEHEADER) - sizeof(BITMAPINFOHEADER);

		pImage = NULL;
		pImage = new BYTE[lDestLen];
		if (NULL == pImage)
			{			
			SAFEDELETEARRAY(pbyteBmp);
			return FALSE;
			}

		// 获得图像数据
		memcpy(pImage, pbyteBmp+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER), lDestLen);

		g_lpBits = pImage;

		// 释放临时转换Buffer
		SAFEDELETEARRAY(pbyteBmp);
		}	
	// RAW
	else
		{
		lsize = lwidth * lheight * 3;
		pImage = new BYTE[lsize];
		if (NULL == pImage)
			{
			return FALSE;
			}
		m_FmtConvAtc.RAW8ToRGB24(pBuffer, pImage, lwidth, lheight);
		lBitCount = 24;

		BITMAPFILEHEADER	hdr;
		hdr.bfType		= MAKEWORD('B', 'M');	// always is "BM"
		hdr.bfSize		= lsize + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
		hdr.bfReserved1 = 0;
		hdr.bfReserved2 = 0;
		hdr.bfOffBits	 = (DWORD) (sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER));

		BITMAPINFOHEADER bih; 
		ZeroMemory(&bih, sizeof(bih));
		bih.biSize = sizeof(BITMAPINFOHEADER); 
		bih.biWidth = lwidth; 
		bih.biHeight = lheight; 		
		bih.biBitCount = (unsigned short)lBitCount;
		bih.biPlanes = 1;
		bih.biCompression = BI_RGB;
		bih.biSizeImage = 0;		

		// 初始化Bitmap		
		g_lpBits = pImage;		
		g_fhdr = hdr;
		g_ihdr = bih;	
		}	
	}
Exemplo n.º 19
0
BSTR CMUSHclientDoc::ExportXML(short Type, LPCTSTR Name) 
{
	CString strResult;
  CString strName = Name;

  // trim spaces, force name to lower-case
  CheckObjectName (strName, false);

  char * p = NULL;

  try
    {
    CMemFile f;      // open memory file for writing
    CArchive ar(&f, CArchive::store);


    // see if trigger exists, if not return EMPTY

    switch (Type)
      {
      case 0:   // trigger
        {
        CTrigger * t;
        if (GetTriggerMap ().Lookup (strName, t))
          {
          Save_Header_XML (ar, "triggers", false);
          Save_One_Trigger_XML (ar, t);
          Save_Footer_XML (ar, "triggers");
          } // end of item existing
        }
        break;

      case 1:   // alias
        {
        CAlias * t;
        if (GetAliasMap ().Lookup (strName, t))
          {
          Save_Header_XML (ar, "aliases", false);
          Save_One_Alias_XML (ar, t);
          Save_Footer_XML (ar, "aliases");
          } // end of item existing
        }
        break;

      case 2:   // timer
        {
        CTimer * t;
        if (GetTimerMap ().Lookup (strName, t))
          {
          Save_Header_XML (ar, "timers", false);
          Save_One_Timer_XML (ar, t);
          Save_Footer_XML (ar, "timers");
          } // end of item existing
        }
        break;

      case 3:   // macro
        {
        for (int i = 0; i < NUMITEMS (strMacroDescriptions); i++)
          {
          if (strMacroDescriptions [i].CompareNoCase (strName) == 0)
            {
            Save_Header_XML (ar, "macros", false);
            Save_One_Macro_XML (ar, i);
            Save_Footer_XML (ar, "macros");
            } // end of item existing
          } // end of finding which one
        }
        break;

      case 4:   // variable
        {
        CVariable * t;
        if (GetVariableMap ().Lookup (strName, t))
          {
          Save_Header_XML (ar, "variables", false);
          Save_One_Variable_XML (ar, t);
          Save_Footer_XML (ar, "variables");
          } // end of item existing
        }
        break;

      case 5:   // keypad
        {
        for (int i = 0; i < NUMITEMS (strKeypadNames); i++)
          {
          if (strKeypadNames [i].CompareNoCase (strName) == 0)
            {
            Save_Header_XML (ar, "keypad", false);
            Save_One_Keypad_XML (ar, i);
            Save_Footer_XML (ar, "keypad");
            } // end of item existing
          } // end of finding which one

        }
        break;

      } // end of switch

    ar.Close();

    int nLength = f.GetLength ();
    p = (char *) f.Detach ();

    strResult = CString (p, nLength);

    free (p);   // remove memory allocated in CMemFile
    p = NULL;

    }   // end of try block

  catch (CException* e)
	  {
    if (p)
      free (p);   // remove memory allocated in CMemFile
	  e->Delete();
    strResult.Empty ();
	  }   // end of catch


	return strResult.AllocSysString();
}   // end of CMUSHclientDoc::ExportXML
Exemplo n.º 20
-1
// serializing structures must follow serializing a common data type,
// because structures are serialized using CArchive::Read function
// which doesn't throw CArchiveException on end-of-file
bool CRegistrySerialize::Save()
{
	if (!Check())
		return false;

	CMemFile mf;
	try
	{
	
		CArchive ar(&mf, CArchive::store);
		m_pObject->Serialize(ar);
		ar.Close();
	}
	catch(CException* e)
	{
		e->Delete();
		return false;
	}

	DWORD iSize = (DWORD)mf.GetLength();
	BYTE* pData = mf.Detach();
	bool ret = RegSetValueEx(m_Key, m_szValue, 0, REG_BINARY, pData, iSize) == ERROR_SUCCESS;
	free(pData);
	return ret;
}