int nRet; HKEY hKey; DWORD dwSize = 256; // Note 1 char pszKeyName[256] = {0}; nRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\PathA",0,KEY_READ,&hKey); if (nRet == ERROR_SUCCESS) nRet = RegQueryValueEx(hKey,"KeyName",NULL,NULL,(BYTE *)g_pszKeyName,&dwSize); nRet = RegCloseKey(hKey); // Note 2 dwSize = 256; // Note 3 nRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\PathB",0,KEY_READ,&hKey); if(nRet == ERROR_SUCCESS) nRet = RegQueryValueEx(hKey,"KeyName",NULL,NULL,(BYTE *)g_pszKeyName,&dwSize); nRet = RegCloseKey(hKey);
Note
- Note 1: dwSize 和 pszKeyName[]要夠大.
- Note 2: RegOpenKeyEx後要記得RegCloseKey, 不然RegOpenKeyEx 65535次會無法RegOpenKeyEx.
- Note 3: 重複使用dwSize 要reset size不然dwSize會為之前RegQueryValueEx的值.
References
沒有留言:
張貼留言