查找 IMAPI2 COM 对象的 UUID/标头或让__uuidof在 mingw 上工作

finding uuid's/headers for imapi2 com objects or get __uuidof to work on mingw

本文关键字:uuidof mingw 工作 对象 COM IMAPI2 UUID 查找      更新时间:2023-10-16

我正在尝试从mingw项目访问imapi2com对象。我试图效仿visual studio的例子。我在微软SDK 7.1中找到了imapi2头文件,但它们似乎没有uuid。我看到的例子是在创建对象时使用__uuidof来查找uuid。这样的:

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

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

对_GUID的未定义引用__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对象的uid ?或者我需要得到其他头文件。

谢谢

微软平台SDK中的

COM接口通常由。idl文件定义,它们使用midl从这些文件生成。h文件。因此,要查找CLSID或IID值,请搜索idl文件。在本例中是imapi2。Idl有您需要的向导,它已经被用来生成一个imapi2.h文件:

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

微软编译器中的__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)的定义,它将返回正确的uid。