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

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

问题描述

假设我的应用程序在启动时调用 CoInitialize,在它存在之前调用 CoUninitialize.

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

假设我的应用程序使用了第 3 方组件并执行类似操作,这会导致某种故障吗?

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_OKS_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天全站免登陆