On Jun 25, 11:25 am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
[quoted text, click to view] wrote:
> On Sun, 24 Jun 2007 20:02:10 -0700, <jan.lou...@gmail.com> wrote:
> > Hi,
> > Is there any way in .NET how to capture WIN API messages that belong
> > to different application?
>
> You can always use p/invoke. I'm not aware of a general-purpose mechanism
> that allows you to hook window messages the way you can with the native
> Win32 API. That said...
>
> > We have a Windows Form app written in .NET
> > 2.0 and from our application we're running another application called
> > MapInfo using Interop. We need to be able to somehow figure out when
> > the user exits the MapInfo applicaiton so we can close our own app as
> > well.
>
> If you are using the Process class to start the other application, you
> should be able to use that Process instance to track the activity of the
> other application and detect when it's been closed. You can subscribe to
> the Process.Exited event to receive notification of the application
> exiting.
>
> > I was looking on SetWindowsHookEx function but couldn't make it work.
>
> What did you try? What about it didn't work?
>
> Pete
I'm running the new application by creating a new instance
this.mi = new MapInfo.MapInfoApplicationClass();
my project has a reference to a MapInfo dll - and when I create this
instance it starts the MapInfo app. It's separate process and
therefore I'm expecting it's running on separate thred - on the other
side - my app halts until the loading of MapInfo finishes so maybe
they're both running on the same thread?
I can get the MapInfo process using (I have a pointer - handler to
it):
Int32 pid = win32.GetWindowProcessID(this.miWin.ToInt32());
mapInfoProcess = Process.GetProcessById(pid);
but when I subscribe to Exited event it never gets fired?
I also tried to "subscribe" to the messages coming from MapInfo so I
can catch WM_CLOSE message but I can't get it working.
My code looks like this:
public delegate IntPtr MessageProc(int code, IntPtr wParam, IntPtr
lParam);
IntPtr hookHandle = SetWindowsHookEx(WH_GETMESSAGE,
hookFunction,IntPtr.Zero, AppDomain.GetCurrentThreadId());
public IntPtr NameOfYourFunction(int code, IntPtr wParam, IntPtr
lParam)
{
Message test =
(Message)Marshal.PtrToStructure(lParam,typeof(Message));
return new IntPtr();
}