Options for Windows service communication
I'm developing a service which will run as System and will process long-running tasks in the background. I now need to display some feedback to the user in the form of a tasktray icon and I would also like to be able to pause/re开发者_如何学Pythonsume the tasks from the tasktray icon so my requirement is to send a message in either direction and receive an arbitrary length data block back in response. A single request/response would be fine but it needs to work in both directions.
This is using C++ (non-MFC) in Windows.
I've looked at MIDL/RPC as I've used it in the past but I need to define a rigid interface spec first and cannot return arbitrary length data (as far as I am aware).
Are there any suggestions for a library I could use for this?
Thanks, J
COM is the best solution for RPC in windows. It is very powerful and easy to write. Raw MS-RPC is good too. With both you can return arbitrary length data, see size_is MIDL attribute:
HRESULT Proc7(
[out] long * pSize,
[out, size_is( , *pSize)] my_type ** ppMyType); /* Specifies a pointer
to a sized pointer,
which points to a block
of my_types, whose size is
unknown when the stub
calls the server. */
You can use any of the following:
- TCP/IP
- UDP
- Pipe
- shared memory (i.e. memory-mapped file)
EDIT - as per comment:
Some shared memory based solutions including source code:
- http://www.codeproject.com/KB/threads/sharedmemipc.aspx
- http://www.codeproject.com/KB/threads/memmapipc1.aspx
- http://www.codeproject.com/KB/cpp/InterprocessSingleton.aspx
精彩评论