Windows: VC编程操作注册表键值

Windows: VC编程操作注册表键值

读写注册表键值的代码如下:

 1     HKEY  hKey;
 2     LPCTSTR path = _T("Software\\IDT\\Apo\\LFX\\MicIn\\Presets\\_Initial\\BeamForming\\");
 3     LPCTSTR name = _T("Bypass");
 4     DWORD val = 0x01;
 5     DWORD type = REG_DWORD;
 6     DWORD cbData = sizeof(DWORD);
 7     
 8     DWORD dwDisposition = REG_OPENED_EXISTING_KEY;
 9     if (::RegCreateKeyEx(HKEY_LOCAL_MACHINE, path, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition) == ERROR_SUCCESS)
10     {
11         if (::RegSetValueEx(hKey, name, NULL, type, (BYTE*)&val, cbData) == ERROR_SUCCESS)
12         {
13             wprintf(_T("%s%s set to %d.\n"), path, name, val);
14         }
15 
16         val = 0x00;
17 
18         if (::RegQueryValueEx(hKey, name, NULL, &type, (BYTE*)&val, &cbData) == ERROR_SUCCESS)
19         {
20             wprintf(_T("%s%s is %d.\n"), path, name, val);
21         }
22 
23 
24         ::RegCloseKey(hKey);
25     }

 

但是在x64系统下测试时遇到问题:

一开始将程序编译为Win32,发现指定位置的键值并没有正确修改,后来添加了读取代码进行测试,结果却发现读到的值确实正确的?

为嘛?

设定了一个特殊字符串的键名,再次运行,然后搜索注册表,发现系统自动在

HKEY_LOCAL_MACHINE\Software\Wow6432Node\IDT\Apo\LFX\MicIn\Presets\_Initial\BeamForming\

创建了此键值!

难怪,参考MSDN: http://msdn.microsoft.com/en-us/library/ms724072(v=vs.85).aspx

Redirection subnodes in the registry tree are created automatically by the WOW64 component using the nameWow6432Node.

将程序编译为x64,问题解决。

Windows: VC编程操作注册表键值

posted @ 2013-02-05 16:57  ououmiao  阅读(457)  评论(0编辑  收藏  举报