HighTechTalks DotNet Forums  

Process Exit

Dotnet Framework (Interop) microsoft.public.dotnet.framework.interop


Discuss Process Exit in the Dotnet Framework (Interop) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
jan.loucka@gmail.com
 
Posts: n/a

Default Process Exit - 06-24-2007 , 11:02 PM






Hi,
Is there any way in .NET how to capture WIN API messages that belong
to different application? 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.
I was looking on SetWindowsHookEx function but couldn't make it work.
Thanks for any help
Jan


Reply With Quote
  #2  
Old   
Peter Duniho
 
Posts: n/a

Default Re: Process Exit - 06-24-2007 , 11:25 PM






On Sun, 24 Jun 2007 20:02:10 -0700, <jan.loucka (AT) gmail (DOT) com> wrote:

Quote:
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...

Quote:
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.

Quote:
I was looking on SetWindowsHookEx function but couldn't make it work.
What did you try? What about it didn't work?

Pete


Reply With Quote
  #3  
Old   
jan.loucka@gmail.com
 
Posts: n/a

Default Re: Process Exit - 06-25-2007 , 12:23 AM



On Jun 25, 11:25 am, "Peter Duniho" <NpOeStPe... (AT) nnowslpianmk (DOT) com>
wrote:
Quote:
On Sun, 24 Jun 2007 20:02:10 -0700, <jan.lou... (AT) gmail (DOT) 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(Mess age));
return new IntPtr();
}




Reply With Quote
  #4  
Old   
Jayme.Pechan
 
Posts: n/a

Default Re: Process Exit - 06-25-2007 , 02:28 AM



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("PRO CESS.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


<jan.loucka (AT) gmail (DOT) com> wrote

Quote:
On Jun 25, 11:25 am, "Peter Duniho" <NpOeStPe... (AT) nnowslpianmk (DOT) com
wrote:
On Sun, 24 Jun 2007 20:02:10 -0700, <jan.lou... (AT) gmail (DOT) 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(Mess age));
return new IntPtr();
}




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.