c++mingwcomobjectimapi

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


I am trying to access imapi2 com objects from a mingw project. I was trying to follow a visual studio example. I found the imapi2 header files in Microsoft SDK 7.1, but they do not seem to have the uuid's. The example I saw was using __uuidof for finding the uuid when creating an object. Like this:

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

But I always get an error because of __uuidof that is

undefined reference to _GUID const& __mingw_uuidof().

But __mingw_uuidof is defined as ...

#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>();                                  \
    }                                                                  \
    }

... in _mingw.h a few lines up from "#define __uuidof(type) __mingw_uuidof<__typeof(type)>()"

Why does the mingw definition for __mingw_uuidof not work?

Is there some way to find the uuid for imapi objects like DiscMaster in the sdk header files? Or do I need to get someother header file.

Thanks


Solution

  • COM interfaces in Microsoft's Platform SDK are normally defined by .idl files and they generate .h files using midl from these. So to just look up the CLSID or IID values search the idl file. In this case imapi2.idl has the guid you need and this has been used to produce an imapi2.h file with:

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

    The __uuidof extension in Microsoft's compilers reads the compiler specific data attached to the class or structure by a compiler specific declspec statement. You can do these using:

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

    So the DECLSPEC_UUID line above is attaching that guid to the class.

    The example code you give from mingw gives a template function that will return a uuid for a given type provided you set up the type using __CRT_UUID_DECL first. It may be that they have a system to call this automatically but that is not shown. Given what I see in your example, to get __uuidof to work for the given coclass you need to add:

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

    Following that statement, you will have a definition for __uuidof(MsftDiscMaster2) that will return the correct uuid.