开发者

Execute External function belonging to other process

开发者 https://www.devze.com 2023-04-02 07:24 出处:网络
I would need help with a problem. I have 2 processes running, one the Watchdog and the other a simple test process. I need process 2 to call code from the Watchdog, the reason I do this is to reduce t

I would need help with a problem. I have 2 processes running, one the Watchdog and the other a simple test process. I need process 2 to call code from the Watchdog, the reason I do this is to reduce the size of process 2. For example process 2 must call a function called "IsSafe" from the watchdog. The IsSafe function relies on other code belonging to Watchdog process and it will not be viable to rewrite this code for process 2. I have thought of ideas, please could you advise on which is the best solution and or give advice.

Idea One

Use Named pipes to communicate between processes and pass parameters and return values around.

Idea Two

Use Share Memory to share parameters and return values

Idea Three

Use windows messages, I honestly think 开发者_如何学运维this will not work

Idea Four

Somehow create a executable portion of shared memory and execute this code with a far jmp.

Please could you advise.


RPC was invented long ago. Then COM on top of that. In my opinion best forget your idea, but if you must, use COM.

By the way, to communicate between processes on the same Windows machine without COM, use mailslots.

Seems you forgot about them in you list.

Cheers & hth.,


Although putting the code in the process which needs to call it is good advice in general, in the particular case of a watchdog (also debugger and any other form of error handler) using separate processes is correct. You don't want the watchdog to fail due to an error in the main code, so it needs to be a separate process.

A named pipe would be ideal in this scenario, the TransactNamedPipe function is designed just for this.


A DLL is the standard implementation of idea 4. It's loaded in both address spaces, but shared in physical RAM. You don't need special tricks; it works everywhere and Windows will deal with any security issues for you.

It's also portable to most other Operating Systems, although they're generally called something else, e.g. .so on Linux.


All you really need is some IPC. For a lightweight and easy solution, simply define an application specific message with WM_APP and have a mapping from the wParam/lParam for parameters. If you find you need more than 8 bytes, you could use WM_COPYDATA instead.

0

精彩评论

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

关注公众号