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 😦 The Fortran 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: #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 😄 The C++ code can be tested by just adding a very simple main().