How to pass an handle to a running application?

  • Thread starter Thread starter Denis @ TheOffice
  • Start date Start date
D

Denis @ TheOffice

Hi,

I am confronted to a situation here.

I need to spawn an application and then pass it a port handle later.
I tried by using the usual :
SetHandleInformation(me_Socket, // handle to object
HANDLE_FLAG_INHERIT, // flags to change
HANDLE_FLAG_INHERIT) // new values for flags

But once on the other application it is not working.
Is there a function that I have to call on the other application?

Thanks
Denis Co
 
Denis said:
Hi,

I am confronted to a situation here.

I need to spawn an application and then pass it a port handle later.
I tried by using the usual :
SetHandleInformation(me_Socket, // handle to object
HANDLE_FLAG_INHERIT, // flags to change
HANDLE_FLAG_INHERIT) // new values for flags

But once on the other application it is not working.
Is there a function that I have to call on the other application?

Thanks
Denis Co
If you're calling SetHandleInformation() _after_ you "spawn" the other
other application, the other application process has already been
started and did not inherit the handle if the handle was not inheritable
when the spawn happened.

To add a new handle to an existing process you need to call
DuplicateHandle(). This adds the handle to the existing process and
gives the calling application its value. Then you have to send that
value to the other application so that it can use the value. (Perhaps
you might use SendMessage() for this.)

Norm
 
Thanks that works great.

Denis

Norman Bullen said:
If you're calling SetHandleInformation() _after_ you "spawn" the other
other application, the other application process has already been
started and did not inherit the handle if the handle was not inheritable
when the spawn happened.

To add a new handle to an existing process you need to call
DuplicateHandle(). This adds the handle to the existing process and
gives the calling application its value. Then you have to send that
value to the other application so that it can use the value. (Perhaps
you might use SendMessage() for this.)

Norm
 
Back
Top