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 

WinAPI calls

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



Joined: 13 Mar 2006
Posts: 43

PostPosted: Sun Aug 27, 2006 12:05 pm    Post subject: WinAPI calls Reply with quote

Hi,

I tried to use the WinAPI functions that access the windows registry, but I ran into some problems at compile time.

The following examples from the FTN95 tutorial are compiling just fine.

STDCALL SUB2 'GetAttr':INTEGER
STDCALL SUB4 'GetSize' (REF,VAL,VAL,INSTRING,OUTSTRING(100))
STDCALL CSUB3(REF,STRING(20)):STRING

Then I tried to compile the following call:

STDCALL REGSETVALUE 'RegSetValueA' (VAL,STRING,VAL,STRING,VAL):INTEGER

It doesn't compile and tells me
"error 904 - Return type is expected.
Found: (VAL,STRING,VAL,STRING,VAL):INTEGER"

I copied that line directly from the "win32api.ins" file and it seems to fit the syntax given in the tutorial.
If I reduce it to the following line, however, it does compile:

STDCALL REGSETVALUE 'RegSetValueA':INTEGER

Am I doing or thinking something wrong ?
Thank you
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Mon Aug 28, 2006 12:59 am    Post subject: WinAPI calls Reply with quote

Rainer,

One possibility is that you are using fixed format Fortran and that the line is truncated at column 72.
Then the INTEGER return type would be missing.

You should also check the arguments. I think you may have missed one out.

The usual way to proceed is to insert

INCLUDE 'win32api.ins'

in your code. You probably will not notice the small increase in time that it takes to compile.
Back to top
View user's profile Send private message AIM Address
Rainer



Joined: 13 Mar 2006
Posts: 43

PostPosted: Mon Aug 28, 2006 4:57 am    Post subject: WinAPI calls Reply with quote

Paul

Thanks for your fast response.
I'm not using fixed format, so that shouldn't be the problem.
I tried to include the win32api.ins. At first I got statement ordering errors, so I assume that the appropriate place for the "include" command is right after the regular "use" commands. When I put it there, I got like 5 minutes of "Return type is expected" error messages. It seems the compiler (FTN95 v4.6.0 btw) has a problem with the syntax of these commands in general.
Could it be a compiler option that I'm missing here ?
Back to top
View user's profile Send private message
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: Nürnberg, Germany

PostPosted: Mon Aug 28, 2006 5:33 am    Post subject: WinAPI calls Reply with quote

Hi Rainer and Paul,

I am trying the same winapi calls and got the same error - Return type is expected

Using FTN95 4.9.1 and this could mean that something other than the compiler is wrong.

Johannes
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Mon Aug 28, 2006 12:26 pm    Post subject: WinAPI calls Reply with quote

The following program compiles OK for me...

include "win32api.ins"
end

I cannot get this to fail no matter what command line switches I use.

Try it from a DOS box...

FTN95 prog.f90

Back to top
View user's profile Send private message AIM Address
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: Nürnberg, Germany

PostPosted: Mon Aug 28, 2006 12:42 pm    Post subject: WinAPI calls Reply with quote

Hi Paul,

the problem was that I used include AND defined the STDCALL again. This implies it was defined twice.
It is compiling now.

Are there any complete examples of how to use some of the win32api calls? I could not figure out what
excactly I must do from the MSDN definition. Are there some simply example from where I can get a
better idea of what to do? This will help a lot!

Thanks

Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Tue Aug 29, 2006 2:52 am    Post subject: WinAPI calls Reply with quote

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
View user's profile Send private message AIM Address
Rainer



Joined: 13 Mar 2006
Posts: 43

PostPosted: Tue Aug 29, 2006 6:35 am    Post subject: WinAPI calls Reply with quote

Hi Paul

I'm sorry to bother you with even more problems...

- Unfortunately it wasn't as easy as Johannes' problem. I did not use both include and STDCALL statements, but the problem is still there.
- Your short sample program compiles okay for me, both from PLATO and DOS Shell. So does your longer example on the windows registry. However, I don't know how to run my actual program from DOS Shell while still applying the corresponding project file. Is that possible ? Without the project file I get the same compiler errors from PLATO and DOS Shell.
- Running my complete project from PLATO (which is what I had done when the problem originally appeared) I get 5 minutes and dozens of pages of the same error message. Strangely, not even aborting the compilation works. Instead I get the message "Build or other process aborted by user", but it's not aborting, neither right away nor later on.

Rainer
Back to top
View user's profile Send private message
Rainer



Joined: 13 Mar 2006
Posts: 43

PostPosted: Tue Aug 29, 2006 6:41 am    Post subject: WinAPI calls Reply with quote

Is it possible that any predefined modules already include the Win API ? I'm including the modules MSWIN32 and MSW32PRM somewhere along the way. Still remnants of my predecessor's work... Sound like they might have something to do with it. Smile

Edit:
Placing calls to these two modules in your winreg sample program, I do indeed get the same "Return type is expected" errors as before. It seems MSWIN32 is the module with the Win API calls and this was the problem in the first place. I'll now go on and try to use the API. Smile

Thanks for the help so far.
Rainer
Back to top
View user's profile Send private message
Rainer



Joined: 13 Mar 2006
Posts: 43

PostPosted: Thu Aug 31, 2006 5:05 am    Post subject: WinAPI calls Reply with quote

Update:

Win API calls work fine now. Very Happy

Thanks again
Back to top
View user's profile Send private message
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