How to create and communicate with a C++ Windows S

2019-05-19 01:11发布

I have a (kind of) database implemented in C++. Now I want to create a Windows service for querying it, because P-invoking it is not an option, as the database would have to be loaded with every query, which takes several minutes.

But I face several problems:

  1. How can I create a C++ Windows Service in VS2010? The template has been removed (why???), can I use a 2008 template and convert it? If yes: where do I find such a template?

  2. Supposed I manage to create a C++ Windows service: what are my options to communicate with this sevice (from c sharp)? What are the advantages/disadvantages?

I'd be glad for any hint!

Ben

5条回答
来,给爷笑一个
2楼-- · 2019-05-19 01:47
  1. you might want to take a look at POCO Project,in particular this class. There are examples if you download the code.
  2. you might also want to implement a web service for easy access from any client anywhere through sockets.
查看更多
对你真心纯属浪费
3楼-- · 2019-05-19 01:57

I don't know why, but the template is really gone.

For communicating between your application and the service WCF would be an option. One advantage of WCF is, that you can easily switch the transport layer (HTTP, TCP, Shared Memory)

Have a look at this MSDN page. It describes exactly what you are trying to achieve: Host a WCF Service in a Windows Service. It even contains a simple Windows Service implementation at the end. Unfortunately no C++ but C#.

查看更多
smile是对你的礼貌
4楼-- · 2019-05-19 01:57

You should implement the followin functions:

VOID WINAPI ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv);
VOID WINAPI ServiceHandler(DWORD fdwControl);
VOID ReportSvcStatus( DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwWaitHint );

More info on MSDN. An example: link.

查看更多
劫难
5楼-- · 2019-05-19 02:03

What I did some years ago was an COM out-of-process server which was a Windows Service. It worked fine and you can access it from C# (and many other languages ...) easily. If you have no COM experience it might become hard (depending on how complex your interface is).

查看更多
我想做一个坏孩纸
6楼-- · 2019-05-19 02:08

Maybe you can use ! ATL Project and then select Service (EXE).

Best Regards

查看更多
登录 后发表回答