2,644
社区成员




//设置传输协议(TCP/UDP)
const char * cRegistryEntryProtocol = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\";
BOOL CRegistry::SetProtocol(const char* inProtocol)
{
const long cMaxLength = 1024;
BYTE protocolData[cMaxLength];
DWORD actualLength = 0;
memset(protocolData, 0, cMaxLength);
// 生成Filter信息注册部分的注册表入口
HKEY hKey = NULL;
LONG result = ::RegOpenKeyEx(HKEY_CURRENT_USER, cRegistryEntryProtocol, 0, KEY_QUERY_VALUE, &hKey);
BOOL pass = (result == ERROR_SUCCESS);
if (pass)
{
// 读取protocol的值
actualLength = cMaxLength;
result = ::RegQueryValueEx(hKey, "3GWaSuTV", NULL, NULL, protocolData, &actualLength);
pass = (result == ERROR_SUCCESS);
}
if (pass)
{
if (strcmp((const char*)protocolData, inProtocol) != 0)
{
// 修改protocol部分,然后写回到注册表
//result = ::RegSetValueEx(hKey, "3GWaSuTV", NULL, REG_SZ, (const BYTE*)inProtocol, actualLength);
result = ::RegSetValueEx(hKey, "3GWaSuTV", NULL, REG_SZ, (const BYTE*)inProtocol, actualLength);
pass = (result == ERROR_SUCCESS);
}
}
if (hKey)
{
::RegCloseKey(hKey);
}
return pass;
}