-
读取REG_SZ 类型的注册表键值
1 // 读取 REG_SZ 类型键值的代码 2 3 HKEY hKey = NULL; 4 DWORD dwSize = 0; 5 DWORD dwDataType = 0; 6 LPBYTE lpValue = NULL; 7 LPCTSTR const lpValueName = _T("TcpPort"); 8 9 LONG lRet = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, 10 _T("SOFTWARE\\Microsoft\\MSSQLServer\\MSSQLServer\\SuperSocketNetLib\\Tcp"), 11 0, 12 KEY_QUERY_VALUE, 13 &hKey); 14 if(ERROR_SUCCESS != lRet) 15 { 16 // Error handling (see this FAQ) 17 // return; 18 } 19 // Call once RegQueryValueEx to retrieve the necessary buffer size 20 ::RegQueryValueEx(hKey, 21 lpValueName, 22 0, 23 &dwDataType, 24 lpValue, // NULL 25 &dwSize); // will contain the data size 26 27 // Alloc the buffer 28 lpValue = (LPBYTE)malloc(dwSize); 29 30 // Call twice RegQueryValueEx to get the value 31 lRet = ::RegQueryValueEx(hKey, 32 lpValueName, 33 0, 34 &dwDataType, 35 lpValue, 36 &dwSize); 37 ::RegCloseKey(hKey); 38 if(ERROR_SUCCESS != lRet) 39 { 40 // Error handling 41 // return; 42 } 43 // Enjoy of lpValue... 44 cout << "port ----------------------- " << lpValue << endl; 45 46 // free the buffer when no more necessary 47 free(lpValue); 48 49 // 此段代码来源:http://forums.codeguru.com/showthread.php?247020-Windows-SDK-Registry-How-can-I-read-data-from-the-registry&s=
-
读取REG_DWORD 类型的注册表键值
1 // 读取 REG_DWORD 类型的注册表键值代码 2 3 long lRet; 4 HKEY hKey; 5 DWORD port;
C++ 读取REG_SZ 、REG_DWORD 、REG_MULTI_SZ 类型注册表值
最新推荐文章于 2022-12-08 14:19:20 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)