when i use invoke RegOpenKeyEx, HKEY_LOCAL_MACHINE...
how come i cant do it like this ..

Hive db "HKEY_LOCAL_MACHINE",2 dup(0)
invoke RegOpenKeyEx, addr Hive

:confused:
Posted on 2003-02-25 05:44:00 by illwill
Hello ill will,
The first param expects a "reg key handle" instead of ASCIIZ string.
HKEY_LOCAL_MACHINE is a constant that RegOpenKeyEx recognises as one of the root handles.
Posted on 2003-02-25 05:52:41 by C.Z.
is there anyway to get around it? i wanna be able to pass HKLM and HKCU depending on what key i need to pull from the registry
Posted on 2003-02-25 05:55:34 by illwill
Yes, pass either HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE as the first param, meaning you're going to open a subkey under either HKCU or HKLM, respectively.
Posted on 2003-02-25 06:01:29 by C.Z.
yea but can i use the Hive db method?? i wanna be able to change it that way ... is there a non ascii way of interchanging it instead of putting HKEY_LOCAL_MACHINE as the first param i want my program to place it there as a variable ..
how can i change it back and forth instead of using the HIVE db
Posted on 2003-02-25 06:05:26 by illwill
Nope, you cannot pass a string for the hKey, it has to be a handle to an open key or one of the predefined keys. Cannot pass a address to a string.

What are you trying to do? Let's say you have a combo box and it is filled with:
HKEY_CLASSES_ROOT
HKEY_CURRENT_CONFIG
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS

are you trying to pass the selection to RegOpenKeyEx?

Let's say you are, then I would use this code:


push 0
push 0
push CB_GETCURSEL
push ComboHandle
call SendMessage
.if eax == 0
mov hHive, HKEY_CLASSES_ROOT

.elseif eax == 1
mov hHive, HKEY_CURRENT_CONFIG

.elseif eax == 2
mov hHive, HKEY_CURRENT_USER

.elseif eax == 3
mov hHive, HKEY_LOCAL_MACHINE

.elseif eax == 4
mov hHive, HKEY_USERS
.endif


and you would pass hHive as the hKey parameter.
Posted on 2003-02-25 08:55:11 by Gunner
just use
.data

Hive dd HKEY_LOCAL_MACHINE

.code
invoke RegOpenKeyEx, Hive... ; open HKLM
mov Hive, HKEY_CURRENT_USER
invoke RegOpenKeyEx, Hive... ; open HKCU


If you are starting out with a string argument from a listbox or something just use a string compare...

.data

szHKLM db "HKEY_LOCAL_MACHINE", 0
szHKCU db "HKEY_CURRENT_USER", 0
Hive dd ?

.code
invoke lstrcmp, addr szHKLM, addr szSelectedInListbox
.if eax == 0
mov Hive, HKEY_LOCAL_MACHINE
.endif
invoke lstrcmp, addr szHKCU, addr szSelectedInListbox
.if eax == 0
mov Hive, HKEY_CURRENT_USER
.endif
invoke RegOpenKeyEx, Hive...


Alternatively if you are using a listbox or a listview you can use LB_SETITEMDATA / LB_GETITEMDATA or LVIF_PARAM respectively to set dword values (like the constants) to individual items, so you dont have to worry about the string mess.
Posted on 2003-02-25 09:02:14 by BubbaFate