winapi - can I call windows api functions (64 bit) when compiling with gcc (gfortran)? -
i'm attempting compile subroutine sendmsg.f90 compiled lf90 32 bit gcc 64 bit. purpose link other 64 bit subroutines compiled gcc.
subroutine updatedisplay(winhand,ntps,qcancel,niter) use win32mod implicit none integer winhand, ntps, messnum, niter, qcancel ! sendmessagea windows function ! winhand = handle of window (from isdev code) ! messnum = message number (assigned isdev) ! ntps = number of year iteration on (wparam) ! dum = 0 (lparam) messnum = 1114 qcancel = sendmessagea(carg(winhand),carg(messnum),carg(ntps), carg(niter)) end subroutine
we have lahey fortran 7.5 has lf90 compiler , gcc (which uses gfortran) , called lgf (which suppose uses gcc, right?).
i'm new windows programming (and fortran). can code compiled gcc call windows api? should use iso_c_binding?
should or should try link .obj file created lf90 .o files created gcc?
thanks help!
update: i've tried calling windows api with:
module snd_c interface integer(c_long) function sendmessage & (winhand,messnum,ntps, niter) & bind(c,name='sendmessage') use iso_c_binding implicit none integer(c_long), value :: winhand integer(c_long), value :: messnum integer(c_long), value :: ntps integer(c_long), value :: niter end function sendmessage end interface end module snd_c subroutine updatedisplay(winhand,ntps,qcancel,niter) use iso_c_binding, only: c_long use snd_c implicit none integer(c_long) winhand, ntps, messnum, niter, qcancel ! sendmessagea windows function ! winhand = handle of window (from isdev code) ! messnum = message number (assigned isdev) ! ntps = number of year iteration on (wparam) ! dum = 0 (lparam) !gcc$ attributes dllexport :: updatedisplay messnum = 1114 qcancel = sendmessage(winhand,messnum,ntps, niter) end subroutine
but when try compile "gcc -m64 sendmsg.f90" error:
c:\users\stephaniej\documents\lahey-fujitsu fortran>gcc -m64 sendmsg.f90 c:/progra~2/lahey-~1/v7.5/gcc-gf~1/bin/../lib/gcc/x86_64-w64-mingw32/4.7.4/../.. /../../x86_64-w64-mingw32/lib/../lib/crt2.o: in function `__tmaincrtstartup': c:\gccbuild\mingw-crt\build32-64\mingw-w64-crt/../../mingwsvn/mingw-w64-crt/crt/ crtexe.c:323: undefined reference `__laheypause' c:\users\stepha~2\appdata\local\temp\ccwjjo5b.o:sendmsg.f90:(.text+0x3e): undefi ned reference `sendmessage' c:/progra~2/lahey-~1/v7.5/gcc-gf~1/bin/../lib/gcc/x86_64-w64-mingw32/4.7.4/../.. /../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): in function `main': c:\gccbuild\mingw-crt\build32-64\mingw-w64-crt/../../mingwsvn/mingw-w64-crt/crt/ crt0_c.c:18: undefined reference `winmain' collect2.exe: error: ld returned 1 exit status
does approach make sense? why reference sendmessage undefined?
probably easiest way call api through c wrapper function might this:
#include <windows.h> void updatedisplay_( hwnd *winhand, wparam *ntps, lresult *qcancel, lparam *niter) { // integer ntps, messnum, niter, qcancel /* ! winhand = handle of window (from isdev code) ! messnum = message number (assigned isdev) ! ntps = number of year iteration on (wparam) ! dum = 0 (lparam) */ uint messnum = 1114; *qcancel = sendmessage(*winhand,messnum,*ntps,*niter); }
the lower case , trailing underscore match fortran default function naming. if suppose file name updatedisplay.c, compile command:
gcc -c updatedisplay.c
on fortran side, instead of sending 0 window handle, use c_null_ptr iso_c_binding instead. can link object file updatedisplay.o fortran code called fortran function of same name, , should work.
to rid of laheypause thing, link file lgfpstub.o proper lib directory either x86_64-w64-mingw32\lib x86_64 or x86_64-w64-mingw32\lib32 x86.
hope helps!
Comments
Post a Comment