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
REG_DWORD
It has the value 4 in win32prm.ins.
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
Can you post all of the relevant code for opening the key etc.
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
Two things...
- Modify the declaration of RegQueryValueEx
- 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
Hello Paul, the modification of the declaration of 'REGQUERY...' is the key in order to become successful. Many thanks for solving my problem. Manfred
According to the documentation the call will fail if length is less than 4 on input.
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
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