3

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

user1404617
  • 585
  • 1
  • 5
  • 20

1 Answers1

4

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.

patthoyts
  • 32,320
  • 3
  • 62
  • 93
  • What I am taking you to say is I need to make a header file out of the idl file. The MS SDK has a imapi2.h file already. I made a project in Visual Studio, that did not seem to generate a more useful header file. I then used midl, but that generated a header file very like imapi2.h. I found another tool that might do it, but have not had time to try it. – user1404617 Mar 20 '14 at 23:13
  • Thanks @patthoys for the answer. For any one else, to get this to work I added the imapi2.h file to my project and then found the id for each of the com objects I needed, and copied the numbers from the `class DECLSPEC_UUID("2735412E-7F64-5B0F-8F00-5D77AFBE261E")` type command to the `__CRT_UUID_DECL(MsftDiscMaster2, 0x2735412e, 0x7f64, 0x5b0f, 0x8f, 0x00, 0x5d, 0x77, 0xaf, 0xbe, 0x26, 0x1e);` command. I then but all these __CRT_UUID_DECL's into my own header files. – user1404617 Apr 17 '14 at 17:05