BOOL CBCGPRegistry::Read(LPCTSTR pszKey, LPPOINT& lpPoint) { ASSERT(m_hKey); BOOL bSucess = FALSE; BYTE* pData = NULL; UINT uDataSize; Read (pszKey, &pData, &uDataSize); try { if (pData != NULL && m_Info.lMessage == ERROR_SUCCESS && m_Info.dwType == REG_BINARY) { CMemFile file (pData, uDataSize); CArchive ar (&file, CArchive::load); ar.m_bForceFlat = FALSE; ASSERT(ar.IsLoading()); CDWordArray dwcArray; ASSERT(dwcArray.IsSerializable()); dwcArray.Serialize(ar); ar.Close(); if (dwcArray.GetSize() == 2) { lpPoint->x = dwcArray.GetAt(0); lpPoint->y = dwcArray.GetAt(1); bSucess = TRUE; } } } catch (CMemoryException* pEx) { pEx->Delete (); TRACE(_T("Memory exception in CBCGPRegistry::Read ()!\n")); } catch (CArchiveException* pEx) { pEx->Delete (); TRACE(_T("CArchiveException exception in CBCGPRegistry::Read ()!\n")); } m_Info.dwType = REG_POINT; m_Info.dwSize = sizeof(POINT); if (pData != NULL) { delete [] pData; pData = NULL; } return bSucess; }
BOOL CBCGPRegistry::Write(LPCTSTR pszKey, LPPOINT& lpPoint) { if (m_bReadOnly) { ASSERT (FALSE); return FALSE; } ASSERT(m_hKey); BYTE* pData = NULL; DWORD dwLen = 0; { CMemFile file(32); CArchive ar(&file, CArchive::store); CDWordArray dwcArray; dwcArray.SetSize(2); dwcArray.SetAt(0, lpPoint->x); dwcArray.SetAt(1, lpPoint->y); ASSERT(dwcArray.IsSerializable()); dwcArray.Serialize(ar); ar.Close(); dwLen = (DWORD) file.GetLength(); pData = file.Detach(); } ASSERT(pData != NULL && dwLen > 0); LONG lReturn = RegSetValueEx(m_hKey, pszKey, 0, REG_BINARY, pData, dwLen); m_Info.lMessage = lReturn; m_Info.dwSize = dwLen; m_Info.dwType = REG_POINT; if (pData != NULL) { free(pData); pData = NULL; } if(lReturn == ERROR_SUCCESS) return TRUE; return FALSE; }
BOOL CRegistry::Read(LPCTSTR pszKey, LPPOINT& lpPoint) { ASSERT(m_hKey); const int iMaxChars = 20; CDWordArray dwcArray; DWORD dwType; DWORD dwData = iMaxChars; BYTE* byData = (BYTE*)::calloc(iMaxChars, sizeof(TCHAR)); ASSERT(byData); LONG lReturn = RegQueryValueEx(m_hKey, pszKey, NULL, &dwType, byData, &dwData); if(lReturn == ERROR_SUCCESS && dwType == REG_BINARY) { ASSERT(dwData < iMaxChars); CMemFile file(byData, dwData); CArchive ar(&file, CArchive::load); ar.m_bForceFlat = FALSE; ASSERT(ar.IsLoading()); ASSERT(dwcArray.IsSerializable()); dwcArray.RemoveAll(); dwcArray.SetSize(5); dwcArray.Serialize(ar); ar.Close(); file.Close(); lpPoint->x = dwcArray.GetAt(0); lpPoint->y = dwcArray.GetAt(1); } m_Info.lMessage = lReturn; m_Info.dwType = REG_POINT; m_Info.dwSize = sizeof(POINT); if(byData) { free(byData); byData = NULL; } if(lReturn == ERROR_SUCCESS) return TRUE; return FALSE; }
BOOL CRegistry::Write(LPCTSTR pszKey, LPPOINT& lpPoint) { if (m_bReadOnly) { ASSERT (FALSE); return FALSE; } ASSERT(m_hKey); const int iMaxChars = 20; CDWordArray dwcArray; BYTE* byData = (BYTE*)::calloc(iMaxChars, sizeof(TCHAR)); ASSERT(byData); dwcArray.SetSize(5); dwcArray.SetAt(0, lpPoint->x); dwcArray.SetAt(1, lpPoint->y); CMemFile file(byData, iMaxChars, 16); CArchive ar(&file, CArchive::store); ASSERT(dwcArray.IsSerializable()); dwcArray.Serialize(ar); ar.Close(); const DWORD dwLen = (DWORD) file.GetLength(); ASSERT(dwLen < iMaxChars); LONG lReturn = RegSetValueEx(m_hKey, pszKey, 0, REG_BINARY, file.Detach(), dwLen); m_Info.lMessage = lReturn; m_Info.dwSize = dwLen; m_Info.dwType = REG_POINT; if(byData) { free(byData); byData = NULL; } if(lReturn == ERROR_SUCCESS) return TRUE; return FALSE; }
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; }
//*************************************************************************************** BOOL CBCGPXMLSettings::Read(LPCTSTR pszKey, LPPOINT& lpPoint) { BOOL bSucess = FALSE; BYTE* pData = NULL; UINT uDataSize; if (!Read (pszKey, &pData, &uDataSize)) { ASSERT (pData == NULL); return FALSE; } ASSERT (pData != NULL); try { CMemFile file (pData, uDataSize); CArchive ar (&file, CArchive::load); CDWordArray dwcArray; dwcArray.SetSize(5); dwcArray.Serialize (ar); lpPoint->x = dwcArray.GetAt(0); lpPoint->y = dwcArray.GetAt(1); bSucess = TRUE; } catch (CMemoryException* pEx) { pEx->Delete (); TRACE(_T("Memory exception in CBCGPXMLSettings::Read ()!\n")); } catch (CArchiveException* pEx) { pEx->Delete (); TRACE(_T("CArchiveException exception in CBCGPXMLSettings::Read ()!\n")); } return TRUE; }
//*************************************************************************************** BOOL CBCGPXMLSettings::Write(LPCTSTR pszKey, LPPOINT& lpPoint) { if (m_bReadOnly) { ASSERT (FALSE); return FALSE; } const int iMaxChars = 20; CDWordArray dwcArray; BYTE* byData = (BYTE*)::calloc(iMaxChars, sizeof(TCHAR)); ASSERT(byData); dwcArray.SetSize(5); dwcArray.SetAt(0, lpPoint->x); dwcArray.SetAt(1, lpPoint->y); CMemFile file(byData, iMaxChars, 16); CArchive ar(&file, CArchive::store); ASSERT(dwcArray.IsSerializable()); dwcArray.Serialize(ar); ar.Close(); #if _MSC_VER >= 1300 ULONGLONG dwLen = file.GetLength (); #else const DWORD dwLen = file.GetLength (); #endif LPBYTE lpbData = file.Detach (); BOOL bRes = Write (pszKey, lpbData, (UINT) dwLen); if(byData) { free(byData); byData = NULL; } return bRes; }