Silverfrost Forums

Welcome to our forums

Windows exectuable with WinMain

10 Mar 2010 9:16 #6115

Our existing F77 code base uses the following to create a windows executable:

      integer function WinMain( hInstance,hPrevInstance,lpCmdLine,
     .                          nCmdShow)
	  use msfwina


! For Windows Execution
      integer     hInstance
      integer     hPrevInstance
      integer     lpCmdLine
      integer     nCmdShow


!MS$ ATTRIBUTES STDCALL ,ALIAS : '_WinMain@16' :: WinMain


!!!!!!! CODE !!!!!!!!!!!!!!!!!!!!!!!!



      WinMain = 0
      END

I see inside win32api.ins there is a 'STDCALL WINMAIN 'WinMain' (VAL,VAL,STRING,VAL):INTEGER*4'

How can I convert the above code to use with FTN95 .Net to create a windows executable?

11 Mar 2010 10:44 #6121

There is no WinMain with FTN95.

For standard Fortran input/output you can put WINAPP on a line before the main Fortran program

WINAPP
program myprog
read*, n
print*, n
end

This will give you a Windows IO window for either Win32 or .NET.

If you want to create a GUI for your program then there are three direct ways to do this...

  1. Create a VB .NET form and access a FTN95 assembly (DLL)
  2. Create a C# form and access a FTN95 assembly (DLL)
  3. Use Silverfrost Visual ClearWin with FTN95

As it happens you can also use the Win32 ClearWin+ from .NET but this is not by design and cannot be guaranteed. In this case (image etc) resources have to be coded into a DLL.

11 Mar 2010 5:13 #6128

Paul, Does winapp have some sort of return code built-in similar to WinMain?

I am not trying to build a GUI exe in FTN95 .Net, but rather a program that gets called from another exe such as VB.

So the scenario is that a VB EXE uses the API GetExitCodeProcess to get the return code from API WinMain in the Fortran EXE.

We are currently using WinMain API in Fortran code to pass along the return code and would like to know how to do this in FTN95 .Net

There is an interface to WinMain inside win32api.ins

STDCALL WINMAIN 'WinMain' (VAL,VAL,STRING,VAL):INTEGER*4

If winapp does not provide a return code, could you give a little pointer on how to use WinMain in FTN95 .Net

Thanks, Dan

11 Mar 2010 6:32 #6131

WINAPP is not a function. It sets an attribute on the executable so that it is a Windows executable and not a console executable.

As far as I know, standard Fortran does not provide a way to return an error state to the operating system but FTN95 provides EXIT and EXIT@ for this purpose.

Please login to reply.