Question on Process.Start

D

Dom

I have a program that starts a second program with Process p =
Process.Start(...). I expect p.Handle to hold the handle of the
started process, which I then use in a series of SendMessage Calls,
eg, SendMessage (p.Handle, 0x800+1, 0, 0).

However, p.Handle is not the handle of the started process. I know
this because, when the new process starts, it writes its own handle in
the caption of the window, and it does not match p.Handle. Also, if I
jigger the first program in the debugger, and use what I know to be
the handle in the SendMessage calls, it works fine.

What is going wrong?
 
P

Peter Duniho

Dom said:
I have a program that starts a second program with Process p =
Process.Start(...). I expect p.Handle to hold the handle of the
started process, which I then use in a series of SendMessage Calls,
eg, SendMessage (p.Handle, 0x800+1, 0, 0).

However, p.Handle is not the handle of the started process. I know
this because, when the new process starts, it writes its own handle in
the caption of the window, and it does not match p.Handle. Also, if I
jigger the first program in the debugger, and use what I know to be
the handle in the SendMessage calls, it works fine.

What is going wrong?

What handle are you expecting? The Process.Handle property is the Win32
HANDLE representing the Win32 process object. To send a message, you
need a _window_ handle, that is a Win32 HWND value.

It may be that all you need to do is use the Process.MainWindowHandle
property instead.

Pete
 
D

Dom

What handle are you expecting?  The Process.Handle property is the Win32
HANDLE representing the Win32 process object.  To send a message, you
need a _window_ handle, that is a Win32 HWND value.

It may be that all you need to do is use the Process.MainWindowHandle
property instead.

Pete

Thanks. That's exactly what I needed. I was a little suspicious
because I knew that in most objects, like controls, the "Handle"
property returns the handle of the control itself. I just couldn't
find any other property that looked like what I needed.
 

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