gpt4 book ai didi

c++ - RegQueryValueEx 得到不正确的数据

转载 作者:行者123 更新时间:2023-11-28 00:41:30 26 4
gpt4 key购买 nike

我使用此代码将注册表数据从 HKCU 复制到 HKLM。在 1-9 之间检索到正确的数字,但在 10 时我得到 a,11 时我得到 b,等等。我不知道我做错了什么,如果有任何帮助,我将不胜感激。

extern "C" UINT __stdcall ReadTempRegKey(MSIHANDLE hInstall)
{
HRESULT hr = S_OK;
UINT er = ERROR_SUCCESS;
HKEY hKey;
char szProductKey[MAX_PATH], lszValue[MAX_PATH];
TCHAR achKey[MAX_KEY_LENGTH], achClass[MAX_PATH] = TEXT(""), achValue[MAX_VALUE_NAME];
DWORD cbName, cchClassName = MAX_PATH, cSubKeys=0, cbMaxSubKey, cchMaxClass, cValues, cchMaxValue, cbMaxValueData, cbSecurityDescriptor;
FILETIME ftLastWriteTime;
PHKEY phkResult = NULL;
DWORD i, retCode, cchValue = MAX_VALUE_NAME,dwType=REG_SZ,dwSKeyValueSize,dwSize=255;

hr = WcaInitialize(hInstall, "ReadTempRegKey");
ExitOnFailure(hr, "Failed to initialize");

WcaLog(LOGMSG_STANDARD, "Initialized.");

Orc_Reg_Sub_LM_CU();

sprintf_s(szProductKey, "SOFTWARE\\%s",Orc_Get_Product_Name());

if( RegOpenKeyEx( HKEY_CURRENT_USER,
szProductKey,
0,
KEY_READ,
&hKey) == ERROR_SUCCESS
)
{
//Get the class name and the value count.
retCode = RegQueryInfoKey(
hKey, // key handle
achClass, // buffer for class name
&cchClassName, // size of class string
NULL, // reserved
&cSubKeys, // number of subkeys
&cbMaxSubKey, // longest subkey size
&cchMaxClass, // longest class string
&cValues, // number of values for this key
&cchMaxValue, // longest value name
&cbMaxValueData, // longest value data
&cbSecurityDescriptor, // security descriptor
&ftLastWriteTime); // last write time

// Enumerate the subkeys, until RegEnumKeyEx fails.

if (cSubKeys)
{
for (i=0; i<cSubKeys; i++)
{
cbName = MAX_KEY_LENGTH;
retCode = RegEnumKeyEx(hKey, i,
achKey,
&cbName,
NULL,
NULL,
NULL,
&ftLastWriteTime);
}
}

//Enumerate the key values.

if (cValues)
{
for (i=0, retCode=ERROR_SUCCESS; i<cValues; i++)
{
cchValue = MAX_VALUE_NAME;
achValue[0] = '\0';
retCode = RegEnumValue(hKey, i,
achValue,
&cchValue,
NULL,
NULL,
NULL,
NULL);

if (retCode == ERROR_SUCCESS )
{
DWORD dwSize = sizeof(lszValue);

retCode = RegQueryValueEx(hKey, achValue, NULL, &dwType,(LPBYTE)&lszValue, &dwSize);

lszValue 是收到的数据。

最佳答案

我将用我的 Crystal 球来尝试回答这个问题。

复制执行得非常好,但您查看的数据是十六进制的而不是十进制的。十进制值10是十六进制的a,十进制11b等等。

关于c++ - RegQueryValueEx 得到不正确的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18660001/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com