Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29233 Discussions

Window programming with ISO_C_BINDING

Robert_van_Amerongen
New Contributor III
621 Views
Hi,

With Fortran 2003 we have the possibility to make a window program without any compiler dependent issues.Only theISO_C_BINDING module and the defs of named constants, structures and interfaces are needed. I tried, just as an example, to create a program with a simple window but without succes.

Enclosed is a zip-file with the source, a screendump and a bat-file. The program fails in the message loop. So either there, and/or in the window procedure something is wrong. Without any write statements the loop terminated immediately; with a single write statement a severe error occured.I think I did I do not have anerror in the source (but I cannot guarantee). The same program with Intel's IFWIN works fine. I made it with an 32 bit machine; windows XP sp3.

Around the issue of compiler-independent Window programmingis some fog. Nowhere in the forum I did found information hereabout, not to mention I found a working example.

Can someone shed some light on this issue?

Thanks!
Robert
0 Kudos
4 Replies
Steven_L_Intel1
Employee
621 Views
You cannot use BIND(C) to declare Win32 API routines on IA-32 because they use the STDCALL calling mechanism, and at least in Intel Fortran, that is not compatible with BIND(C). You willl need to continue to use extensions or vendor-supplied modules.

A hint: if you feel you need to add "@n" as a suffix in an alias, you're probably doing something wrong.
0 Kudos
Robert_van_Amerongen
New Contributor III
621 Views
Steve,

thanks for the reply. In the meantime I have looked elsewhere and it seems that this combination (BIND(C) and Window api) is nowhere handled without some form of compiler-dependent intervention. At least for 32 bit machines; in 64 bit machines every problem is gone!

Remarkable is that a simple "MessageBox" programm works fine; in the program that I send it went oke with window classregistering, window creation and window show.But failurestarted once the loop is entered.

If I leave "@n" the compiler, or better, the linker complains that it can not file the function ...

Maybe somewhat outside of this forum: should it, retrospectively,have been better ifthe Fortran standard had something like

FUNCTION xx( , , ) BIND(C, bind_type='STDCALL' , .. )

in the part on C-interoperability?

Robert
0 Kudos
Steven_L_Intel1
Employee
621 Views
The reason it sometimes seems to work is that making the call corrupts the stack - your program may or may not notice this.

The natural way to express this would be BIND(STDCALL), and we are free to do that, but it too is an extension and we decided that, for now, if you are going to use one extension, you may as well use the one we already have.

My personal opinion is that we should allow !DEC$ ATTRIBUTES STDCALL with BIND(C), and maybe someday we will if I can convince enough people.
0 Kudos
Robert_van_Amerongen
New Contributor III
621 Views
Thanks Steve,

the use of !DEC$ in combination with BIND(C) would be very welcomed! Hope to see that soon.

Best regards,
Robert
0 Kudos
Reply