News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

HELP: How to read a DWORD value from Registry

Started by gh0sts416, April 08, 2009, 08:18:42 PM

Previous topic - Next topic

gh0sts416

I am very new to asm and when it comes to querying a registry value, DWORD in my case,
I'm absolutely lost. I was able to build a little function with the help of about 5 different examples.
Of course I know I'm doing something wrong because I always get an empty value.

This code is a simple variation, 99%, from Mincho Georgiev's registry class, the only problem is
when I use the original class from Mincho Georgiev I get an error saying 'return' is unidentified
or something to that extent.


ReadDWORD proc hKey:HKEY, subKey:DWORD, dwValue:DWORD
   LOCAL phkResult :DWORD
   LOCAL dwDisp    :DWORD
   LOCAL dwSize    :DWORD
   LOCAL regType   :DWORD
   LOCAL lpData    :DWORD
   
invoke RegCreateKeyEx, hKey, subKey, NULL,
                                     NULL,
                                     REG_OPTION_NON_VOLATILE,
                                     KEY_ALL_ACCESS,
                                     NULL,
                                     addr phkResult,
                                     addr dwDisp   
   .if eax == ERROR_SUCCESS
       mov eax, REG_DWORD
       mov regType, eax
       invoke RegQueryValueEx, phkResult, dwValue, NULL,
                                                   addr regType,
                                                   addr lpData,
                                                   addr dwSize 
       invoke RegCloseKey, phkResult
   .endif
    ret
ReadDWORD endp


Any help in the right direction would be an absolute god send!! 

donkey

The type is a return not a parameter, you can use NULL if you don't need to know the returned type. The second parameter is a value name, always a pointer to a string or NULL if you want the default...

mov [dwSize], 4 // Set the size of the return buffer
invoke RegQueryValueEx, [phkResult], NULL, NULL, NULL, addr lpData, addr dwSize
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Mark Jones

Hi Ghosts, welcome to the forum.

Please try the search box near the top-left of the page, chances are very good that most questions have already been asked. Here is one example from several years ago:

http://www.masm32.com/board/index.php?topic=2620.0
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08