The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Ksbunker on December 12, 2007, 05:22:00 AM

Title: Problems reading Registry
Post by: Ksbunker on December 12, 2007, 05:22:00 AM
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


Title: Re: Problems reading Registry
Post by: sinsi on December 12, 2007, 05:41:38 AM
invoke RegQueryValueEx,phkResult,lpszValueName,
   NULL,ADDR RType, lpszBuffer,
   ADDR lpcbData