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:
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?
Supposed I manage to create a C++ Windows 开发者_JAVA技巧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
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#.
- you might want to take a look at POCO Project,in particular this class. There are examples if you download the code.
- you might also want to implement a web service for easy access from any client anywhere through sockets.
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).
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.
Maybe you can use ! ATL Project and then select Service (EXE).
Best Regards
精彩评论