在我的进程中托管一个 COM 服务器

Host a COM server inside my process

我知道我可以注册要使用的 COM 对象 inproc(通过标准 com 注册)和 outproc(通过 dcom)托管在专用的 dllhost.exe 进程中。

但是是否可以让我的 COM 对象 运行 在 external process 中提供给消费者(如 dcom)而不是托管在 dllhost 而不是我自己的进程中?

我的目标是让一个进程(windows 服务)运行符合我的逻辑,并且只托管一个 COM 对象,以便其他进程可以使用简单的方式与我通信 CoCreateInstance COM 对象。可能吗?

请不要提供其他协议作为答案,如果无法以这种方式托管 COM 就足够了。

谢谢!

COM 的概念是 DLL Surrogates:

COM makes it possible to create DLL servers that can be loaded into a surrogate EXE process. This combines the ease of writing DLL servers with the benefits of executable implementation. Development tools like Microsoft Visual Studio facilitate the writing of DLL servers, but a DLL server in itself has limits

dllhost.exe我们经常在后台看到运行(作为一个或多个实例)实际上是默认的代理进程,但是你可以写一个自定义的:Writing a Custom Surrogate .这是很少见的。

但是当您说 "host a COM object so that other processes can communicate with me using simple CoCreateInstance of the COM object" 时,我认为您不需要所有管道(实施起来可能相当复杂)。只需从您的 Windows 服务托管和注册 COM 对象。它被称为 Out-Of-Process COM server 而不是 In-Process COM 服务器(DLL)。