有没有办法在 C 中使用 use/call COM 接口?

Is there a way to use/call COM interfaces in C?

MSDN 参考了C语言也可以用来创建和使用COM对象。

我查看了 CodeProject here,发现相关的头文件已创建,它们将包含在调用这些 COM 接口的任何 C 应用程序中。

Windows 中的所有 COM 对象都会有类似的相关头文件吗?

或者有没有其他方法可以从 C 调用 COM 接口?

Will all COM objects from Windows will have similar relevant header files?

Microsoft Interface Definition Language file using the MIDL compiler will contain definitions for use by C programs. See C/C++-Compiler Considerations:

生成的所有 header 个文件

The generated .h file has both C-style and C++-style definitions for interfaces.

我不知道 all COM objects 是否附带 Windows 或 Windows SDK 是否附带 pre-built headers 供 C 程序使用,但假设如此肯定是合理的。如果您发现没有 C-style 接口定义的接口,您始终可以 运行 MIDL 编译器针对 .idl 文件。

Or is there any other way to call COM interfaces from C ?

一些 COM 接口实现也作为 type libraries (.tlb). You can #import TLB 进入您的 C++ 代码。这会生成一个主要的 header 文件 (.tlh),您可以使用它来重建 C-style 接口定义。