如何在 Visual Studio 2010 中创建 C++ Windows 服务并与之通信?

如何在 Visual Studio 2010 中创建 C++ Windows 服务并与之通信?

问题描述:

我有一个(某种)用 C++ 实现的数据库.现在我想创建一个用于查询它的 Windows 服务,因为 P 调用它不是一个选项,因为每个查询都必须加载数据库,这需要几分钟.

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.

但我面临几个问题:

  1. 如何在 VS2010 中创建 C++ Windows 服务?模板已被删除(为什么???),我可以使用 2008 模板并转换它吗?如果是:我在哪里可以找到这样的模板?

  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?

假设我设法创建了一个 C++ Windows 服务:我有哪些选项可以与该服务进行通信(来自 CSharp)?有哪些优点/缺点?

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!

不知道为什么,模板真的没了.

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

对于您的应用程序和服务 WCF 之间的通信将是一个选项.WCF 的优点之一是,您可以轻松切换传输层(HTTP、TCP、共享内存)

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)

查看此 MSDN 页面.它准确描述了您要实现的目标:在 Windows 服务中托管 WCF 服务.它甚至在最后包含一个简单的 Windows 服务实现.不幸的是没有 C++ 而是 C#.

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#.