在msdn中对于CoInitialize的解释如下: Initializes the COM library on the current apartment and identifies the concurrency model as single-thread apartment (STA). Applications must initialize the COM library before they can call COM library functions other than CoGetMalloc and memory allocation functions. 初始化com库。应用程序调用com库函数(除CoGetMalloc和内存分配函数)之前必须初始化com库。
在别人的博客上看到下面的说明: CoInitialize并不装载com库,这个函数只是用来初始化当前线程使用什么样的套间。当使用这个函数以后,线程就和一个套间建立了对应关系。
线程的套间模式决定了该线程如何调用com对象,是否需要列集等 你可以看一下有关列集的资料,使用不同套间之间对象接口是通过列集来完成的。关于列集的实现,很多书上都有较详细的说明。 CoInitialize()并不会干扰客户和服务之间的通信,套所作的事情只是让线程注册一个套间,而线程运行过程中就必然在此套间中,就象我们每个活着的人,都一定属于某个国家一样。 需要强调的是,套间是com中用来解决并发调用冲突的很有效的办法 Before calling any COM functions, a thread needs to call CoInitialize to load the COM infrastructure (and to enter an apartment). Once a thread calls CoInitialize, the thread is free to call COM APIs.
CoInitialize(0)让当前线程进入一个STA的Apartment... 转载地址(http://blog.sina.com.cn/u/49055f91010004f6) 自己在综合了各种说法,有如下理解: COM是得到windows支持的一个特殊功能,提供方便、简单的对象编程模型。(我对此表示怀疑^0^)
大概就这样了,CoInitialize对windows来说可能只是设置一个标志,让下面的CoCreateInstance创建不同的线程对象罢了,同理,CoUninitialize可能只是清除标志。 |
|