replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Starting a new process in a minimised window
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 

Starting a new process in a minimised window

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



Joined: 21 Jun 2006
Posts: 404
Location: N�rnberg, Germany

PostPosted: Wed Sep 30, 2009 10:35 am    Post subject: Starting a new process in a minimised window Reply with quote

For some applications it is required to start an external executable from our Fortran application. In this particular case a new window is opened each time the program is called. This makes it impossible to continue working on the PC. We could not figure out a way to avoid this in FTN95.

I found a very useful C++ subroutine from a colleague which compile and execute wihtout any problems using the SCC compiler. However, when I try to use it (in a mix language project), the executable to be started does not open Sad The Fortran code:
Code:
program start_process
  implicit none
  integer :: start_process@,i

  C_EXTERNAL STARTAPPNOWINDOW 'StartAppNoWindow'(REF) : INTEGER

  i = StartAppNoWindow("notepad.exe")
  write(*,'(I2)') i
  i = start_process@('notepad.exe','')
  write(*,'(I2)') i

end program start_process

and the C++ code:
Code:
#include <windows.h>

extern "C" int StartAppNoWindow(char* szPathApplication)
{
  /* Strukturen erstellen und initialisieren */
  PROCESS_INFORMATION pi = {0};
 
 
  STARTUPINFOA         si = {0};    //StartupInfo zum Parametrieren des Starts
  si.cb           = sizeof(STARTUPINFO);  //Strukturgroesse definieren
  si.dwFlags      = STARTF_USESHOWWINDOW; //Flag wShowWindow benutzen
 
  si.wShowWindow  = SW_MINIMIZE | SW_HIDE;//Fenster nicht anzeigen, minimiert
 

  /* Prozess starten */
  if (CreateProcessA(NULL,szPathApplication,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi))
  {
    CloseHandle(pi.hThread); //Thread-Handle wird nicht mehr benoetigt
    WaitForSingleObject(pi.hProcess,INFINITE); //Warten bis Prozess fertig ist!
    CloseHandle(pi.hProcess); //Prozess Handle wird nicht mehr benoetigt
  }
  else
    return -1;
  return 0;
};

Some advise wil be most welcome Very Happy The C++ code can be tested by just adding a very simple main().
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Wed Sep 30, 2009 11:47 am    Post subject: Reply with quote

You might find that the Microsoft WinExec solves the problem. It is available in windows.ins I think. It also uses SW_HIDE etc.

I don't know what you mean by "does not open the Fortran" but your C function may not return until you close Notepad. If this is the problem then the C code needs to be modified to allow the function to return immediately.
Back to top
View user's profile Send private message AIM Address
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: N�rnberg, Germany

PostPosted: Wed Sep 30, 2009 6:40 pm    Post subject: Reply with quote

I think that I should reformulate the problem: The procedure calls the external program, wait for it and continue when done. However, the result of the C++ function is different when called from the Fortran project compared to when the C++ is used as a standalone.

The following C++ program illustrates what should happen (in this example the user must close the notepad application). In the actual application the external program does some calculations (which takes a few minutes). After the calculations are done the Fortran program reads the output file, collect the desired data and continues to call the external program with new parameters.
Code:
int main()
{
  int i,x;
  for ( x = 0; x < 10; x++ ){
    printf( "%d\n", x );
    i = StartAppNoWindow("notepad.exe"); /*user needs to close potepad*/
                             /*"real" application close auto.*/
    printf( "%d\n", i );
  }
}
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Thu Oct 01, 2009 8:17 am    Post subject: Reply with quote

I cannot see any significant difference unless it is that you ought to pass the string as an INSTRING rather than a REF.

If furhter work is necessary then I would compile both the C and the Fortran with /DEBUG and see if stepping through the code produces any ideas.
Back to top
View user's profile Send private message AIM Address
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: N�rnberg, Germany

PostPosted: Tue Oct 06, 2009 12:34 pm    Post subject: Reply with quote

I tried several combinations of the code. On my machine the C++ project and the FTN95 project have different results. We could not resolve this issue.

At the moment we (anyway) work the external software supplier to change the code to include new options. However, there are still other applications where we would like this to work. Thus, we will investigate this issue at a later stage.
Back to top
View user's profile Send private message
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: N�rnberg, Germany

PostPosted: Wed Nov 11, 2009 7:33 am    Post subject: Reply with quote

Hi Paul,

as you know, one can use the compiler from the command line or with Plato (my favourite). Anyway, from the command line the messages are displayed in the DOS box. When one uses Plato the messegas are displayed in a small output window in the lower part of the Plato IDE. How is this done?

We have several applications where I would like to get this "Plato" result. Even if the program is the same many users think that a DOS box is old and outdated stuff. One can say: keep the customer happy and present everthing in a window Smile
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Wed Nov 11, 2009 9:24 am    Post subject: Reply with quote

It may be sufficient for you to put WINAPP at the beginning of your main program.

Plato causes the DOS output to be sent to a results file (which you can probably see in the relevant project folder) and then reads this data into the Output window.
Back to top
View user's profile Send private message AIM Address
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: N�rnberg, Germany

PostPosted: Wed Nov 11, 2009 9:37 am    Post subject: Reply with quote

Thanks Paul. I always thought that the DOS box output was "directly" redirectet to the Plato output window. My C++ colleague implement this with some redirection as he calls it, and this is what I tried as well. The file method as Plato does it, seems to be much easier or at least something that I can do as well Very Happy
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