开发者

Run function on running application on execute

Alright so what I am trying to do is essentially create a program that, when it is already executed, can be "executed" again, detect the already existing process and instead of creating another process, execute a function in the existing process.

Any ideas?

It's possible I am going at this all wrong. I am trying to adapt this open-source Virtual Printer (http://sourceforge.net/projects/imageprinter/) to an application of mine. The printer prints for example a PDF to a file and it seems also has a feature to launch an application. I need to grab the PDF into my own app开发者_StackOverflow社区lication for handling at this point and the user needs to be able to append more pdfs by printing them to this printer.

The way I was planning to handle it is to have the application check that folder for new files everytime it opens and a command is called when a new file is printed. Is there another way to import the pdf data more directly to a running process?


1: The typical solution is to use a named mutex for this. See this question asked on MSDN for more details.

2: Use one of these functions (maybe FindWindowEx?) and (if needed) some way to get the information for locating the HWND between the two processes. Sorry I can't be more clear, there are way too many ways to do this and it varies from application to application.

3: After you know the other application is running, you can use SendMessage with your own UINT message (make sure it doesn't clash with an existing message) and make sure to handle the special message in your message loop.


Sounds like you might want to start googling around for information about the Running Object Table... Here is sample with and MFC Client calling a .net Application that registers itself with the Running object table so they can perform inter process communication.

Running Object Table: Provider in .NET, consumer in MFC

What exactly are you trying to do here, I am sure you have a good reason for what you are doing but there might be other approaches that get the same result in a simpler way.


There are two stages to the answer:

I am asumming a Win32 API program, rather than MFC/.net

  1. Named mutexs, as pointed out.
  2. WM_USER messages. In your message loop, set up a case to handle messages you defined. This message will cause the execution of your target function.

Basically, look up inter process communication in the win32 api.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜