Silverfrost Forums

Welcome to our forums

WinAPI calls

27 Aug 2006 11:05 #950

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

27 Aug 2006 11:59 #951

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.

28 Aug 2006 3:57 #952

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 ?

28 Aug 2006 4:33 #953

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

28 Aug 2006 11:26 #955

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

28 Aug 2006 11:42 #956

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

29 Aug 2006 1:52 #961

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

29 Aug 2006 5:35 #963

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

29 Aug 2006 5:41 #964

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

31 Aug 2006 4:05 #973

Update:

Win API calls work fine now. 😄

Thanks again

Please login to reply.