VS 2005与VS2015中的ATL C ++ COM服务器(ATL 8与ATL 14) [英] ATL C++ COM Server in VS 2005 vs. VS2015 (ATL 8 vs. ATL 14 )

查看:154
本文介绍了VS 2005与VS2015中的ATL C ++ COM服务器(ATL 8与ATL 14)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我们使用VS2005来构建进程外(可执行)服务器。当我们搬到VS2015时,我注意到一个基本问题以不同的方式表现(至少在我看来)。 Com对象定义如下:

Up until now we used VS2005 for building our out of process (executable) servers. When we moved to VS2015 I paid attention that one basic issue behaves in a different way (at least as I see it). Com Object is defined as following:

class

ATL_NO_VTABLE CHwServerObject:

public CComObjectRootEx< CComMultiThreadModel>,

public CComCoClass< CHwServerObject,& CLSID_HwServerObject>,

公共 IHwServerObject

此外,我们将COM对象创建为单例

In addition, we create COM object as a singleton

DECLARE_CLASSFACTORY_SINGLETON(CHwServerObject)

DECLARE_CLASSFACTORY_SINGLETON(CHwServerObject)

在VS 2005中,如果 我添加两个方法来接口并在对象Method1和Method2中实现它们两个不同客户端(包括同一客户端进程中的两个不同线程)可以同时调用Method1和Method2,我可以看到不同的线程
 (我称之为"自动COM线程")同时执行Method1和Method2(通常,  ;这些"自动COM线程"之一线程是一个主进程线程)。我们负责所有可能发生在
Method1和Method2中的数据争用。出于某种原因,当我在VS2015中构建相同的项目时,相同的线程将执行Method1和Method2,因此,两个客户端相互依赖,并且在长同步调用的情况下,一个客户端将等待第二个 
这就是我真正想要避免的事情。我为我的描述中可能不正确的术语道歉。如果我理解正确,则在"呼叫同步"结束时post on msdn(https://msdn.microsoft.com/en-us/library/windows/desktop/ms693770(v = vs.85).aspx
)描述了我的案例。如果是这样,我怎样才能强制我的COM服务器以类似VS2005的方式工作?

In VS 2005, If I add two methods to interface and implement them in the object Method1 and Method2 two different clients (including two different threads in the same client process) can call Method1 and Method2 simultaneously, I can see different threads  (I call it "Automatic COM Threads") execute Method1 and Method2 simultaneously (usually, one of these "Automatic COM Threads" threads is a  Main process thread). We take care of all possible data races which can happen in Method1 and Method2. For some reason, when I build the same project in VS2015, same thread will execute Method1 and Method2 and as a result, two clients depend on each other and in the case of a long synchronous call one client will wait for the second  and that is what I really want to avoid. I apologize for a possible incorrect terminology in my description. If I understand correct, at the end of "Call Synchronization" post on msdn ( https:/msdn.microsoft.com/en-us/library/windows/desktop/ms693770(v=vs.85).aspx ) described my case. And if it is so, how can I still force my COM server to work in a similar to VS2005 way?

非常感谢,最诚挚的问候,Alexander

Thank you very much, Best Regards, Alexander

推荐答案

您好
Alexander Kavushansky,

感谢您在此发布。

您使用的是多线程公寓吗?

Are you using Multithreaded Apartments?

在多线程公寓模型中,进程中的所有线程都是已被初始化为单个单元中的自由线程驻留。因此,不需要在线程之间编组。线程不需要检索和分派消息,因为
COM在此模型中不使用窗口消息。

In a multithreaded apartment model, all the threads in the process that have been initialized as free-threaded reside in a single apartment. Therefore, there is no need to marshal between threads. The threads need not retrieve and dispatch messages because COM does not use window messages in this model.

多线程单元中对象方法的调用可以在公寓中的任何线程上运行。没有序列化的调用;同一方法或同时对同一对象可能会发生多次调用。在多线程中创建apartment
必须能够随时从其他线程处理对其方法的调用。

Calls to methods of objects in the multithreaded apartment can be run on any thread in the apartment. There is no serialization of calls; many calls may occur to the same method or to the same object simultaneously. Objects created in the multithreaded apartment must be able to handle calls on their methods from other threads at any time.

多个客户端可以同时从不同的线程调用支持自由线程的对象。在自由线程进程外服务器中,COM通过RPC子系统在服务器进程中创建一个线程池,并且任何这些线程都可以传递客户端调用(或多个
客户端调用)。随时。进程外服务器还必须在其类工厂中实现同步。自由线程的进程内对象可以从客户端的多个线程接收直接调用。

Multiple clients can simultaneously call, from different threads, an object that supports free-threading. In free-threaded out-of-process servers, COM, through the RPC subsystem, creates a pool of threads in the server process and a client call (or multiple client calls) can be delivered by any of these threads at any time. An out-of-process server must also implement synchronization in its class factory. Free-threaded, in-process objects can receive direct calls from multiple threads of the client.

有关详细信息,请参阅以下文档。

For more information, please refer to this document below.

https://msdn.microsoft.com/en -us / library / windows / desktop / ms693421(v = vs.85).aspx

希望这可以帮助你。

最诚挚的问候,

Sera Yu


这篇关于VS 2005与VS2015中的ATL C ++ COM服务器(ATL 8与ATL 14)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆