473,508 Members | 2,361 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Process Exit

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

Jun 25 '07 #1
3 5644
On Sun, 24 Jun 2007 20:02:10 -0700, <ja********@gmail.comwrote:
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
Jun 25 '07 #2
On Jun 25, 11:25 am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Sun, 24 Jun 2007 20:02:10 -0700, <jan.lou...@gmail.comwrote:
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();
}
Jun 25 '07 #3
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
<ja********@gmail.comwrote in message
news:11*********************@j4g2000prf.googlegrou ps.com...
On Jun 25, 11:25 am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
>On Sun, 24 Jun 2007 20:02:10 -0700, <jan.lou...@gmail.comwrote:
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();
}

Jun 25 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1464
by: ajikoe | last post by:
Hello, I would like to run a python process and wait until the process exit. How can I do it? For example I would like to run a.exe. and wait until a.exe exit. Sincerely Yours, Pujo
2
4967
by: RL | last post by:
Hello Perl gurus, 1. I have a web page where I can push a button (dospawn.html). 2. This button calls a CGI script (spawnboss.cgi) 3. spawnboss.cgi calls a forking perl script (forkme.pl) 4....
1
5035
by: Ken Barz | last post by:
So close so close. Thanks Fergus and Herfried. I need one more step for this to work. I get my program to run ok, but I need something in there to tell it to wait for it to finish before it...
4
3323
by: Nick | last post by:
Hi there, I'm running a process object within a .NET app, very simple, the process is declared with events, i'm handling the Exit event and running a win32 application. No matter how the...
3
13445
by: WRH | last post by:
Hello I used the VS designer to set up Process code as follows... the problem is, although the process is executed, when it is shut down I never get the Exited event. .... private...
0
1298
by: Cwappy | last post by:
I have a class that builds a DataTable and then, when the process is exiting, tries to write that DataTable to SQL Server 2000 via the SqlBulkCopy class. I know the process is exiting because I'm...
3
1807
by: norm4h8 | last post by:
Hi! I have a question about how to create a process in such a way that it would terminate itself if its wated for input for too long. Here is the story. I have 2 different files, say R.c and...
5
3219
by: alexia.bee | last post by:
Hi, I my program runs other program(form) by process.start. In some cases the other program gets exception and dies. Can I get the reason of the termination of other program(Stopped by user,...
1
1816
by: dae3 | last post by:
Let's say I have two programs: 'foo' and 'bar'. 'foo' always returns an exit code of 10. 'bar' always exits normally (i.e. returns 0). If I do: `foo | bar` in my shell, the shell will return 10....
0
7321
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7489
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5624
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5047
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4705
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1547
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
414
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.