View previous topic :: View next topic |
Author |
Message |
EKruck
Joined: 09 Jan 2010 Posts: 224 Location: Aalen, Germany
|
Posted: Wed Jan 17, 2018 10:32 am Post subject: Process Handle |
|
|
How can I get the handle of a process that I started with START_PROCESS_AND_WAIT@ in a new thread?
Code: | !-----------------------------------------------------------------------------------
INTEGER FUNCTION ModWait (ProgramName, ParamString, iSilent)
! Start program in separate thread which waits for completion
USE ProcNameS
IMPLICIT NONE
CHARACTER*(*), INTENT(IN) :: ProgramName, ParamString
INTEGER, INTENT(IN) :: iSilent
INTEGER :: iThID, NULL4b
INTEGER :: iThread
INTEGER, EXTERNAL :: WaitForBingo
! STDCALL CreateThread 'CreateThread' (REF,VAL,REF,REF,VAL,REF) : INTEGER*4
! Original modified to call with NULL pointer:
STDCALL CreateThread 'CreateThread' (VAL,VAL,REF,REF,VAL,REF) : INTEGER*4
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NULL4b = 0
iThID = 0
:
:
iThread = CreateThread (NULL4b, NULL4b, WaitForBingo, iSilent, NULL4b, iThID)
:
:
RETURN
END FUNCTION ModWait
!-----------------------------------------------------------------------------------
INTEGER FUNCTION WaitForBingo (iSilent)
! Start program and wait for completion
USE ProcNameS
IMPLICIT NONE
INCLUDE <clearwin.ins>
INTEGER, INTENT(IN) :: iSilent
CHARACTER CTX*256, cProgName*128, cRunString*128
INTEGER iStat
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
:
:
iStat = START_PROCESS_AND_WAIT@ (cProgName, cRunString, -1)
:
:
WaitForBingo = 1
RETURN
END FUNCTION WaitForBingo
!-----------------------------------------------------------------------------------
|
|
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Wed Jan 17, 2018 11:02 am Post subject: |
|
|
If your spawned program cProgName was written by you, you can give it a class name through Clearwin+, and send messages to it. Inside cProgName you would need something like:
IA=WINIO@('%nc[cProgClassName]%rm&',MESSAGE_REPLY_FN)
in which MESSAGE_REPLY_FN is an integer function that responds to Windows messages within program cProgName. Messages could be sent from the parent program, or indeed, sent from the spawned program back to the parent.
You will also need to use CALL REPLY_TO_TEXT_MESSAGE@ and SEND_TEXT_MESSAGE@ (described in FTN95.CHM) and if communication back to the parent is required, it will also need its own class name and message handler.
If you didn't write cProgName, then you will need a Windows utility to discover its class name.
A way of doing this and finding the program handle is given here:
https://stackoverflow.com/questions/4727135/how-to-find-out-class-name-tiled-of-program-in-c |
|
Back to top |
|
|
EKruck
Joined: 09 Jan 2010 Posts: 224 Location: Aalen, Germany
|
Posted: Wed Jan 17, 2018 11:10 am Post subject: |
|
|
That is already in use, but not thread-save. |
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Wed Jan 17, 2018 11:30 am Post subject: |
|
|
Interesting. Clearly, the software side of things lags behind the hardware, as the latter is very capable of handling threads, but Windows may not be. It's only to be expected therefore that other software lags even further behind.
A bit like 64-bit ... |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7928 Location: Salford, UK
|
Posted: Wed Jan 17, 2018 12:58 pm Post subject: |
|
|
The Silverfrost libraries do not provide a way to get this handle.
At the moment I can't think of an alternative approach other than to write your own call to CreatProcess. |
|
Back to top |
|
|
EKruck
Joined: 09 Jan 2010 Posts: 224 Location: Aalen, Germany
|
Posted: Wed Jan 17, 2018 1:40 pm Post subject: |
|
|
Paul,
my point is to get a return code within "WaitForBingo" (one integer or string) from the program started with START_PROCESS_AND_WAIT@.
That program is written in Intel Fortran. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7928 Location: Salford, UK
|
Posted: Wed Jan 17, 2018 4:22 pm Post subject: |
|
|
Erwin
I am not sure that I follow. How would you use this returned handle? |
|
Back to top |
|
|
EKruck
Joined: 09 Jan 2010 Posts: 224 Location: Aalen, Germany
|
Posted: Wed Jan 17, 2018 4:48 pm Post subject: |
|
|
Paul,
I have a cycle to start two programs in sequence several times, creating a new thread for every start. This cause problems in 64 bit version. Therefore I want to do this cycle within one thread. To decide what's to do next, I need the return code from the first program.
The first program can provide the return code via Code: | VOID WINAPI ExitProcess(
__in UINT uExitCode
);
|
The cycle in the tread could get the return code using Code: | BOOL WINAPI GetExitCodeProcess(
__in HANDLE hProcess,
__out LPDWORD lpExitCode
);
| This needs the process handle. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7928 Location: Salford, UK
|
Posted: Wed Jan 17, 2018 6:03 pm Post subject: |
|
|
Erwin
I could provide a routine that takes an address from you and plants the process handle into that address.
I notice that you are using INTEGER*4 for the return from CreateThread and that should be INTEGER*8 for 64 bits. |
|
Back to top |
|
|
EKruck
Joined: 09 Jan 2010 Posts: 224 Location: Aalen, Germany
|
Posted: Wed Jan 17, 2018 6:08 pm Post subject: |
|
|
perfect |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7928 Location: Salford, UK
|
Posted: Wed Jan 24, 2018 11:37 am Post subject: |
|
|
Erwin
It seems like my personal messages are not getting through to you.
Are you reading your new messages? |
|
Back to top |
|
|
EKruck
Joined: 09 Jan 2010 Posts: 224 Location: Aalen, Germany
|
Posted: Wed Jan 24, 2018 1:00 pm Post subject: |
|
|
Thanks Paul,
now I received 3 emails and found your message in my inbox.
I will start testing immediately.
Erwin |
|
Back to top |
|
|
|