views:

4672

answers:

4

I was making the following call:

result = RegOpenKeyEx(key, s, 0, KEY_READ, &key);

(C++, Visual Studio 5, Vista 64bit).

It is failing with error code 2 ("File not found") even though "regedit" shows that the key exists. This code has always worked on 32bit XP. Why is it "file not found" when it clearly is there?

+5  A: 

I discovered that I could solve my problem using the flag: KEY_WOW64_64KEY , as in:

result = RegOpenKeyEx(key, s, 0, KEY_READ|KEY_WOW64_64KEY, &key);

For a full explanation: http://msdn.microsoft.com/en-us/library/ms724072(VS.85).aspx

Tim Cooper
+4  A: 

On a Windows 64-bit system the Registry is actually divided into two parts. One section is used by 64-bit processes, and one part by 32-bit processes.

For example, if a 32-bit application programatically writes to what it believes is HKLM\SOFTWARE\Company\Application, it's actually redirected by the WoW64-layer to HKLM\SOFTWARE\Wow6432Node\Company\Application.

So when you run your 32-bit application and call RegOpenKeyEx it's actually working against the Wow6432Node\ folder, and not the regular \SOFTWARE node.

Frode Lillerud
A: 

hi, i had a similar problem i was using dwResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, (LPWSTR)"SOFTWARE\0test", 0, WRITE_DAC , &hKey);

didn't work...returned 2

tried like this and it worked dwResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\0test"), 0, WRITE_DAC , &hKey);

A: 

Taken from http://www.codeguru.com/forum/showthread.php?t=360665

wchar_t sound[]=L"C:/ohhnooo.wav";

TEXT("c:\ohhnooo.wav")

konkeong