我收到了一些“使用旧式转换”的警告,我想将其删除,但我对此了解不够。
编辑:
HKEY_CURRENT_USER
确实是在 WinAPI 中定义的,所以我将不理会它。
(LPBYTE)&result
: LPBYTE(&result)
和 reinterpret_cast<LPBYTE>(&result)
工作,但我不知道两者是否等效。
那么我应该使用这三个中的哪一个?
(const BYTE*)&value
: reinterpret_cast<const BYTE*>(&value)
有效,但又是同样的事情。
那么我应该使用这两者中的哪一个?
更多上下文:
HKEY hKey;
std::string sResult = "";
if(regOpenKey(KEY_READ, &hKey))
{
DWORD size=1024, type = REG_SZ;
wchar_t result[MAX_PATH];
if(RegQueryValueEx(hKey, key, nullptr, &type, (LPBYTE)&result, &size) == ERROR_SUCCESS)
sResult = str_narrow(result);
}
RegCloseKey(hKey);
和:
HKEY hKey;
if(regOpenKey(KEY_ALL_ACCESS, &hKey))
{
DWORD value = 1;
RegSetValueEx(hKey, key, 0, REG_DWORD, (const BYTE*)&value, sizeof(value));
}
RegCloseKey(hKey);
感谢您的帮助:)
最佳答案
HKEY_CURRENT_USER
已在 WinAPI 中定义,因此不用管它。它可能会在没有警告的情况下发生变化(虽然不太可能,但有可能)。
(LPBYTE)&result: LPBYTE(&result)
works, but again, I have no idea if it's equivalent.
是的,是一样的。
(const BYTE*)&value: reinterpret_cast<const BYTE*>(&value)
works, but same thing again.
还是一样。
关于c++ - 如何处理这些旧式类型转换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52513830/