两次调用CoInitialize() [英] double calls to CoInitialize()

查看:295
本文介绍了两次调用CoInitialize()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我的应用程序在启动时调用CoInitialize,在存在之前调用CoUninitialize。

Let's say my application calls CoInitialize when it starts and CoUninitialize before it exists.

假设我有一个第三方组件,该组件已被我的应用程序使用,并且做了类似的事情,这会导致某种故障吗?

Assuming I have a 3rd party component that's used by my application and does a similar thing, will this cause some kind of failure?

在提交了调用之后可以调用CoInitialize吗?第二个呼叫会失败吗?

is it okay to call CoInitialize when that call has already been submitted? will the second call fail? or will it just "let it pass" as it's already called.

推荐答案

CoInitialize 如果已在调用线程中初始化,将返回 S_FALSE 。但是,对于两个返回 S_OK S_FALSE 的调用,都需要一个 CoUninitialize 调用。仅对 CoUninitialize 的数量等于 CoInitialize 的数量进行计数。

CoInitialize will return S_FALSE if it has already been initialized in the calling thread. However, for both invocations that return S_OK and S_FALSE there needs to be a CoUninitialize call. The number of calls to this functions get counted, and only when the number of CoUninitialize equals that of CoInitialize it will actually uninitialize things.

因此,总之,第二次调用是无害的,并且多次调用这对函数没有问题。

So in conclusion, a second call is harmless, and there are no problems with calling this pair of functions more than once.

这篇关于两次调用CoInitialize()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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