Coinitialize(nil)和CoInitializeEx(0,COINIT_MULTITHREADED)的区别 [英] Coinitialize(nil) and CoInitializeEx(0, COINIT_MULTITHREADED) difference

查看:2043
本文介绍了Coinitialize(nil)和CoInitializeEx(0,COINIT_MULTITHREADED)的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个线程中,
是有区别的,如果我使用

in a thread, is there a difference if I use

Coinitialize(nil)

而不是

CoInitializeEx(0, COINIT_MULTITHREADED);

我使用Delphi 7,但我认为问题可以保留为其他编程语言
感谢

I use Delphi 7 but I presume the question can remain for other programming languages Thanks for your help.

推荐答案

前者初始化COM的方式是将调用线程放入自己的单线程公寓。后者以将调用线程置于共享多线程公寓(MTA)中的方式初始化COM。两个公寓有非常不同的语义,特别是在如何访问COM对象跨线程边界。不同公寓中的线程必须使用代理共享COM对象,但COM为您提供同步(通过每线程消息队列)。同一公寓中的线程可以共享COM对象而不使用代理,但必须手动同步,例如关键部分或互斥体。

The former initializes COM in a way that puts the calling thread into its own single-threaded apartment (STA). The latter initializes COM in a way that puts the calling thread into a shared multi-threaded apartment (MTA). The two apartments have very different semantics, especially in how COM objects are accessed across thread boundaries. Threads in different apartments must use proxies to share COM objects, but COM provides synchronization for you (via per-thread messages queues). Threads in the same apartment can share COM objects without using proxies, but must synchronize manually, such as with critical sections or mutexes.

是的,有一个区别,它可以非常显着。请阅读MSDN上的文档,它非常详细。

So yes, there is a difference and it can be very significant. Please read the documentation on MSDN, it is very detailed.

CoInitialize函数

CoInitializeEx函数

处理,主题和公寓

这篇关于Coinitialize(nil)和CoInitializeEx(0,COINIT_MULTITHREADED)的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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