gpt4 book ai didi

windows - 在我的应用程序退出前将终止的线程上调用 CoUninitialize 是否重要?

转载 作者:可可西里 更新时间:2023-11-01 13:03:39 32 4
gpt4 key购买 nike

我调用 CoInitializeEx,特别是:

CoInitializeEx(NULL, COINIT_DISABLE_OLE1DDE | COINIT_APARTMENTTHREADED);

在我的应用程序创建但随后在应用程序退出之前终止的线程中。将它们与 CoUninitialize 调用配对是否重要,或者在线程终止时释放这些资源是否重要?

最佳答案

资源通常在进程终止时返回给系统,而不是在其中一个线程终止时。

然而,CoUninitialize()不仅释放资源和卸载 DLL,它还进入模态消息循环以便在线程终止之前抽取剩余的 COM 消息。文档说:

If there are open conversations remaining, CoUninitialize starts a modal message loop and dispatches any pending messages from the containers or server for this COM application. By dispatching the messages, CoUninitialize ensures that the application does not quit before receiving all of its pending messages. Non-COM messages are discarded.

因此,为了避免调用方出现 RPC 错误,我建议您遵循文档的建议,并始终在终止调用了 CoInitializeEx( )

关于windows - 在我的应用程序退出前将终止的线程上调用 CoUninitialize 是否重要?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8054487/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com