Discussion:
How to pass an handle to a running application?
(too old to reply)
Denis @ TheOffice
2006-08-17 22:24:46 UTC
Permalink
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
Norman Bullen
2006-08-18 01:19:28 UTC
Permalink
Post by Denis @ TheOffice
Hi,
I am confronted to a situation here.
I need to spawn an application and then pass it a port handle later.
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
--
--
To reply, change domain to an adult feline.
Denis @ TheOffice
2006-08-18 17:47:43 UTC
Permalink
Thanks that works great.

Denis
Post by Norman Bullen
Post by Denis @ TheOffice
Hi,
I am confronted to a situation here.
I need to spawn an application and then pass it a port handle later.
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
--
--
To reply, change domain to an adult feline.
Continue reading on narkive:
Loading...