c++ - 后台程序提供API供其它程序使用
阿神
阿神 2017-04-17 11:45:40
0
5
632

最近遇到了一个问题,就是我想写一个程序,我可以启动它,在后台运行,该程序可以提供函数接口做一些操作。然后其它程序可以通过包含后台程序的头文件,使用后台程序的函数。

想了好久不知道,该怎么做。求各位帮助啊。

阿神
阿神

闭关修行中......

reply all(5)
Ty80

It is recommended to refer to Inter-Process Communication (RPC)
However, it may not be possible to directly include the header file of the background program and use the functions of the background program

Ty80

The simplest way is to redirect the standard input and standard output and control the background program through them.

http://stackoverflow.com/questions/2680174/redirect-stdin-in-c-program-to-another-process

Ty80

The program started in the background is a service (a memory-resident process, A), and the subsequent program (called program B) and A can communicate in various ways;
After being able to communicate, all functions in A can be called at will (of course, through the protocol negotiated by both parties);
If you need to directly expose a function to the outside world, in fact, you need to publish this function as a service for other users to use;

Publish functions into services. Some middleware services do this, such as Tuxedo;

There are many ways to communicate between processes,
For example, pipes; shared memory, queues, etc.; refer to "UNIX Network Programming Volume 2" inter-process communication: http://www.me115.com/book/129.html

Perhaps your requirement is just a dynamic link library to package A's code into a dynamic library,
Expose the header file interface for B to use? In this way, there is only one process;

左手右手慢动作

Extract the parts shared by the current background program and other programs into a dynamic library

小葫芦

webService,soap

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template