How to pass an handle to a running application?

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
 
N

Norman Bullen

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
 
D

Denis @ TheOffice

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top