Exemplo n.º 1
0
BOOL	CRegistry::WriteProfileString( LPCSTR lpszSection, LPCSTR lpszEntry, LPCSTR lpszValue )
{
#ifndef	INI_USE
	LONG	lResult;
	if( !lpszEntry ) {
		HKEY	hAppKey = GetRegistryKey();
		if( !hAppKey )
			return	FALSE;
		lResult = ::RegDeleteKey( hAppKey, lpszSection );
		::RegCloseKey( hAppKey );
	} else if( !lpszValue ) {
		HKEY	hSecKey = GetSectionKey( lpszSection );
		if( !hSecKey )
			return	FALSE;
		lResult = ::RegDeleteValue( hSecKey, (LPTSTR)lpszEntry );
		::RegCloseKey( hSecKey );
	} else {
		HKEY	hSecKey = GetSectionKey( lpszSection );
		if( !hSecKey )
			return	FALSE;
		lResult = ::RegSetValueEx(hSecKey, lpszEntry, NULL, REG_SZ,
			(LPBYTE)lpszValue, (lstrlen(lpszValue)+1)*sizeof(TCHAR));
		::RegCloseKey( hSecKey );
	}
	return	(lResult == ERROR_SUCCESS);
#else
	return	::WritePrivateProfileString( lpszSection, lpszEntry, lpszValue, m_szRegistryKey );
#endif
}
Exemplo n.º 2
0
	BOOL CULProfileReg::WriteProfileString(LPCTSTR pcszSection,
		LPCTSTR pcszEntry,LPCTSTR pcszValue)
	{
		if(m_hAppKey==NULL)
			return FALSE;
		LONG lResult; 
		if(pcszEntry == NULL)
			lResult = ::RegDeleteKey(m_hAppKey, pcszSection);
		else
			if(pcszValue == NULL)
			{
				HKEY hSecKey=GetSectionKey(pcszSection);
				if (hSecKey==NULL)
					return FALSE;
				lResult = ::RegDeleteValue(hSecKey,(LPTSTR)pcszEntry);
				RegCloseKey(hSecKey);
			}
			else
			{
				HKEY hSecKey = GetSectionKey(pcszSection);
				if (hSecKey == NULL)
					return FALSE;
				lResult = RegSetValueEx(hSecKey, pcszEntry, NULL, REG_SZ,
					(LPBYTE)pcszValue, ((DWORD)_tcslen(pcszValue)+1)*sizeof(TCHAR));
				RegCloseKey(hSecKey);
			}
		return (lResult == ERROR_SUCCESS);
	}
Exemplo n.º 3
0
	BOOL CULProfileReg::WriteProfileBinary(LPCTSTR pcszSection,
		LPCTSTR pcszEntry,void* pValue,DWORD dwSizeVal)
	{
		if(m_hAppKey==NULL)
			return FALSE;
		LONG lResult; 
		if(pcszEntry==NULL)
			lResult = ::RegDeleteKey(m_hAppKey, pcszSection);
		else
			if(pValue==NULL)
			{
				HKEY hSecKey=GetSectionKey(pcszSection);
				if (hSecKey==NULL)
					return FALSE;
				lResult = ::RegDeleteValue(hSecKey,(LPTSTR)pcszEntry);
				RegCloseKey(hSecKey);
			}
			else
			{
				HKEY hSecKey=GetSectionKey(pcszSection);
				if (hSecKey==NULL)
					return FALSE;
				lResult=RegSetValueEx(hSecKey, pcszEntry, NULL, REG_BINARY,
					(LPBYTE)pValue, dwSizeVal);
				RegCloseKey(hSecKey);
			}
		return (lResult==ERROR_SUCCESS);
	}
BOOL CXTPRegistryManager::WriteProfileString(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpszValue)
{
	ASSERT(lpszSection != NULL);
	if (!lpszSection)
		return 0;

	if (m_strINIFileName.IsEmpty())
	{
		if (lpszEntry == NULL) //delete whole section
		{
			CHKey hAppKey(GetAppRegistryKey(FALSE));
			if (hAppKey == NULL)
				return FALSE;

			m_lResult = ::RegDeleteKey(hAppKey, lpszSection);

			if (m_lResult != ERROR_SUCCESS)
				return FALSE;
		}
		else if (lpszValue == NULL)
		{
			CHKey hSecKey(GetSectionKey(lpszSection));
			if (hSecKey == NULL)
				return FALSE;

			// necessary to cast away const below
			m_lResult = ::RegDeleteValue(hSecKey, (LPTSTR)lpszEntry);

			if (m_lResult != ERROR_SUCCESS)
				return FALSE;
		}
		else
		{
			CHKey hSecKey(GetSectionKey(lpszSection));
			if (hSecKey == NULL)
				return FALSE;

			m_lResult = ::RegSetValueEx(hSecKey, lpszEntry, NULL, REG_SZ,
				(LPBYTE)lpszValue, (lstrlen(lpszValue)+1)*sizeof(TCHAR));

			if (m_lResult != ERROR_SUCCESS)
				return FALSE;
		}

		return TRUE;
	}
	else
	{
		ASSERT(m_strINIFileName.IsEmpty() == FALSE);
		ASSERT(m_strINIFileName.GetLength() < 4095); // can't read in bigger
		return ::WritePrivateProfileString(lpszSection, lpszEntry, lpszValue,
			m_strINIFileName);
	}
}
Exemplo n.º 5
0
	BOOL CULProfileReg::GetProfileBinary(LPCTSTR pcszSection, LPCTSTR pcszEntry,
			void* pValue,DWORD* lpdwValLen)
	{
		if(pcszEntry==NULL)
			return FALSE;
		HKEY hSecKey = GetSectionKey(pcszSection);
		if (hSecKey == NULL)
			return FALSE;
		DWORD dwType, dwCount;
		LONG lResult=RegQueryValueEx(hSecKey, (LPTSTR)pcszEntry, NULL, &dwType,
			NULL, &dwCount);
		if(pValue==NULL)
		{
			*lpdwValLen=dwCount;
			return FALSE;
		}
		if ((lResult==ERROR_SUCCESS)&&(dwType==REG_BINARY)&&(dwCount<=*lpdwValLen))
		{ 
			lResult = RegQueryValueEx(hSecKey, (LPTSTR)pcszEntry, NULL, &dwType,
				(LPBYTE)pValue,lpdwValLen);
			RegCloseKey(hSecKey);	
		}
		else
		{
			RegCloseKey(hSecKey);	
			return FALSE;
		}
		return (lResult == ERROR_SUCCESS);
	}
Exemplo n.º 6
0
UINT GetProfileInteger(STR lpszSection, STR lpszEntry, int nDefault)
{
	DWORD dwValue;
	DWORD dwType;
	DWORD dwCount = sizeof(DWORD);
	LONG lResult;

	assert(lpszSection != NULL);
	assert(lpszEntry != NULL);

	if (gszRegistryKey[0] != '\0') // use registry
	{
		HKEY hSecKey = GetSectionKey(lpszSection);
		if (hSecKey == NULL)
			return nDefault;
		lResult = RegQueryValueEx(hSecKey, (LPTSTR)lpszEntry, NULL, &dwType,
			(LPBYTE)&dwValue, &dwCount);
		RegCloseKey(hSecKey);
		if (lResult == ERROR_SUCCESS)
		{
			assert(dwType == REG_DWORD);
			assert(dwCount == sizeof(dwValue));
			return (UINT)dwValue;
		}
		return nDefault;
	}
	else
	{
		assert(gszProfileName[0] != '\0');
		return GetPrivateProfileInt(lpszSection, lpszEntry, nDefault,
			gszProfileName);
	}
}
Exemplo n.º 7
0
BOOL CRegProfile::WriteProfileBinary(LPCTSTR lpszSection, LPCTSTR lpszEntry,
                                     LPBYTE pData, UINT nBytes)
{
    ASSERTATLMFC(lpszSection != NULL);
    if (m_pszRegistryKey != NULL)
    {
        LONG lResult;
        HKEY hSecKey = GetSectionKey(lpszSection);
        if (hSecKey == NULL)
            return FALSE;
        lResult = RegSetValueEx(hSecKey, lpszEntry, NULL, REG_BINARY,
                                pData, nBytes);
        RegCloseKey(hSecKey);
        return lResult == ERROR_SUCCESS;
    }

    // convert to string and write out
    LPTSTR lpsz = new TCHAR[nBytes*2+1];
    for (UINT i = 0; i < nBytes; i++)
    {
        lpsz[i*2] = (TCHAR)((pData[i] & 0x0F) + 'A'); //low nibble
        lpsz[i*2+1] = (TCHAR)(((pData[i] >> 4) & 0x0F) + 'A'); //high nibble
    }
    lpsz[i*2] = 0;

    ASSERTATLMFC(m_pszProfileName != NULL);

    BOOL bResult = WriteProfileString(lpszSection, lpszEntry, lpsz);
    delete[] lpsz;
    return bResult;
}
BOOL CXTPRegistryManager::WriteProfileRect(LPCTSTR lpszSection, LPCTSTR lpszEntry, CRect* pValue)
{
	ASSERT(lpszSection != NULL);
	if (m_strINIFileName.IsEmpty())
	{
		CHKey hSecKey(GetSectionKey(lpszSection));
		if (hSecKey == NULL)
			return FALSE;

		m_lResult = ::RegSetValueEx(hSecKey, lpszEntry, NULL, REG_BINARY,
			(LPBYTE)pValue, sizeof(CRect));

		if (m_lResult != ERROR_SUCCESS)
			return FALSE;

		return TRUE;
	}

	CString str;
	str.Format(_T("%i,%i,%i,%i"), pValue->left, pValue->top, pValue->right, pValue->bottom);

	BOOL bResult = WriteProfileString(lpszSection, lpszEntry, str);

	return bResult;
}
Exemplo n.º 9
0
BOOL	CRegistry::GetProfileString( LPCSTR lpszSection, LPCSTR lpszEntry, LPVOID lpData, UINT nBytes )
{
#ifndef	INI_USE
	HKEY	hSecKey = GetSectionKey( lpszSection );
	if( !hSecKey )
		return	lpszDefault;

	DWORD	dwType, dwCount;
	LONG	lResult = ::RegQueryValueEx( hSecKey, (LPTSTR)lpszEntry, NULL, &dwType, NULL, &dwCount );
	if( dwCount > nBytes ) {
		::RegCloseKey( hSecKey );
		return	FALSE;
	}

	if( lResult == ERROR_SUCCESS ) {
		lResult = ::RegQueryValueEx( hSecKey, (LPTSTR)lpszEntry, NULL, &dwType, lpData, &dwCount );
	}
	::RegCloseKey( hSecKey );

	return	(lResult==ERROR_SUCCESS)?TRUE:FALSE;
#else
	DWORD dw = ::GetPrivateProfileString( lpszSection, lpszEntry, "", (CHAR*)lpData, nBytes, m_szRegistryKey );
	return	(dw&&(dw<nBytes))?TRUE:FALSE;
#endif
}
UINT CXTPRegistryManager::GetProfileInt(LPCTSTR lpszSection, LPCTSTR lpszEntry, int nDefault)
{
	ASSERT(lpszSection != NULL);
	ASSERT(lpszEntry != NULL);
	if (!lpszSection || !lpszEntry)
		return 0;

	if (m_strINIFileName.IsEmpty()) // use registry
	{
		CHKey hSecKey(GetSectionKey(lpszSection, KEY_READ));
		if (hSecKey == NULL)
			return nDefault;

		DWORD dwValue;
		DWORD dwType;
		DWORD dwCount = sizeof(DWORD);

		m_lResult = ::RegQueryValueEx(hSecKey, (LPTSTR)lpszEntry, NULL, &dwType,
			(LPBYTE)&dwValue, &dwCount);

		if (m_lResult != ERROR_SUCCESS)
			return nDefault;

		ASSERT(dwType == REG_DWORD);
		ASSERT(dwCount == sizeof(dwValue));

		return (UINT)dwValue;
	}
	else
	{
		ASSERT(m_strINIFileName.IsEmpty() == FALSE);
		return ::GetPrivateProfileInt(lpszSection, lpszEntry, nDefault,
			m_strINIFileName);
	}
}
Exemplo n.º 11
0
UINT CRegProfile::GetProfileInt(LPCTSTR lpszSection, LPCTSTR lpszEntry,
                                int nDefault)
{
    ASSERTATLMFC(lpszSection != NULL);
    ASSERTATLMFC(lpszEntry != NULL);
    if (m_pszRegistryKey != NULL) // use registry
    {
        HKEY hSecKey = GetSectionKey(lpszSection);
        if (hSecKey == NULL)
            return nDefault;
        DWORD dwValue;
        DWORD dwType;
        DWORD dwCount = sizeof(DWORD);
        LONG lResult = RegQueryValueEx(hSecKey, (LPTSTR)lpszEntry, NULL, &dwType,
                                       (LPBYTE)&dwValue, &dwCount);
        RegCloseKey(hSecKey);
        if (lResult == ERROR_SUCCESS)
        {
            ASSERTATLMFC(dwType == REG_DWORD);
            ASSERTATLMFC(dwCount == sizeof(dwValue));
            return (UINT)dwValue;
        }
        return nDefault;
    }
    else
    {
        ASSERTATLMFC(m_pszProfileName != NULL);
        return ::GetPrivateProfileInt(lpszSection, lpszEntry, nDefault,
                                      m_pszProfileName);
    }
}
int CXTPRegistryManager::EnumValues(LPCTSTR lpszSection, CMap<CString, LPCTSTR, DWORD, DWORD&>* mapItems,
									CStringArray * arrayNames)
{
	ASSERT(lpszSection != NULL);

	CHKey hKey(GetSectionKey(lpszSection, KEY_READ));
	if (hKey == NULL)
		return 0;

	int index = 0;

	TCHAR szValue[512];
	DWORD dwLen = 512;
	DWORD dwType;

	while (::RegEnumValue(hKey, index++, szValue, &dwLen,
		NULL, &dwType, NULL, NULL) == ERROR_SUCCESS)
	{
		if (mapItems) mapItems->SetAt(szValue, dwType);
		if (arrayNames) arrayNames->Add(szValue);
		dwLen = 512;
	}

	return --index;
}
Exemplo n.º 13
0
BOOL CRegProfile::WriteProfileInt(LPCTSTR lpszSection, LPCTSTR lpszEntry,
                                  int nValue)
{
    ASSERTATLMFC(lpszSection != NULL);
    ASSERTATLMFC(lpszEntry != NULL);
    if (m_pszRegistryKey != NULL)
    {
        HKEY hSecKey = GetSectionKey(lpszSection);
        if (hSecKey == NULL)
            return FALSE;
        LONG lResult = RegSetValueEx(hSecKey, lpszEntry, NULL, REG_DWORD,
                                     (LPBYTE)&nValue, sizeof(nValue));
        RegCloseKey(hSecKey);
        return lResult == ERROR_SUCCESS;
    }
    else
    {
        ASSERTATLMFC(m_pszProfileName != NULL);

        TCHAR szT[16];
        wsprintf(szT, _T("%d"), nValue);
        return ::WritePrivateProfileString(lpszSection, lpszEntry, szT,
                                           m_pszProfileName);
    }
}
BOOL CXTPRegistryManager::WriteProfileInt(LPCTSTR lpszSection, LPCTSTR lpszEntry, int nValue)
{
	ASSERT(lpszSection != NULL);
	ASSERT(lpszEntry != NULL);
	if (!lpszSection)
		return 0;

	if (m_strINIFileName.IsEmpty())
	{
		CHKey hSecKey(GetSectionKey(lpszSection));
		if (hSecKey == NULL)
			return FALSE;

		m_lResult = ::RegSetValueEx(hSecKey, lpszEntry, NULL,
			REG_DWORD, (LPBYTE)&nValue, sizeof(nValue));

		if (m_lResult != ERROR_SUCCESS)
			return FALSE;

		return TRUE;
	}
	else
	{
		ASSERT(m_strINIFileName.IsEmpty() == FALSE);

		TCHAR szT[16];
		wsprintf(szT, _T("%d"), nValue);
		return ::WritePrivateProfileString(lpszSection, lpszEntry, szT,
			m_strINIFileName);
	}
}
Exemplo n.º 15
0
CStringW InformApp::GetProfileString(LPCSTR section, LPCWSTR entry, LPCWSTR defaultValue)
{
  if (theOS.IsWindows9X())
  {
    CString entryA(entry), defaultValueA(defaultValue);
    return CStringW(CWinApp::GetProfileString(section,entryA,defaultValueA));
  }

  if (m_pszRegistryKey == NULL)
    return defaultValue;
  HKEY secKey = GetSectionKey(section);
  if (secKey == NULL)
    return defaultValue;

  CStringW value;
  DWORD type, count;
  LONG result = ::RegQueryValueExW(secKey,entry,NULL,&type,NULL,&count);
  if (result == ERROR_SUCCESS)
  {
    result = ::RegQueryValueExW(secKey,entry,NULL,&type,
      (LPBYTE)value.GetBuffer(count/sizeof(WCHAR)),&count);
    value.ReleaseBuffer();
  }
  ::RegCloseKey(secKey);
  if (result == ERROR_SUCCESS)
    return value;
  return defaultValue;
}
Exemplo n.º 16
0
PString GetProfileString(LPCTSTR lpszSection, LPCTSTR lpszEntry,
	LPCTSTR lpszDefault)
{
	ASSERT(lpszSection != NULL);
	ASSERT(lpszEntry != NULL);
	if (m_pszRegistryKey != NULL)
	{
		HKEY hSecKey = GetSectionKey(lpszSection);
		if (hSecKey == NULL)
			return lpszDefault;
		CString strValue;
		DWORD dwType=REG_NONE;
		DWORD dwCount=0;
		LONG lResult = RegQueryValueEx(hSecKey, (LPTSTR)lpszEntry, NULL, &dwType,
			NULL, &dwCount);
		if (lResult == ERROR_SUCCESS)
		{
			ASSERT(dwType == REG_SZ);
			lResult = RegQueryValueEx(hSecKey, (LPTSTR)lpszEntry, NULL, &dwType,
				(LPBYTE)strValue.GetBuffer(dwCount/sizeof(TCHAR)), &dwCount);
			strValue.ReleaseBuffer();
		}
		RegCloseKey(hSecKey);
		if (lResult == ERROR_SUCCESS)
		{
			ASSERT(dwType == REG_SZ);
			return strValue;
		}
		return lpszDefault;
	}

	return lpszDefault;
}
bool CXTPRegistryManager::DeleteKey(LPCTSTR lpszSection, LPCTSTR lpszKey)
{
	CHKey hSectionKey(GetSectionKey(lpszSection));
	if (hSectionKey == NULL)
		return false;

	return (RecurseDeleteKey(hSectionKey, lpszKey) == ERROR_SUCCESS);
}
Exemplo n.º 18
0
BOOL CRegProfile::GetProfileBinary(LPCTSTR lpszSection, LPCTSTR lpszEntry,
                                   BYTE** ppData, UINT* pBytes)
{
    ASSERTATLMFC(lpszSection != NULL);
    ASSERTATLMFC(lpszEntry != NULL);
    ASSERTATLMFC(ppData != NULL);
    ASSERTATLMFC(pBytes != NULL);
    *ppData = NULL;
    *pBytes = 0;
    if (m_pszRegistryKey != NULL)
    {
        HKEY hSecKey = GetSectionKey(lpszSection);
        if (hSecKey == NULL)
            return FALSE;

        DWORD dwType, dwCount;
        LONG lResult = RegQueryValueEx(hSecKey, (LPTSTR)lpszEntry, NULL, &dwType,
                                       NULL, &dwCount);
        *pBytes = dwCount;
        if (lResult == ERROR_SUCCESS)
        {
            ASSERTATLMFC(dwType == REG_BINARY);
            *ppData = new BYTE[*pBytes];
            lResult = RegQueryValueEx(hSecKey, (LPTSTR)lpszEntry, NULL, &dwType,
                                      *ppData, &dwCount);
        }
        RegCloseKey(hSecKey);
        if (lResult == ERROR_SUCCESS)
        {
            ASSERTATLMFC(dwType == REG_BINARY);
            return TRUE;
        }
        else
        {
            delete [] *ppData;
            *ppData = NULL;
        }
        return FALSE;
    }
    else
    {
        ASSERTATLMFC(m_pszProfileName != NULL);

        CString str = GetProfileString(lpszSection, lpszEntry, NULL);
        if (str.IsEmpty())
            return FALSE;
        ASSERTATLMFC(str.GetLength()%2 == 0);
        int nLen = str.GetLength();
        *pBytes = nLen/2;
        *ppData = new BYTE[*pBytes];
        for (int i=0; i<nLen; i+=2)
        {
            (*ppData)[i/2] = (BYTE)
                             (((str[i+1] - 'A') << 4) + (str[i] - 'A'));
        }
        return TRUE;
    }
}
bool CXTPRegistryManager::DeleteValue(LPCTSTR lpszSection, LPCTSTR lpszValue)
{
	CHKey hSecKey(GetSectionKey(lpszSection, KEY_ALL_ACCESS));
	if (hSecKey == NULL)
		return false;

	m_lResult = ::RegDeleteValue(hSecKey, (LPTSTR)lpszValue);
	return (m_lResult == ERROR_SUCCESS);
}
Exemplo n.º 20
0
BOOL WriteProfileChar(STR lpszSection, STR lpszEntry, STR lpszValue)
{
	assert(lpszSection != NULL);

	if (gszRegistryKey[0] != '\0')
	{
		LONG lResult;
		if (lpszEntry == NULL) //delete whole section
		{
			HKEY hAppKey = GetAppRegistryKey();
			if (hAppKey == NULL)
				return FALSE;
			lResult = RegDeleteKey(hAppKey, lpszSection);
			RegCloseKey(hAppKey);
		}
		else if (lpszValue == NULL)
		{
			HKEY hSecKey = GetSectionKey(lpszSection);
			if (hSecKey == NULL)
				return FALSE;
			// necessary to cast away const below
			lResult = RegDeleteValue(hSecKey, (LPTSTR)lpszEntry);
			RegCloseKey(hSecKey);
		}
		else
		{
			HKEY hSecKey = GetSectionKey(lpszSection);
			if (hSecKey == NULL)
				return FALSE;
			lResult = RegSetValueEx(hSecKey, lpszEntry, 0, REG_SZ,
				(LPBYTE)lpszValue, (lstrlen(lpszValue)+1)*sizeof(TCHAR));
			RegCloseKey(hSecKey);
		}
		return lResult == ERROR_SUCCESS;
	}
//	else
//	{
//		assert(gpszProfileName != NULL);
//		assert(lstrlen(gpszProfileName) < 4095); // can't read in bigger
//		return ::WritePrivateProfileString(lpszSection, lpszEntry, lpszValue,
//			gpszProfileName);
//	}
	return TRUE;
}
Exemplo n.º 21
0
BOOL CRegProfile::WriteProfileString(LPCTSTR lpszSection, LPCTSTR lpszEntry,
                                     LPCTSTR lpszValue)
{
    ASSERTATLMFC(lpszSection != NULL);
    if (m_pszRegistryKey != NULL)
    {
        LONG lResult;
        if (lpszEntry == NULL) //delete whole section
        {
            HKEY hAppKey = GetSetupRegistryKey();
            if (hAppKey == NULL)
                return FALSE;
            lResult = ::RegDeleteKey(hAppKey, lpszSection);
            RegCloseKey(hAppKey);
        }
        else if (lpszValue == NULL)
        {
            HKEY hSecKey = GetSectionKey(lpszSection);
            if (hSecKey == NULL)
                return FALSE;
            // necessary to cast away const below
            lResult = ::RegDeleteValue(hSecKey, (LPTSTR)lpszEntry);
            RegCloseKey(hSecKey);
        }
        else
        {
            HKEY hSecKey = GetSectionKey(lpszSection);
            if (hSecKey == NULL)
                return FALSE;
            lResult = RegSetValueEx(hSecKey, lpszEntry, NULL, REG_SZ,
                                    (LPBYTE)lpszValue, (lstrlen(lpszValue)+1)*sizeof(TCHAR));
            RegCloseKey(hSecKey);
        }
        return lResult == ERROR_SUCCESS;
    }
    else
    {
        ASSERTATLMFC(m_pszProfileName != NULL);
        ASSERTATLMFC(lstrlen(m_pszProfileName) < 4095); // can't read in bigger
        return ::WritePrivateProfileString(lpszSection, lpszEntry, lpszValue,
                                           m_pszProfileName);
    }
}
Exemplo n.º 22
0
	BOOL CULProfileReg::WriteProfileInt(LPCTSTR pcszSection, LPCTSTR pcszEntry,int nValue)
	{
		if(pcszEntry==NULL)
			return FALSE;
		HKEY hSecKey = GetSectionKey(pcszSection);
		if (hSecKey == NULL)
			return FALSE;
		LONG lResult = RegSetValueEx(hSecKey, pcszEntry, NULL, REG_DWORD,
			(LPBYTE)&nValue, sizeof(nValue));
		RegCloseKey(hSecKey);
		return (lResult == ERROR_SUCCESS);
	}
Exemplo n.º 23
0
BOOLEAN GetProfileChar(STR lpszSection, STR lpszEntry, STR lpszDefault, STR lpszValue)
{
	DWORD		dwType, dwCount;
	LONG		lResult;
	BOOLEAN	fRet = TRUE;
	CHAR		strValue[200];

	assert(lpszSection != NULL);
	assert(lpszEntry != NULL);
	assert(lpszDefault != NULL);

	if (gszRegistryKey[0] != '\0')
	{
		HKEY hSecKey = GetSectionKey(lpszSection);
		if (hSecKey == NULL)
		{
			strcpy( lpszValue, lpszDefault );
			return(TRUE);
		}
		lResult = RegQueryValueEx(hSecKey, (LPTSTR)lpszEntry, NULL, &dwType,
			NULL, &dwCount);
		if (lResult == ERROR_SUCCESS)
		{
			assert(dwType == REG_SZ);
			lResult = RegQueryValueEx(hSecKey, (LPTSTR)lpszEntry, NULL, &dwType,
				(LPBYTE)strValue, &dwCount);
		}
		RegCloseKey(hSecKey);
		if (lResult == ERROR_SUCCESS)
		{
			assert(dwType == REG_SZ);
			strcpy( lpszValue, strValue );
			return(TRUE);
		}
		strcpy( lpszValue, lpszDefault );
		return(TRUE);
	}
//	else
//	{
//		assert(gpszProfileName != NULL);
//
//		if (lpszDefault == NULL)
//			lpszDefault = &afxChNil;    // don't pass in NULL
//		TCHAR szT[4096];
//		DWORD dw = ::GetPrivateProfileString(lpszSection, lpszEntry,
//			lpszDefault, szT, _countof(szT), gpszProfileName);
//		assert(dw < 4095);
//		return szT;
//	}

	return( fRet );
}
BOOL CXTPRegistryManager::GetProfileDouble(LPCTSTR lpszSection, LPCTSTR lpszEntry, double* dResult)
{
	ASSERT(lpszSection != NULL);
	ASSERT(lpszEntry != NULL);

	if (m_strINIFileName.IsEmpty())
	{

		CHKey hSecKey(GetSectionKey(lpszSection, KEY_READ));
		if (hSecKey == NULL)
			return FALSE;

		DWORD dwType, dwCount;
		m_lResult = ::RegQueryValueEx(hSecKey, (LPTSTR)lpszEntry, NULL, &dwType,
			NULL, &dwCount);

		if (m_lResult != ERROR_SUCCESS)
			return FALSE;

		ASSERT(dwType == REG_BINARY);
		m_lResult = ::RegQueryValueEx(hSecKey, (LPTSTR)lpszEntry, NULL, &dwType,
			(LPBYTE)dResult, &dwCount);

		if (m_lResult != ERROR_SUCCESS)
			return FALSE;

		ASSERT(dwType == REG_BINARY);
		return TRUE;
	}
	else
	{
		ASSERT(m_strINIFileName.IsEmpty() == FALSE);

		CString str = GetProfileString(lpszSection, lpszEntry, NULL);
		if (str.IsEmpty())
			return FALSE;

		ASSERT(str.GetLength()%2 == 0);
		int nLen = str.GetLength();

		LPBYTE pData = (LPBYTE) dResult;

		int i;
		for (i = 0; i < nLen; i += 2)
		{
			(pData)[i/2] = (BYTE)
				(((str[i + 1] - 'A') << 4) + (str[i] - 'A'));
		}

		return TRUE;
	}
}
Exemplo n.º 25
0
BOOL	CRegistry::WriteProfileBinary( LPCSTR lpszSection, LPCSTR lpszEntry, LPVOID lpData, UINT nBytes )
{
#ifndef	INI_USE
	HKEY	hSecKey = GetSectionKey( lpszSection );
	if( !hSecKey )
		return	FALSE;
	LONG	lResult = ::RegSetValueEx(hSecKey, lpszEntry, NULL, REG_BINARY, lpData, nBytes );
	::RegCloseKey( hSecKey );
	return	(lResult == ERROR_SUCCESS);
#else
	return	::WritePrivateProfileStruct( lpszSection, lpszEntry, lpData, nBytes, m_szRegistryKey );
#endif
}
Exemplo n.º 26
0
void CCommands::SetApplicationObject (IApplication * pApplication)
{
	// This function assumes pApplication has already been AddRef'd
	// for us, which CDSAddIn did in it's QueryInterface call
	// just before it called us.
	m_pApplication = pApplication;
	if (! m_pApplication)
		return;

	// Create Application event handlers
	XApplicationEventsObj::CreateInstance (&m_pApplicationEventsObj);
	if (! m_pApplicationEventsObj)
	{
		ReportInternalError ("XApplicationEventsObj::CreateInstance");
		return;
	}
	m_pApplicationEventsObj->AddRef ();
	m_pApplicationEventsObj->Connect (m_pApplication);
	m_pApplicationEventsObj->m_pCommands = this;

#ifdef NEVER
	// Create Debugger event handler
	CComPtr < IDispatch > pDebugger;
	if (SUCCEEDED (m_pApplication->get_Debugger (&pDebugger))
	    && pDebugger != NULL)
	{
		XDebuggerEventsObj::CreateInstance (&m_pDebuggerEventsObj);
		m_pDebuggerEventsObj->AddRef ();
		m_pDebuggerEventsObj->Connect (pDebugger);
		m_pDebuggerEventsObj->m_pCommands = this;
	}
#endif

	// Get settings from registry HKEY_CURRENT_USER\Software\Vim\VisVim
	HKEY hAppKey = GetAppKey ("Vim");
	if (hAppKey)
	{
		HKEY hSectionKey = GetSectionKey (hAppKey, "VisVim");
		if (hSectionKey)
		{
			g_bEnableVim = GetRegistryInt (hSectionKey, "EnableVim",
						       g_bEnableVim);
			g_bDevStudioEditor = GetRegistryInt(hSectionKey,"DevStudioEditor",
							    g_bDevStudioEditor);
			g_ChangeDir = GetRegistryInt (hSectionKey, "ChangeDir",
						      g_ChangeDir);
			RegCloseKey (hSectionKey);
		}
		RegCloseKey (hAppKey);
	}
}
Exemplo n.º 27
0
BOOL WriteProfileString(LPCTSTR lpszSection, LPCTSTR lpszEntry,
			LPCTSTR lpszValue)
{
	ASSERT(lpszSection != NULL);
	if (m_pszRegistryKey != NULL)
	{
		LONG lResult;
		if (lpszEntry == NULL) //delete whole section
		{
			HKEY hAppKey = GetAppRegistryKey();
			if (hAppKey == NULL)
				return FALSE;
			lResult = ::RegDeleteKey(hAppKey, lpszSection);
			RegCloseKey(hAppKey);
		}
		else if (lpszValue == NULL)
		{
			HKEY hSecKey = GetSectionKey(lpszSection);
			if (hSecKey == NULL)
				return FALSE;
			// necessary to cast away const below
			lResult = ::RegDeleteValue(hSecKey, (LPTSTR)lpszEntry);
			RegCloseKey(hSecKey);
		}
		else
		{
			HKEY hSecKey = GetSectionKey(lpszSection);
			if (hSecKey == NULL)
				return FALSE;
			lResult = RegSetValueEx(hSecKey, lpszEntry, NULL, REG_SZ,
				(LPBYTE)lpszValue, (ATL::lstrlen(lpszValue)+1)*sizeof(TCHAR));
			RegCloseKey(hSecKey);
		}
		return lResult == ERROR_SUCCESS;
	}
	return FALSE;
}
CString CXTPRegistryManager::GetProfileString(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpszDefault)
{
	ASSERT(lpszSection != NULL);
	ASSERT(lpszEntry != NULL);
	if (m_strINIFileName.IsEmpty())
	{
		CHKey hSecKey(GetSectionKey(lpszSection, KEY_READ));
		if (hSecKey == NULL)
			return lpszDefault;

		CString strValue;
		DWORD dwType, dwCount;

		m_lResult = ::RegQueryValueEx(hSecKey, (LPTSTR)lpszEntry, NULL, &dwType,
			NULL, &dwCount);

		if (m_lResult != ERROR_SUCCESS)
			return lpszDefault;

		ASSERT(dwType == REG_SZ);
		m_lResult = ::RegQueryValueEx(hSecKey, (LPTSTR)lpszEntry, NULL, &dwType,
			(LPBYTE)strValue.GetBuffer(dwCount/sizeof(TCHAR)), &dwCount);
		strValue.ReleaseBuffer();

		if (m_lResult != ERROR_SUCCESS)
			return lpszDefault;

		ASSERT(dwType == REG_SZ);
		return strValue;
	}
	else
	{
		TCHAR chNil = '\0';

		ASSERT(m_strINIFileName.IsEmpty() == FALSE);

		if (lpszDefault == NULL)
		{
			lpszDefault = &chNil;    // don't pass in NULL
		}

		TCHAR szT[4096];
		DWORD dw = ::GetPrivateProfileString(lpszSection, lpszEntry,
			lpszDefault, szT, _countof(szT), m_strINIFileName);
		ASSERT(dw < 4095);
		return szT;
	}
}
Exemplo n.º 29
0
	BOOL CULProfileReg::GetProfileInt(LPCTSTR pcszSection, LPCTSTR pcszEntry,DWORD* pdwValue)
	{
		if(pcszEntry==NULL)
			return FALSE;
		if(pdwValue==NULL)
			return FALSE;
		HKEY hSecKey = GetSectionKey(pcszSection);
		if (hSecKey == NULL)
			return FALSE;
		DWORD dwType;
		DWORD dwCount = sizeof(*pdwValue);
		LONG lResult = RegQueryValueEx(hSecKey, (LPTSTR)pcszEntry, NULL, &dwType,
			(LPBYTE)pdwValue, &dwCount);
		RegCloseKey(hSecKey);
		return (lResult == ERROR_SUCCESS);
	}
Exemplo n.º 30
0
BOOL	CRegistry::WriteProfileInt( LPCSTR lpszSection, LPCSTR lpszEntry, INT nValue )
{
#ifndef	INI_USE
	HKEY	hSecKey = GetSectionKey( lpszSection );
	if( !hSecKey )
		return	FALSE;
	LONG	lResult = ::RegSetValueEx(hSecKey, lpszEntry, NULL, REG_DWORD,
			(LPBYTE)&nValue, sizeof(nValue));
	::RegCloseKey( hSecKey );
	return	(lResult == ERROR_SUCCESS);
#else
	CHAR	szTemp[16];
	wsprintf( szTemp, "%d", nValue );
	return	::WritePrivateProfileString( lpszSection, lpszEntry, szTemp, m_szRegistryKey );
#endif
}