开发者

Do I need to specify "ThreadingModel" when registering an out-proc COM server?

When an in-proc COM server is registered there usually should be a ThreadingModel value under HKCR\CLSID\ClassId\InprocServer32 that controls how the class obje开发者_开发问答ct should be used in a multithreading environment. Looks like this value is not needed for out-proc servers. I searched and found lots of examples where there is ThreadingModel value under HKCR\CLSID\ClassId\LocalServer32 and also this article that explains this value isn't needed, but I'm not quite sure I understand the reasoning there.

I also searched the registry on my machine and found quite a lot of classes mostly shipped by Microsoft where ThreadingModel is also specified under InProcServer32.

Will ThreadingModel have any effect for an out-proc server or can I just always omit it?


You do not need the ThreadingModel for LocalServer32 because no matter what you do COM will always create a proxy between the client and the server for .exe COM servers because a proxy is needed for interprocess calls. So it does not matter to the client whether the server is in an STA or in an MTA.

The point of the article is that for inproc servers COM will try to decide which apartment is the best to use depending on the caller's apartment and on the ThreadingModel in InProcServer32, while for outproc servers the caller does not care about the apartment so by omitting ThreadingModel from the registry the developer of the COM server can decide which apartment to use through his/her implementation of the class factory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜