Win32 API and gfortran
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.fortran Profile…
 Up
Win32 API and gfortran         


Author: James Van Buskirk
Date: Nov 9, 2007 20:35

There seems to be a problem with Win32 API and 32-bit gfortran.

C:\gfortran\test>type hello.f90
! hello.f90

module mykinds
implicit none
integer, parameter :: ik4 = selected_int_kind(9)
integer, parameter :: ik8 = selected_int_kind(18)
end module mykinds

module Win32
use mykinds
implicit none
private
Show full article (3.46Kb)
39 Comments
Re: Win32 API and gfortran         


Author: Steve Lionel
Date: Nov 10, 2007 05:24

On Nov 9, 11:35 pm, "James Van Buskirk" comcast.net> wrote:
> The issue is that the name of a Win32 API function can't be converted
> into the name ld.exe likes,

The problem is bigger than that. All Win32 API routines on 32-bit
Windows use the STDCALL calling mechanism, which has a naming
convention adding the @n at the end of the name to signify the number
of bytes to pop off the stack on return. gfortran, like most Fortran
compilers on Windows (except for CVF and MSFPS) default to the C
convention. If you call a STDCALL routine but the compiler thinks it
is a C routine, the stack gets popped twice and you corrupt the
stack. Things go downhill from there.

You will have to see what gfortran offers for specifying that an
external routine is STDCALL. Whatever it is, it's going to be an
extension and probably not part of BIND. In Intel Fortran, for
example, one uses !DEC$ ATTRIBUTES STDCALL :: routinename

Never, ever attempt to paper over the naming convention difference by
simply adding the @n suffix - the errors this will cause can be
mystifying.

Steve
no comments
Re: Win32 API and gfortran         


Author: alexzenk
Date: Nov 10, 2007 09:18

On Nov 10, 7:35 am, "James Van Buskirk" comcast.net> wrote:
> There seems to be a problem with Win32 API and 32-bit gfortran.
>

Call Win32 API from gfortran is possible, but for this you should
write for each used Win32 API functions interface subroutine on C.
In consequence of significant difficulties of the mixed programming
for Windows, such approach impractical. Writing of the whole program
on C will probably more simply.
Here is example such working program

---------------File myfirst1.f95------------------------------------
SUBROUTINE FortranSub()
integer i, j
CHARACTER(LEN = 15):: Text
CHARACTER(LEN = 15) :: Caption
i = 0
j = 0
Text = "Hello All"//CHAR...
Show full article (1.84Kb)
no comments
Re: Win32 API and gfortran         


Author: Gary Scott
Date: Nov 10, 2007 09:23

alexzenk wrote:
> On Nov 10, 7:35 am, "James Van Buskirk" comcast.net> wrote:
>
>>There seems to be a problem with Win32 API and 32-bit gfortran.
>>
>
>
> Call Win32 API from gfortran is possible, but for this you should
> write for each used Win32 API functions interface subroutine on C.
> In consequence of significant difficulties of the mixed programming
> for Windows, such approach impractical. Writing of the whole program
> on C will probably more simply.

Not an acceptable solution. A compiler targeted at a specific OS MUST
be able to directly call OS APIs. I will never ever use a compiler
which does not support this.
> Here is example such working program
>
>
> ---------------File myfirst1.f95------------------------------------
> SUBROUTINE FortranSub()
> integer i, j
> CHARACTER(LEN = 15):: Text
> CHARACTER(LEN...
Show full article (2.50Kb)
no comments
Re: Win32 API and gfortran         


Author: e p chandler
Date: Nov 10, 2007 09:39

On Nov 9, 11:35 pm, "James Van Buskirk" comcast.net> wrote:
> There seems to be a problem with Win32 API and 32-bit gfortran.
>
> C:\gfortran\test>type hello.f90
> ! hello.f90
>
> module mykinds
> implicit none
> integer, parameter :: ik4 = selected_int_kind(9)
> integer, parameter :: ik8 = selected_int_kind(18)
> end module mykinds
>
> module Win32
> use mykinds
> implicit none
> private
>
> public GetStdHandle
> interface
> function GetStdHandle(nStdHandle) bind(C,name='GetStdHandle') ...
Show full article (4.58Kb)
no comments
Re: Win32 API and gfortran         


Author: James Van Buskirk
Date: Nov 10, 2007 13:00

"Steve Lionel" intel.com> wrote in message
news:1194701088.535461.293950@22g2000hsm.googlegroups.com...
> Never, ever attempt to paper over the naming convention difference by
> simply adding the @n suffix - the errors this will cause can be
> mystifying.
--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end
no comments
Re: Win32 API and gfortran         


Author: James Van Buskirk
Date: Nov 10, 2007 14:48

"e p chandler" juno.com> wrote in message
news:1194716385.730596.279790@o80g2000hse.googlegroups.com...
> One of your problems is that WriteConsoleA seems not to be there at
> all.
> Replacing WriteConsoleA with WriteFile in your source code and
> compiling with g95 gives

Well, I find the string 'WriteConsoleA' 5 times each in:

C:\g95\lib\libkernel32.a
C:\gfortran\lib\libkernel32.a
C:\gfortran\win64\x86_64-pc-mingw32\lib\libkernel32.a

so I don't think that's the problem. Doing the g95 thing with @n:

C:\g95\test>type hello.f90
! hello.f90

module mykinds
implicit none
integer, parameter :: ik4 = selected_int_kind(9)
integer, parameter :: ik8 = selected_int_kind(18)
end module mykinds
Show full article (2.97Kb)
no comments
Re: Win32 API and gfortran         


Author: Steve Lionel
Date: Nov 10, 2007 18:20

On Nov 10, 4:00 pm, "James Van Buskirk" comcast.net> wrote:
> "Steve Lionel" intel.com> wrote in message
>
> news:1194701088.535461.293950@22g2000hsm.googlegroups.com...
>
>> Never, ever attempt to paper over the naming convention difference by
>> simply adding the @n suffix - the errors this will cause can be
>> mystifying.

No, as a matter of fact. The post you link to relates to incorrect
name decoration for a C-convention routine, where the compiler ought
to be supplying a leading underscore but doesn't. There it's just the
name that's wrong. If you want to read an Intel forum thread that IS
relevant, see http://softwarecommunity.intel.com/isn/Community/en-US/forums/thread/30243178.as...
Show full article (4.13Kb)
no comments
Re: Win32 API and gfortran         


Author: e p chandler
Date: Nov 10, 2007 18:53

On Nov 10, 5:48 pm, "James Van Buskirk" comcast.net> wrote:
> "e p chandler" juno.com> wrote in messagenews:1194716385.730596.279790@o80g2000hse.googlegroups.com...
>
>> One of your problems is that WriteConsoleA seems not to be there at
>> all.
>> Replacing WriteConsoleA with WriteFile in your source code and
>> compiling with g95 gives
>
> Well, I find the string 'WriteConsoleA' 5 times each in:
>
> C:\g95\lib\libkernel32.a
> C:\gfortran\lib\libkernel32.a
> C:\gfortran\win64\x86_64-pc-mingw32\lib\libkernel32.a
>
> so I don't think that's the problem. Doing the g95 thing with @n:
>
> C:\g95\test>type hello.f90
> ! hello.f90
>
> module mykinds ...
Show full article (4.51Kb)
no comments
Re: Win32 API and gfortran         


Author: James Van Buskirk
Date: Nov 11, 2007 01:22

"Steve Lionel" intel.com> wrote in message
news:1194747615.729298.201610@v2g2000hsf.googlegroups.com...
> You want to call some Win32 API routines from Fortran. These are
> STDCALL routines and their global symbols have the @n suffix.
> Compilers which support STDCALL will automatically add the proper @n...
Show full article (2.65Kb)
no comments
1 2 3 4