c++ - 查找 imapi2 com 对象的 uuid/ header 或获取 __uuidof 以在 mingw 上工作

标签 c++ mingw comobject imapi

我正在尝试从 mingw 项目访问 imapi2 com 对象。我试图遵循一个 Visual Studio 的例子。我在 Microsoft SDK 7.1 中找到了 imapi2 头文件,但它们似乎没有 uuid。我看到的示例是在创建对象时使用 __uuidof 查找 uuid。像这样:

CoCreateInstance(__uuidof(MsftDiscMaster2), NULL, CLSCTX_INPROC_SERVER, __uuidof(IDiscMaster2), (void**) &m_discMaster);

但我总是得到一个错误,因为 __uuidof 那是

undefined reference to _GUID const& __mingw_uuidof().

但是 __mingw_uuidof 被定义为 ...

#define __CRT_UUID_DECL(type,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8)           \
    extern "C++" {                                                      \
    template<> inline const GUID &__mingw_uuidof<type>() {              \
        static const IID __uuid_inst = {l,w1,w2, {b1,b2,b3,b4,b5,b6,b7,b8}}; \
        return __uuid_inst;                                             \
    }                                                                   \
    template<> inline const GUID &__mingw_uuidof<type*>() {             \
        return __mingw_uuidof<type>();                                  \
    }                                                                  \
    }

...在 _mingw.h 中,从“#define __uuidof(type) __mingw_uuidof<__typeof(type)>()”开始的几行

为什么 __mingw_uuidof 的 mingw 定义不起作用?

有没有办法在sdk头文件中找到像DiscMaster这样的imapi对象的uuid?或者我是否需要获取其他头文件。

谢谢

最佳答案

Microsoft 平台 SDK 中的 COM 接口(interface)通常由 .idl 文件定义,它们使用 midl 从这些文件生成 .h 文件。因此,只需查找 CLSID 或 IID 值即可搜索 idl 文件。在这种情况下,imapi2.idl 具有您需要的 guid,这已用于生成 imapi2.h 文件:

class DECLSPEC_UUID("2735412E-7F64-5B0F-8F00-5D77AFBE261E")
MsftDiscMaster2;

Microsoft 编译器中的 __uuidof 扩展通过编译器特定的 declspec 语句读取附加到类或结构的编译器特定数据。您可以使用以下方法执行这些操作:

struct declspec(uuid("{......}")) IMyInterfaceType;

所以上面的 DECLSPEC_UUID 行将该 guid 附加到类。

您从 mingw 提供的示例代码提供了一个模板函数,如果您首先使用 __CRT_UUID_DECL 设置类型,该函数将返回给定类型的 uuid。可能他们有一个系统可以自动调用它,但没有显示出来。鉴于我在您的示例中看到的内容,要让 __uuidof 为您需要添加的给定 coclass 工作:

__CRT_UUID_DECL(MsftDiscMaster2, 0x2735412e, 0x7f64, 0x5b0f, 0x8f, 0x00, 0x5d, 0x77, 0xaf, 0xbe, 0x26, 0x1e);

在该语句之后,您将拥有 __uuidof(MsftDiscMaster2) 的定义,它将返回正确的 uuid。

关于c++ - 查找 imapi2 com 对象的 uuid/ header 或获取 __uuidof 以在 mingw 上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22517853/

相关文章:

c++ - 使用 com 对象删除计划任务

c++ - 如何在 Win32 c++ Dll 中连接 int 和 char* 并返回 char*?

c++ - BST的递归插入

c++ - 基于数据集合执行二叉树搜索

c++ - 让 mingw-get 正确安装 - mingw/msys 路径缺失以及更多!

c++ - 如何在 Windows 上编译 64 位版本的 ffmpeg?

c# - 在 InnoSetup 中访问 C# COM 对象时出现异常

c# - 如何在 C# 中从 Active Directory 获取 System.__ComObject 值

c++ - 为什么我的函数总是返回 "2"?试图在数组中找到搜索数字的索引

c - 可以从 MinGW-w64 二进制文件中安全删除哪些文件?