WINAPI: Windows Registry functions fail

0

I have a trouble writing some keys into registry:

PHKEY key = NULL; HRESULT hResult = S_FALSE;
hResult = RegOpenKeyEx(HKEY_CLASSES_ROOT, _T("AppID"), 0, KEY_CREATE_SUB_KEY, key);

and this fails with code 0x00000057 - The parameter is incorrect.

hResult = RegCreateKeyEx(HKEY_CLASSES_ROOT, _T("new_key_name"), 0, NULL,
    REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, key, NULL);

this fails with code 0x000003f2 - The configuration registry key is invalid.

I have also tried some variations, but the result is always the same. I was using this functions before and never had a problem. I'm totally confused.

Can anyone help???

c++
winapi
registry

1 Answer

4

In the first example, the last parameter (HKEY *) returns the new key. You must provide the variable (HKEY, not PHKEY) where RegOpenKeyEx should store the value, and pass its address:

HKEY key = 0;
hResult = RegOpenKeyEx(...., &key);

The second call may have the same problem.

answered on Stack Overflow May 28, 2015 by peterchen • edited May 28, 2015 by peterchen

User contributions licensed under CC BY-SA 3.0