View previous topic :: View next topic |
Author |
Message |
Rainer
Joined: 13 Mar 2006 Posts: 43
|
Posted: Sun Aug 27, 2006 12:05 pm Post subject: WinAPI calls |
|
|
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 |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7924 Location: Salford, UK
|
Posted: Mon Aug 28, 2006 12:59 am Post subject: WinAPI calls |
|
|
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 |
|
|
Rainer
Joined: 13 Mar 2006 Posts: 43
|
Posted: Mon Aug 28, 2006 4:57 am Post subject: WinAPI calls |
|
|
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 |
|
|
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: Nürnberg, Germany
|
Posted: Mon Aug 28, 2006 5:33 am Post subject: WinAPI calls |
|
|
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 |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7924 Location: Salford, UK
|
Posted: Mon Aug 28, 2006 12:26 pm Post subject: WinAPI calls |
|
|
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 |
|
|
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: Nürnberg, Germany
|
Posted: Mon Aug 28, 2006 12:42 pm Post subject: WinAPI calls |
|
|
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 |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7924 Location: Salford, UK
|
Posted: Tue Aug 29, 2006 2:52 am Post subject: WinAPI calls |
|
|
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 |
|
|
Rainer
Joined: 13 Mar 2006 Posts: 43
|
Posted: Tue Aug 29, 2006 6:35 am Post subject: WinAPI calls |
|
|
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 |
|
|
Rainer
Joined: 13 Mar 2006 Posts: 43
|
Posted: Tue Aug 29, 2006 6:41 am Post subject: WinAPI calls |
|
|
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.
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.
Thanks for the help so far.
Rainer
|
|
Back to top |
|
|
Rainer
Joined: 13 Mar 2006 Posts: 43
|
Posted: Thu Aug 31, 2006 5:05 am Post subject: WinAPI calls |
|
|
Update:
Win API calls work fine now.
Thanks again |
|
Back to top |
|
|
|