Silverfrost Forums

Welcome to our forums

REG_DWORD

2 Apr 2007 2:48 #1841

Hello, can anyone tell me how to get the decimal value of a variable of type REG_DWORD which i have read from the registry using the STDCALL 'REGQUERYVALUEEX'. Many Thanks Manfred

2 Apr 2007 4:27 #1843

It has the value 4 in win32prm.ins.

3 Apr 2007 7:04 #1844

Paul, thanks for your comment, but this is not my problem. I tried to read the registry item 'Test' of type REG_DWORD which has the value 0x00000020(32). When i read this item with the STDCALL 'REGQUERYVALUEEX(hkey,'Test',CORE4(0), what_type, iwert, length)' where hkey, what_type, iwert and length are integers and length has the value of 4 i got for iwert a value of 538976288 and not the value 32. Manfred

3 Apr 2007 7:30 #1845

Can you post all of the relevant code for opening the key etc.

3 Apr 2007 10:01 #1846

Hello Paul, here comes the relevant code

IMPLICIT NONE STDCALL RegOpenKeyEx 'RegOpenKeyExA' (VAL,STRING,VAL,VAL,REF):INTEGER4 STDCALL RegQueryValueEx'RegQueryValueExA'(VAL,STRING,REF,REF,STRING,REF):INTEGER STDCALL RegCloseKey'RegCloseKey'(VAL):INTEGER INTEGER,PARAMETER :: HKEY_LOCAL_MACHINE=Z'80000002' INTEGER,PARAMETER :: KEY_ALL_ACCESS=Z'f003f' INTEGER,PARAMETER :: BUFSIZE=256 INTEGER :: hKey,res,length, what_type, iwert length = BUFSIZE res = RegOpenKeyEx(HKEY_LOCAL_MACHINE,'SOFTWARE\DYSMASP',0,KEY_ALL_ACCESS,hKey)
IF(res /= 0) STOP 'ERROR:Cannot open registry key : HKEY_LOCAL_MACHINE\SOFTWARE\DYSMASP' res = RegQueryValueEx(hKey,'Test',CORE4(0),what_type,iwert,length) IF(res /= 0)THEN PRINT
,'ERROR:Cannot read REG_DWORD Test' ELSE PRINT*,'REG_DWORD Test = ', iwert ENDIF res = RegCloseKey(hKey) END

Thanks, Manfred

3 Apr 2007 10:59 #1847

Two things...

  1. Modify the declaration of RegQueryValueEx
  2. set length = 4 before the call as below

IMPLICIT NONE STDCALL RegOpenKeyEx 'RegOpenKeyExA' (VAL,STRING,VAL,VAL,REF):INTEGER4 STDCALL RegQueryValueEx'RegQueryValueExA'(VAL,STRING,REF,REF,REF,REF):INTEGER STDCALL RegCloseKey'RegCloseKey'(VAL):INTEGER INTEGER,PARAMETER :: HKEY_LOCAL_MACHINE=Z'80000002' INTEGER,PARAMETER :: KEY_ALL_ACCESS=Z'f003f' INTEGER,PARAMETER :: BUFSIZE=256 INTEGER :: hKey,res,length, iwert length = BUFSIZE res = RegOpenKeyEx(HKEY_LOCAL_MACHINE,'SOFTWARE\Microsoft\.NETFramework',0,KEY_ALL_ACCESS,hKey) IF(res /= 0) STOP 'ERROR:Cannot open registry key' length = 4
res = RegQueryValueEx(hKey,'DbgJITDebugLaunchSetting',CORE4(0),CORE4(0),iwert,length) IF(res /= 0)THEN PRINT
,'ERROR:Cannot read REG_DWORD' ELSE PRINT*,'REG_DWORD Test = ', iwert ENDIF res = RegCloseKey(hKey) END

3 Apr 2007 11:48 #1849

Hello Paul, the modification of the declaration of 'REGQUERY...' is the key in order to become successful. Many thanks for solving my problem. Manfred

4 Apr 2007 6:51 #1850

According to the documentation the call will fail if length is less than 4 on input.

25 Mar 2010 10:01 #6217

When I use the code from this thread that Paul posted I get the following error message:

System.InvalidProgramException was unhandled Message: Common Language Runtime detected an invalid program.

If I replace CORE4(0) with 0, I do not get that error message, but the call to RegQueryValueEx returns an invalid value of 87.

Do I need to import something to use CORE4?

Here is the code I am using:

IMPLICIT NONE
STDCALL RegOpenKeyEx 'RegOpenKeyExA' (VAL,STRING,VAL,VAL,REF):INTEGER*4
STDCALL RegQueryValueEx'RegQueryValueExA'(VAL,STRING,REF,REF,REF,REF):INTEGER
STDCALL RegCloseKey'RegCloseKey'(VAL):INTEGER
INTEGER,PARAMETER :: HKEY_LOCAL_MACHINE=Z'80000002'
INTEGER,PARAMETER :: KEY_ALL_ACCESS=Z'f003f'
INTEGER,PARAMETER :: BUFSIZE=256
INTEGER :: hKey,res,length, iwert
length = BUFSIZE
res = RegOpenKeyEx(HKEY_LOCAL_MACHINE,'SOFTWARE\\Microsoft\\.NETFramework',0,KEY_ALL_ACCESS,hKey)
IF(res /= 0) STOP 'ERROR:Cannot open registry key'
length = 4
res = RegQueryValueEx(hKey,'DbgJITDebugLaunchSetting',CORE4(0),CORE4(0),iwert,length)
IF(res /= 0)THEN
PRINT*,'ERROR:Cannot read REG_DWORD'
ELSE
PRINT*,'REG_DWORD Test = ', iwert
ENDIF
res = RegCloseKey(hKey)
END
13 Jul 2010 8:12 #6614

I do not know what is going wrong here but if you need to use .NET rather than Win32 then you can avoid CORE4 by using a VAL rather than a REF...

IMPLICIT NONE 
STDCALL RegOpenKeyEx 'RegOpenKeyExA' (VAL,STRING,VAL,VAL,REF):INTEGER*4 
STDCALL RegQueryValueEx'RegQueryValueExA'(VAL,STRING,VAL,VAL,REF,REF):INTEGER 
STDCALL RegCloseKey'RegCloseKey'(VAL):INTEGER 
INTEGER,PARAMETER :: HKEY_LOCAL_MACHINE=Z'80000002' 
INTEGER,PARAMETER :: KEY_ALL_ACCESS=Z'f003f' 
INTEGER,PARAMETER :: BUFSIZE=256 
INTEGER :: hKey,res,length, iwert 
length = BUFSIZE 
res = RegOpenKeyEx(HKEY_LOCAL_MACHINE,'SOFTWARE\\Microsoft\\.NETFramework',0,KEY_ALL_ACCESS,hKey) 
IF(res /= 0) STOP 'ERROR:Cannot open registry key' 
length = 4 
res = RegQueryValueEx(hKey,'DbgJITDebugLaunchSetting',0,0,iwert,length) 
IF(res /= 0)THEN 
PRINT*,'ERROR:Cannot read REG_DWORD' 
ELSE 
PRINT*,'REG_DWORD Test = ', iwert 
ENDIF 
res = RegCloseKey(hKey) 
END 
Please login to reply.