Silverfrost Forums

Welcome to our forums

Undocumented F_STDCALL behaviour

24 Nov 2006 12:09 #1318

Dear Paul,

I’ve downloaded FTN95 compiler (Personal Edn) v. 4.9 and upgraded it to 4.91. Then I’ve tried to make a simple program with GUI. The need to use a lot of crazy keywords like %ac, %fh, %th, %uw, etc. with ClearWin+ library really frightened me, so I decided to write a program in pure Win32 API.

Well, starting points were as follows:

  1. One need to declare STDCALL integer function WinMain as a main body of the program.
  2. It is worth to use alias ‘WinMain’ to preserve the letters’ case.
  3. As stated in FTN help file, F_STDCALL declaration should be used in such a case. An example of this declaration taken directly from help file:

F_STDCALL INTEGER FUNCTION LIBMAIN(hInst,ul,lpR)

  1. One need to use module with declarations of all used Win32 API functions and equates. According to FTN95 help, it could be made this way:

Fortran 77 routines that use ClearWin+ and/or the Windows API should include the line INCLUDE <windows.ins>

I think that this is valid for Fortran 90/95 too.

That was a point, and I’ve started. Actually I’ve translated (partially) a BCX BASIC program that shows a window with gradient background colour. After correcting syntax errors, I’ve came to a dead end due to strange compiler behaviour. The main trouble was that I was not able to declare STDCALL function WinMain:

F_STDCALL INTEGER FUNCTION WinMain 'WinMain' (HINSTANCE,HPREVINST,LPCMDLINE,NCMDSH)

Compiler reported an error:

*** 'W' found after FUNCTION where a comma was expected

It was unexpected as the declaration used was definitely in accordance with the example. But if compiler wants a comma, you must provide it! Next attempt was:

F_STDCALL INTEGER FUNCTION, WinMain 'WinMain' (HINSTANCE,HPREVINST,LPCMDLINE,NCMDSH)

Compiler reported:

''' found after WINMAIN where a comma was expected

It puzzled me a bit, but then I made the next attempt:

F_STDCALL INTEGER FUNCTION, WinMain, 'WinMain' (HINSTANCE,HPREVINST,LPCMDLINE,NCMDSH)

Compiler reported:

''' found where a Variable names name was expected

Yes, with duplication in compiler message. But the point is that I was unable to finish properly the declaration of my alias, and I couldn’t find any workaround. So I gave up.

Well, how could I declare F_STDCALL function?

24 Nov 2006 1:22 #1319

Vladimir

You cannot use a WinMain function as your entry point. Just write a Fortran main PROGRAM in the ordinary way then you can access Windows API functions from there onwards.

If you are creating a DLL you should avoid providing a LIBMAIN unless you have global data that you need to initialise. SLINK will provide a default LIBMAIN for you.

24 Nov 2006 3:12 #1320

Thanks for the answer!

I will try this. A string with LIBMAIN in my post was used only as example of STDCALL function declaration taken from the help file, I had no intention to use it in my program. Actually I want to say that compiler is not satisfied with my F_STDCALL function declared just in the same way as in this example.

24 Nov 2006 5:50 #1321

Vladimir

Normally you only need F_STDCALL you are exporting to a DLL for use in another environment (i.e. not FTN95). FTN95 does not allow you to supply an alias in a Win32 program. It is not needed since the call can be made to be upper-case only. However, I think the linker (SLINK) allows you to provide an alias if you prefer to have one.

28 Nov 2006 1:13 #1328

It's me again!

Well, if I don’t use WinMain function, so the system couldn’t return HINSTANCE (a handle to the instance of the current module), which is needed to register a window class, to create a window, or to do some other operations. So I couldn’t move any further. Does it mean that Salford FTN95 prohibits pure Win95 API programming?

Please login to reply.