 |
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: N�rnberg, Germany
|
Posted: Fri Aug 25, 2006 12:14 am Post subject: FTN95 Interface to Windows registry |
|
|
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.
|
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
|
Back to top |
|
 |
Anonymous Guest
|
Posted: Mon Aug 28, 2006 5:05 am Post subject: FTN95 Interface to Windows registry |
|
|
Hi Paul,
I could not find an example and tried out the program below. There was a similar
question in the forum. However, I get the error - Retrun type is expected
Since I am using free format there should not be any truncation problems. What
could be the possible problem in this case?
Code: | program test_win32api
implicit none
include 'win32api.ins'
! Example from FTN95 Help
stdcall SUB2 'GetAttr':integer
stdcall CSUB3(REF,STRING(20)):STRING
stdcall SUB4 'GetSize'(REF,VAL,VAL,INSTRING,OUTSTRING(100))
! Copied this line from win32ins.api
STDCALL REGOPENKEYEX 'RegOpenKeyExA' (VAL,STRING,VAL,VAL,REF):INTEGER
STDCALL REGQUERYVALUE 'RegQueryValueA' (VAL,STRING,STRING,REF):INTEGER*4
end test_win32api |
|
|
Back to top |
|
 |
Anonymous Guest
|
Posted: Mon Aug 28, 2006 7:01 am Post subject: FTN95 Interface to Windows registry |
|
|
Hi Paul,
I assume that by using Code: | include 'win32api.ins' | I do not
have to define it again as I did. In the documentaion only examples
of how to define the calls are given.
From the MSDN the syntax is clear, I have however difficulties implementing
what I would like to do.
Is there some complete example in the documentation available?
|
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Mon Aug 28, 2006 12:44 pm Post subject: FTN95 Interface to Windows registry |
|
|
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.
|
|
Back to top |
|
 |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: N�rnberg, Germany
|
Posted: Mon Aug 28, 2006 12:48 pm Post subject: FTN95 Interface to Windows registry |
|
|
Hi Paul,
it is working!
If you could send your sample program that access the registry it will help me a lot!
Thanks
|
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Tue Aug 29, 2006 2:51 am Post subject: FTN95 Interface to Windows registry |
|
|
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,PARAMETER::HKEY_LOCAL_MACHINE=Z'80000002'
INTEGER,PARAMETER::BUFSIZE=256
INTEGER hKey,res,cbValue
CHARACTER(LEN=BUFSIZE) processorName
cbValue = BUFSIZE
res = RegOpenKey(HKEY_LOCAL_MACHINE,"HARDWAREDESCRIPTIONSystemCentralProcessor ",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 |
|
Back to top |
|
 |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: N�rnberg, Germany
|
Posted: Tue Aug 29, 2006 4:01 am Post subject: FTN95 Interface to Windows registry |
|
|
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
|
|
Back to top |
|
 |
dheller
Joined: 12 May 2011 Posts: 13 Location: Germany
|
Posted: Tue Dec 10, 2013 4:47 pm Post subject: |
|
|
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.
Code: | 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. |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Thu Dec 12, 2013 9:03 am Post subject: |
|
|
I am not able to give you a quick response. I have added it to my "to do" list. |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Thu Dec 12, 2013 8:03 pm Post subject: |
|
|
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.
Code: | 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
|
|
|
Back to top |
|
 |
dheller
Joined: 12 May 2011 Posts: 13 Location: Germany
|
Posted: Fri Dec 13, 2013 1:28 pm Post subject: |
|
|
Works for me now, thanks for your quick help. |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|