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 

Process Handle

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> 64-bit
View previous topic :: View next topic  
Author Message
EKruck



Joined: 09 Jan 2010
Posts: 224
Location: Aalen, Germany

PostPosted: Wed Jan 17, 2018 10:32 am    Post subject: Process Handle Reply with quote

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
View user's profile Send private message Visit poster's website
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Wed Jan 17, 2018 11:02 am    Post subject: Reply with quote

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
View user's profile Send private message
EKruck



Joined: 09 Jan 2010
Posts: 224
Location: Aalen, Germany

PostPosted: Wed Jan 17, 2018 11:10 am    Post subject: Reply with quote

That is already in use, but not thread-save.
Back to top
View user's profile Send private message Visit poster's website
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Wed Jan 17, 2018 11:30 am    Post subject: Reply with quote

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
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Wed Jan 17, 2018 12:58 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
EKruck



Joined: 09 Jan 2010
Posts: 224
Location: Aalen, Germany

PostPosted: Wed Jan 17, 2018 1:40 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


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

PostPosted: Wed Jan 17, 2018 4:22 pm    Post subject: Reply with quote

Erwin

I am not sure that I follow. How would you use this returned handle?
Back to top
View user's profile Send private message AIM Address
EKruck



Joined: 09 Jan 2010
Posts: 224
Location: Aalen, Germany

PostPosted: Wed Jan 17, 2018 4:48 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


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

PostPosted: Wed Jan 17, 2018 6:03 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
EKruck



Joined: 09 Jan 2010
Posts: 224
Location: Aalen, Germany

PostPosted: Wed Jan 17, 2018 6:08 pm    Post subject: Reply with quote

perfect
Back to top
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


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

PostPosted: Wed Jan 24, 2018 11:37 am    Post subject: Reply with quote

Erwin

It seems like my personal messages are not getting through to you.
Are you reading your new messages?
Back to top
View user's profile Send private message AIM Address
EKruck



Joined: 09 Jan 2010
Posts: 224
Location: Aalen, Germany

PostPosted: Wed Jan 24, 2018 1:00 pm    Post subject: Reply with quote

Thanks Paul,

now I received 3 emails and found your message in my inbox.
I will start testing immediately.

Erwin
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> 64-bit 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