I've been messing with this for quite a while with no luck.
I'm sure the answer is probably simple.

I am trying to compare KeyValue and do something based on it.




.DATA

SubKey      BYTE "Marzipan\Mint",0; name of sub key in HKEY_CURRENT_USER
Key_Made    BYTE "Register key sucessfully created.",0
Failed      BYTE "Register key NOT sucessfully created.",0
Sample      BYTE "BOX",0
NewRegValue BYTE "Key's Value",0  ; Value name
KeyValue    DWORD 1234            ; Key set to this value
RegBuffer  db      256 dup(?)
RegSize    dd      256
CmpOK      db "Key value is OK.",0

.DATA?

RegH            PHKEY    ?    ; Handle for reg. key
RegType        DWORD    ?

.CODE

Start:
jmp begin

begin:


invoke RegCreateKey,HKEY_CURRENT_USER, ADDR SubKey,ADDR RegH

.IF EAX == ERROR_SUCCESS
invoke MessageBox, 0, ADDR Key_Made, ADDR Sample,MB_ICONINFORMATION
.ELSE
; if failed

invoke MessageBox, 0, ADDR Failed, ADDR Sample,MB_ICONINFORMATION

.ENDIF

invoke RegCloseKey, ADDR RegH; close handle for reg. key

invoke RegSetValueEx, RegH,ADDR NewRegValue,0,REG_DWORD,ADDR KeyValue,4

invoke  RegQueryValueEx, ADDR SubKey,\
              addr KeyValue, NULL,ADDR RegType,\
              addr RegBuffer, addr RegSize


.IF EAX == ERROR_SUCCESS

invoke MessageBox, 0, ADDR CmpOK, ADDR Sample,MB_ICONINFORMATION
.ELSE
; if failed

;invoke MessageBox, 0, ADDR Failed, ADDR Sample,MB_ICONINFORMATION

.ENDIF


invoke RegCloseKey, ADDR RegH; close handle for reg. key
Posted on 2010-09-11 19:48:23 by skywalker
Very simple indeed.  You closed the key handle and are subsequently trying to use the now invalid handle in subsequent calls ;)
Posted on 2010-09-11 21:42:23 by p1ranha
.DATA

SubKey      BYTE "Marzipan\Mint",0; name of sub key in HKEY_CURRENT_USER
Key_Made    BYTE "Register key sucessfully created.",0
Failed      BYTE "Register key NOT sucessfully created.",0
Sample      BYTE "BOX",0
NewRegValue BYTE "Key's Value",0  ; Value name
KeyValue    DWORD 1234            ; Key set to this value
RegBuffer  db      256 dup(?)
RegSize    dd      256
CmpOK      db "Key value is OK.",0

.DATA?

RegH            PHKEY    ?    ; Handle for reg. key
RegType        DWORD    ?
lpcbData dword ?
.code


; ---------------------------------------------------------------------------


start:
invoke RegCreateKey,HKEY_CURRENT_USER, ADDR SubKey,ADDR RegH


.IF EAX == ERROR_SUCCESS
invoke MessageBox, 0, ADDR Key_Made, ADDR Sample,MB_ICONINFORMATION
.ELSE
; if failed

invoke MessageBox, 0, ADDR Failed, ADDR Sample,MB_ICONINFORMATION

.ENDIF

COMMENT *
Why are you closing the handle?  You need the handle to set and query the value!

invoke RegCloseKey,  RegH; close handle for reg. key *

invoke RegSetValueEx, RegH,ADDR NewRegValue,0,REG_DWORD,ADDR KeyValue,4

COMMENT *
lpcbData
A pointer to a variable that specifies the size of the buffer pointed to by the lpData parameter, in bytes. When the function returns, this variable contains the size of the data copied to lpData.

The lpcbData parameter can be NULL only if lpData is NULL.

invoke  RegQueryValueEx, ADDR SubKey,\
              addr KeyValue, NULL,ADDR RegType,\
              addr RegBuffer, addr RegSize

Also, you need to use the handle of the key you used to set the value!
*
mov lpcbData, 4
invoke  RegQueryValueEx,  RegH,\
              addr NewRegValue, 0,0,\
              addr RegBuffer, addr lpcbData


.IF EAX == ERROR_SUCCESS

invoke MessageBox, 0, ADDR CmpOK, ADDR Sample,MB_ICONINFORMATION
.ELSE
; if failed

invoke MessageBox, 0, ADDR Failed, ADDR Sample,MB_ICONINFORMATION

.ENDIF

COMMENT *
NOW we can close the handle!
hKey
A handle to the open key to be closed

NOT a pointer to the handle!
*

invoke RegCloseKey, RegH; close handle for reg. key
Posted on 2010-09-11 21:59:48 by Gunner
Thanks a lot.

What is this doing?

mov lpcbData, 4

Posted on 2010-09-11 22:16:35 by skywalker

Thanks a lot.

What is this doing?

mov lpcbData, 4



Read the comment in the code, it tells you!
Posted on 2010-09-11 22:19:23 by Gunner