{I+=codeWee;}
[C++] MFC: Set/Get Registry String
void SetRegString( HKEY hKeyParent, LPCTSTR lpszSubKey ,LPCTSTR lpzValueName, LPCTSTR lpszValue = NULL )
{
    DWORD dw;
    HKEY hKey = NULL;
    LONG lRes = RegCreateKeyEx( hKeyParent, lpszSubKey, 0,
        REG_NONE, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
        NULL, &hKey , &dw);
    
    if( lpszValue )
        RegSetValueEx( hKey, lpzValueName, 0,  REG_SZ, (BYTE * const)lpszValue, (lstrlen(lpszValue)+1)*sizeof(TCHAR));
    
    RegCloseKey(hKey);
}

BOOL GetRegString( HKEY hKeyParent, LPCTSTR LpszSubKey, LPCTSTR lpzValueName, CString& rsValue )
{
    HKEY hKey = NULL;
    if (RegOpenKeyEx(hKeyParent, LpszSubKey, 0, KEY_ALL_ACCESS, &hKey)
        != ERROR_SUCCESS)
    {
        return FALSE;
    }

    TCHAR szValue[_MAX_PATH];
    DWORD dwCount = (DWORD)_MAX_PATH;
    
    DWORD dwType = NULL;
    if( RegQueryValueEx(hKey, (LPTSTR)lpzValueName, NULL, &dwType,
        (LPBYTE)szValue, &dwCount) == ERROR_SUCCESS )
    {
        if( (dwType == REG_SZ) || (dwType == REG_MULTI_SZ) || (dwType == REG_EXPAND_SZ) )
        {
            rsValue = szValue;
            RegCloseKey(hKey);
            return TRUE;
        }
    }
    
    return FALSE;
}
HTML | PHP | C++ | DirectX11 | Javascript | C# | HTML5 | ASP | SQL | General | CSS | Oculus Rift | Unity3d | Virtools SDK | Tip | NSIS | PowerShell | node.js | Web API | RTSP | All
Copyright© 2016 CodeWee.com All rights reserved.