且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

两次调用CoInitialize()

更新时间:2022-03-03 21:42:12

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.