Out-of-process COM singletons

跟風遠走 提交于 2019-12-13 00:06:35

问题


I am dealing with a single-threaded library (not thread safe) that I want to wrap in a COM out-of-process object to get around its thread non-safety. I need a behavior where each new COM object is instantiated in its own process - some form of out-of-process singleton.

It's been a while since I've been dealing with hardcore COM so I am not sure how to approach this or whether this is at all possible without some trickery.


回答1:


Call CoRegisterClassObject() with the REGCLS argument set to REGCLS_SINGLEUSE. Beware of the cost, a process is not a cheap operating system object.

There is otherwise no reason why you couldn't ensure that marshaled method calls are thread-safe, just call CoInitializeEx() to ask for an STA. Works as well in a out-of-process server as it does in a in-process server. If you are only doing this to solve a threading problem then definitely favor in-process STA. Message loop required.



来源:https://stackoverflow.com/questions/11817822/out-of-process-com-singletons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!