News:

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

Registry Access

Started by Mincho Georgiev, June 26, 2005, 11:24:47 PM

Previous topic - Next topic

Mincho Georgiev

I Hope My Class For RegAccess to be usefull for somebody!


;--====================================================================--
;--===        Registry Access                               ==--
;--===          Copyright 2005 by Mincho Georgiev                    ==--
;--===                   shaka_zulu@mail.bg                                            ==-
;--====================================================================--

;--===================================================================--
SaveString PROTO :DWORD,:DWORD,:DWORD,:DWORD
GetString  PROTO :DWORD,:DWORD,:DWORD
SaveDword  PROTO :DWORD,:DWORD,:DWORD,:DWORD
GetDword   PROTO :DWORD,:DWORD
;--===================================================================--

.code
;--====================string values==================================--

SaveString proc lpszKey:DWORD,lpszValue:DWORD,
lpszString:DWORD, dwStrLength:DWORD
LOCAL phkResult :DWORD
LOCAL lpdwDisposition :DWORD

invoke RegCreateKeyEx,HKEY_LOCAL_MACHINE,
lpszKey,NULL,NULL,
REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,
NULL,ADDR phkResult,ADDR lpdwDisposition
.if eax==ERROR_SUCCESS
invoke RegSetValueEx,phkResult,lpszValue,
NULL,REG_SZ,lpszString,dwStrLength
invoke RegCloseKey,phkResult
return TRUE
.endif
xor eax,eax
ret
SaveString endp

GetString proc  lpszKey:DWORD,lpszValueName:DWORD,lpszBuffer:DWORD
LOCAL dwStrLength:DWORD
LOCAL phkResult :DWORD
LOCAL RType:DWORD
LOCAL lpcbData :DWORD
mov eax,REG_SZ
mov RType,eax
invoke RegCreateKeyEx,HKEY_LOCAL_MACHINE,
lpszKey,NULL,NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,ADDR phkResult,ADDR RType
.if eax==ERROR_SUCCESS
mov eax,REG_DWORD
mov RType,eax
invoke RegQueryValueEx,phkResult,lpszValueName,
NULL,ADDR RType, lpszBuffer,
lpcbData
invoke RegCloseKey,phkResult

.endif

ret
GetString endp

;--======================dword values========================================--

SaveDword proc   dwKey:DWORD,dwValue:DWORD,
lpDword:DWORD,dwStrLength:DWORD

LOCAL phkResult :DWORD
LOCAL lpdwDisposition :DWORD
invoke RegCreateKeyEx,HKEY_LOCAL_MACHINE,
dwKey,NULL,NULL,
REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,
NULL,ADDR phkResult,ADDR lpdwDisposition
.if eax==ERROR_SUCCESS
invoke RegSetValueEx,phkResult,dwValue,
NULL,REG_DWORD,lpDword,dwStrLength
invoke RegCloseKey,phkResult
return TRUE
.endif

xor eax,eax
ret
SaveDword endp

GetDword proc dwKey:DWORD,dwValueName:DWORD
LOCAL dwSize:DWORD
LOCAL phkResult :DWORD
LOCAL lpdwDisposition :DWORD
LOCAL RType :DWORD
LOCAL lpData:DWORD
invoke RegCreateKeyEx,HKEY_LOCAL_MACHINE,
dwKey,NULL,NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,NULL,
ADDR phkResult,ADDR lpdwDisposition
.if eax==ERROR_SUCCESS
mov eax,REG_DWORD
mov RType,eax
invoke RegQueryValueEx,phkResult,
dwValueName,NULL,ADDR RType,
ADDR lpData,ADDR dwSize
invoke RegCloseKey,phkResult
return lpData
.endif

xor eax,eax
ret
GetDword endp
;--====================================================================--


Mincho, I added the "code" tags in square brackets so your code would display correctly. hutch--

Mincho Georgiev


braymailloux

Does the code require change to access REG_BINARY data types?

Gunner

Haven't tested, but it seems good.
Why use KEY_ALL_ACCESS for everything?  Why not use KEY_READ for getting  and KEY_WRITE for putting.
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com