forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using Windows API call to query registry through FTN95

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
mhudson



Joined: 05 Jan 2006
Posts: 18

PostPosted: Fri Jan 06, 2006 7:29 am    Post subject: Using Windows API call to query registry through FTN95 Reply with quote

Dear All,

A colleague of mine has been attempting to read values from the Windows registry by using Windows API calls through FTN95. The calls themselves are all defined, together with some of the parameter values that they need, in the windows.ins file, but he and I are unable to see why they are not working as expected.

Any help would be appreciated.

The code for a short program is as follows (in it, we are trying to get the processor name from the registry) (code is in fixed format so needs to be indented to work):
Code:

PROGRAM RegKey
IMPLICIT NONE

include <windows.ins>

CHARACTER(LEN=1000) :: Response

integer :: MyKey,Length

Response=''
Length=0
MyKey=0

PRINT*,'REGOPENKEYEX Return :',
®OPENKEYEX(HKEY_LOCAL_MACHINE,
&'HARDWAREDESCRIPTIONSystemCentralProcessor',
&0,KEY_READ,MyKey)

PRINT*,'REGOPENKEYEX MyKey :',MyKey

PRINT*,'REGQUERYVALUEEX Return:',
®QUERYVALUEEX(MyKey,'ProcessorNameString',
&0,REG_SZ,Response,Length)

PRINT*,'REGQUERYVALUEEX Length:',Length
PRINT*,'REGQUERYVALUEEX Text :',TRIM(Response)

PRINT*,'REGCLOSEKEY Return :',REGCLOSEKEY(MyKey)

END PROGRAM RegKey


The RegOpenKeyEx command seems to be working correctly because of the 0 return value and also because another return value is given if one changes the string to a registry key that definitely does not exist.

The problem is with the RegQueryValueEx command. The value of "0" that is used should possibly be somethng else because, according to the MSDN, this should be a NULL value. I recalled vaguely reading that a NULL can be mocked up by a CORE4(0), but this does not fix the problem. Neither does explicitly terminating the strings with char(0).

Does anyone out there have any experience of trying to do this sort of thing through FTN95?

Thanks for any help.
Back to top
View user's profile Send private message
Andrew



Joined: 09 Sep 2004
Posts: 232
Location: Frankfurt, Germany

PostPosted: Sat Jan 07, 2006 6:52 am    Post subject: Using Windows API call to query registry through FTN95 Reply with quote

If only Fortran had a NULL...

Probably one of the easiest ways to do do what you want is to write a small bit of C using the Salford C compiler, SCC.EXE which is installed with FTN95. You could write a simple routine (or set of routines) that do what you want with the registry, compile them to object format, and they can they directly link in with your Fortran objects (and be called from) to produce your final executable. If you use the Salford C compiler, rather than VC++ for example then you can link the objects directly, without having to bother with DLL calls etc.
Back to top
View user's profile Send private message
Anonymous
Guest





PostPosted: Sat Jan 07, 2006 2:29 pm    Post subject: Using Windows API call to query registry through FTN95 Reply with quote

I have some experience of using the Registry API calls through FTN77. The problem whether you are usnig FTN77 or FTN95 is the same - that sometimes you have to supply a NULL value to one of the API calls. Furthermore, some of the API calls are cluttered with arguments that you hardly ever need for most purposes.

I've got some C and Fortran wrappers in source form if this is of interest to you. I could also dust off a test program.

DMV
Back to top
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7923
Location: Salford, UK

PostPosted: Sat Jan 07, 2006 5:03 pm    Post subject: Using Windows API call to query registry through FTN95 Reply with quote

PROGRAM RegKey
INCLUDE <windows.ins>
CHARACTER(LEN=1000) :: Response
INTEGER :: MyKey,Length

Length=1000

k = REGOPENKEYEX(HKEY_LOCAL_MACHINE,
& 'HARDWAREDESCRIPTIONSystemCentralProcessor',
& 0,KEY_READ,MyKey)

k = REGQUERYVALUEEX(MyKey,'ProcessorNameString',
& CORE4(0),CORE4(0),Response,Length)

k = REGCLOSEKEY(MyKey)

PRINT*, Response(1:Length)

END PROGRAM RegKey
Back to top
View user's profile Send private message AIM Address
Anonymous
Guest





PostPosted: Mon Jan 09, 2006 2:42 am    Post subject: Using Windows API call to query registry through FTN95 Reply with quote

Hi Paul,

Thanks for the working example. Of course, it leads me to ask the obvious question...

Why do we need to use the CORE4(0) (i.e. NULL) in the place of the REG_SZ?

But, in any case, thanks for the reponse, and thanks to the others who responded.

Mark.
Back to top
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7923
Location: Salford, UK

PostPosted: Wed Jan 11, 2006 12:30 am    Post subject: Using Windows API call to query registry through FTN95 Reply with quote

Mark

The documentation says that it is an [out] value that can be set to NULL if it is not needed.

Regards

Paul
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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