c - 使用ShellExecute()时是否需要初始化COM?

标签 c winapi com

我可以在不先初始化 COM 的情况下使用 ShellExecute() 吗?

最佳答案

documentation有你问题的答案:

Because ShellExecute can delegate execution to Shell extensions (data sources, context menu handlers, verb implementations) that are activated using Component Object Model (COM), COM should be initialized before ShellExecute is called. Some Shell extensions require the COM single-threaded apartment (STA) type. In that case, COM should be initialized as shown here:

CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE)

There are certainly instances where ShellExecute does not use one of these types of Shell extension and those instances would not require COM to be initialized at all. Nonetheless, it is good practice to always initalize COM before using this function.

不想听起来太居高临下,有一点是要确保您始终从上到下阅读文档。

关于c - 使用ShellExecute()时是否需要初始化COM?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31189867/

相关文章:

c - 正确使用指针

c++ - OpenMP num_threads(1) 比没有 OpenMP 执行得更快

c++ - 如何知道 DeferWindowPos() 是否导致重新分配?

c++ - 将 HTML 导出为 PDF(C++、Windows)

Python 3.0 窗口/COM

c# - F# 和 C# 中 COM 对象创建的差异

在 xcode 上崩溃,但在 Windows 上不崩溃。信号传输?

指数基数为 10 的 double 和 float 的 c 代码序列化

c# - 如何在 C# 中使用 sendkey 消息定位虚拟桌面?

c++ - 从 COM 调用返回时接口(interface)未注册 (0x80040155)