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 

Undocumented F_STDCALL behaviour

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



Joined: 22 Nov 2006
Posts: 11

PostPosted: Fri Nov 24, 2006 1:09 am    Post subject: Undocumented F_STDCALL behaviour Reply with quote

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)

4. 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?
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Fri Nov 24, 2006 2:22 am    Post subject: Undocumented F_STDCALL behaviour Reply with quote

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.
Back to top
View user's profile Send private message AIM Address
Vladimir



Joined: 22 Nov 2006
Posts: 11

PostPosted: Fri Nov 24, 2006 4:12 am    Post subject: Undocumented F_STDCALL behaviour Reply with quote

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.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Fri Nov 24, 2006 6:50 am    Post subject: Undocumented F_STDCALL behaviour Reply with quote

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.
Back to top
View user's profile Send private message AIM Address
Vladimir



Joined: 22 Nov 2006
Posts: 11

PostPosted: Tue Nov 28, 2006 2:13 am    Post subject: Undocumented F_STDCALL behaviour Reply with quote

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?
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