Hallo,
is it possible to access the windows registry using FTN95. The reason for this is to extract the initial paths for a program that is called from the FTN95 source.
Welcome to our forums
Hallo,
is it possible to access the windows registry using FTN95. The reason for this is to extract the initial paths for a program that is called from the FTN95 source.
Johannes
You can access the Registry using Windows API functions such RegOpenKeyEx and RegQueryValueEx that are declared in win32api.ins and the equivalent MODULE.
The documentation for these functions is in http://msdn.microsoft.com/library/en-us/sysinfo/base/registry_functions.asp
Johannes
Does the following program compile OK for you?
include 'win32api.ins' end
I did have a sample program that accesses the registry. I will see if I can find it.
Hi Paul,
it is working!
If you could send your sample program that access the registry it will help me a lot! 😃
Thanks
IMPLICIT NONE
STDCALL RegOpenKey'RegOpenKeyA'(VAL,STRING,REF):INTEGER
STDCALL RegQueryValueEx'RegQueryValueExA'(VAL,STRING,REF,REF,STRING,REF):INTEGER
STDCALL RegCloseKey'RegCloseKey'(VAL):INTEGER
INTEGER,PARAMETERHKEY_LOCAL_MACHINE=Z'80000002'
INTEGER,PARAMETERBUFSIZE=256
INTEGER hKey,res,cbValue
CHARACTER(LEN=BUFSIZE) processorName
cbValue = BUFSIZE
res = RegOpenKey(HKEY_LOCAL_MACHINE,'HARDWARE\DESCRIPTION\System\CentralProcessor\0',hKey)
IF(res /= 0) STOP 'ERROR:Cannot open registry key'
res = RegQueryValueEx(hKey,'ProcessorNameString',CORE4(0),CORE4(0),processorName,cbValue)
IF(res /= 0)THEN
PRINT*,'ERROR:Cannot read processor name'
ELSE
PRINT*,processorName(1:LEN_TRIM(processorName))
ENDIF
res = RegCloseKey(hKey)
end
Hi Paul,
thanks. This helps a lot 😃
From the example I could get the the desired result!
What I did not know was the following: 80000000 → HKEY_CLASSES_ROOT 80000001 → HKEY_CURRENT_USER 80000002 → HKEY_LOCAL_MACHINE 80000003 → HKEY_USERS
Please allow me to resurrect this topic, because I have a similar problem right now.
My code, in a nutshell, opens a subkey of HKCU, enumerates its underlying sub-subkeys, and checks them for a certain value.
integer, parameter :: ERROR_SUCCESS = 0, KEY_READ = Z'20019'
integer*8, parameter :: HKEY_CURRENT_USER = Z'80000001'
....
ret = RegOpenKeyEx(HKEY_CURRENT_USER, subkey, 0, KEY_READ,
+ key_handle)
.... !if no error ....
c......... number of subkeys?
ret = RegQueryInfoKey(key_handle, 0, 0, 0, LOC(num_subkeys),
+ 0, 0, 0, 0, 0, 0, 0)
.... rest of code
However, RegQueryInfoKey always fails with ret equal to 87: (WindowsError 87: ERROR_INVALID_PARAMETER The parameter is incorrect.)
What is wrong here? The code runs just fine with Intel Fortran, but I need it to work with FTN95, as well.
I already did try to use CORE4(0) instead of directly passing zeros, but I just get a runtime exception then. Also, Paul, I don't understand why in your last code sample you used CORE4(0) instead of directly passing a 0-pointer. As I understand it, CORE4(x) kind of de-references a pointer, much like * in C, but is the content of address 0 even well-defined?
Thanks in advance for any help. 😃
*Please note that I just included win32api.ins, instead of copying those STDCALL-statements like above.
I am not able to give you a quick response. I have added it to my 'to do' list.
Here is a small program to get the number of sub keys under Plato3. The answer is 26.
Note that I have modified the binding for RegQueryInfoKey to pass a REF rather than an INSTRING. Also this is FTN95 so the handles are 32 bit integers.
integer, parameter :: KEY_READ = Z'20019'
integer, parameter :: HKEY_CURRENT_USER = Z'80000001'
stdcall RegOpenKeyEx 'RegOpenKeyExA' (VAL,STRING,VAL,VAL,REF):integer
stdcall RegQueryInfoKey 'RegQueryInfoKeyA'(VAL,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF):integer
stdcall RegCloseKey 'RegCloseKey' (VAL):integer
integer ret,key_handle,num_subkeys
character(len=80)::subkey
subkey = 'Software\\Salford Software\\Plato3'
num_subkeys = 0
ret = RegOpenKeyEx(HKEY_CURRENT_USER, subkey, 0, KEY_READ, key_handle)
ret = RegQueryInfoKey(key_handle, CORE4(0), CORE4(0), CORE4(0), num_subkeys, &
& CORE4(0), CORE4(0), CORE4(0), CORE4(0), CORE4(0), CORE4(0), CORE4(0))
ret = RegCloseKey(key_handle)
print*, num_subkeys
end
Works for me now, thanks for your quick help.