> 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
jan.loucka@gmail.com - 25 Jun 2007 05:23 GMT
On Jun 25, 11:25 am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
> > Hi,
> > Is there any way in .NET how to capture WIN API messages that belong
[quoted text clipped - 21 lines]
>
> 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();
}
Jayme.Pechan - 25 Jun 2007 07:28 GMT
I have had a problem with a 3rd party out-of-process com object that has a
tendency to crash. Of course, it causes problems when this exe crashes, so
I had to watch to determine when the exe exited. All I did was spin up a
thread that used something simliar to the following:
public void ThreadFunc()
{
Process[] processList =
System.Diagnostics.Process.GetProcessesByName("PROCESS.EXE");
if (processList.length > 0)
{
processList[0].WaitForExit();
// The process has exited
}
else
{
// could not find the process
}
}
Not sure if this is what you are looking for but hope this helps.
Jayme
> On Jun 25, 11:25 am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
> wrote:
[quoted text clipped - 52 lines]
> return new IntPtr();
> }