News:

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

Problems reading Registry

Started by Ksbunker, December 12, 2007, 05:22:00 AM

Previous topic - Next topic

Ksbunker

Ok, i'm writing a DLL that gets loaded by a process. Before the process is loaded, the DLL checks a particular register value, and performs a subsequent action.

Im having zero troubles writing to this value, but as soon as I attempt to read it, I get an error "This program has failed to initialize properley (0xc0000005). Press END to terminate this process".

The code... any ideas, cheers.

DllEntry proc hInstDll:HINSTANCE, reason:DWORD, reserved1:DWORD

.IF reason == DLL_PROCESS_ATTACH

  invoke ForceFullScreen

.ENDIF

mov eax, 1
ret
DllEntry endp

ForceFullscreen PROC

.data

szInit db "Initializing...", 0
szForceFullscreen db "Forcing FullScreen Mode", 0

szTrue db "TRUE", 0
szFalse db "FALSE", 0

szKeyName db "Software\Red Storm Entertainment\Rogue Spear", 0
szFullScreen db "FullScreen", 0
szFullScreenBuf db 10 dup(0)
dwSize dd 0

.code

  Invoke GetRegKeySZ, ADDR szKeyName, ADDR szFullScreen, ADDR szFullScreenBuf
 
  Invoke MessageBox, 0, ADDR szFullScreenBuf, ADDR szFullScreenBuf, MB_OK
;  Invoke lstrcmp, ADDR szTemp, ADDR szTrue
;  cmp eax, 0
;  jne @F
;  ret
 
@@: 
  Invoke MsgBoxTimeout, 0, ADDR szForceFullscreen, ADDR szInit, MB_OK, 2000
  Invoke SetRegKeySZ, ADDR szTrue, ADDR szKeyName, ADDR szFullScreen, SIZEOF szFullScreen

ret
ForceFullscreen EndP

GetRegKeySZ 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
GetRegKeySZ endp



sinsi

invoke RegQueryValueEx,phkResult,lpszValueName,
   NULL,ADDR RType, lpszBuffer,
   ADDR lpcbData
   
Light travels faster than sound, that's why some people seem bright until you hear them.