|
// 读取 REG_DWORD 类型的注册表键值代码
long lRet;
HKEY hKey;
DWORD port;
DWORD dwType = REG_DWORD;
DWORD dwValue;
lRet = RegOpenKeyEx(
HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\MSSQLServer\\Client\\SuperSocketNetLib\\Tcp",
0,
KEY_QUERY_VALUE,
&hKey
); //打开注册表
if(lRet == ERROR_SUCCESS)//读操作成功
{
lRet = RegQueryValueEx(
hKey,
"DefaultPort",
0,
&dwType,
(LPBYTE)&port,
&dwValue
); //如果打开成功,则读
if(lRet == ERROR_SUCCESS)
{
printf("\n打开成功,则读:");
cout << "DefaultPort: " << port << endl;
//mcfile << "DefaultPort: " << port << endl;
mcfile << "<port>" << port << "</port>" << endl;
}
//以下是读取失败
else
{
printf("\n读取失败:");
}
}
//以下是打开失败
else
{
printf("\n打开失败:");
}
RegCloseKey(hKey);//记住,一定要关闭 |
|