0

I have the following scenario:

My app gets some data from the command line.

After getting executed by the first time, my app runs always one instance and that instance will be in memory until the use explicitly tells it to shutdown instead of just hiding the form when not needed.

When the user tries to run the app a second time, the process starts, checks if there is another one in memory and if that is true, it sends a WM_COPYDATA message to the process in memory with the data it got from the command line and exits.

That all works well when the it«s the user who runs the app.

I needed to ran it from the Microsoft Word 2003 toolbar so i used a "Add-in" for that. The problem is that when my app is started from that Add-In (using Process class), it seems that the process already in memory gets a WM_ACTIVATEAPP message instead of a WM_COPYDATA one, so i can't get the needed data sent from the process started by the Add-In.

I have no idea on why is that happening and how to fix it. I've googled for hours and nothing helped...

Can anyone help?

skaffman
  • 398,947
  • 96
  • 818
  • 769
osiris
  • 432
  • 5
  • 18

1 Answers1

1

Getting a WM_ACTIVATEAPP message is quite normal, part of the usual notifications that Windows sends. Don't assume that the first message you'll get is WM_COPYDATA, keep looking. If you don't get it at all then the window handle that you used to send the message was wrong. Which is a very common problem, it is not that easy to accurately find a window back.

The .NET framework already has very good support for single-instance apps that can retrieve the command line from a second instance. Consider using it instead. Check this blog post.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Kinda late answer but here it goes: Thanks for the answer. I was only getting the first message, i should be getting all of them and try to find the right one. About your suggestion, i didnt want use VB stuff in a C# app and ended up using MSMQ. Still, i ask you: how do i get all the messages? WndProc was only being called once so i only got one message... Either way, thanks for the help. :) +1 P.S. - I marked it as answer because it helped me to find what was probably happening with the messages and the suggestion given helped me into finding MSMQ – osiris Feb 27 '11 at 23:09
  • What makes you think this is "VB stuff"? It was written in C#. The ability to freely mix languages in .NET is a feature, not a bug. It is not infectious. – Hans Passant Feb 27 '11 at 23:15