OOPortal 





Basic COM  «Prev 
MIDL: Compiling IDL files

Inside the MIDL-generated files

As discussed above, the MIDL-generated interface definitions use a set of macros defined in a standard include file objbase.h. Following are the definitions of both interfaces after C++ preprocessing:
struct __declspec(uuid
  ("673B0E01-4987-11d2-85C0-08001700C57F"))
  
    IMyComInterface : public IUnknown
    {
    public:
        virtual HRESULT __stdcall Fx1
    (unsigned char  *buf) = 0;
        
        virtual HRESULT __stdcall Fx2( void) = 0;
        
    };
…
struct __declspec(uuid
  ("24A4A631-4B59-11d2-85C2-08001700C57F"))
  
    IYourComInterface : public IUnknown
    {
    public:
        virtual HRESULT __stdcall Zx1
    (LONG ix) = 0;
        
    };
Notice how these definitions are similar to the manually coded version we did in the previous lesson. Also remember that in C++, with some exceptions, a struct and a class can be used interchangeably.
The _declspec(uuid(…)) directive is used by Visual C++ to associate the IID with a type of structure. One difference between this version and the one we did earlier is that these interface member functions are defined as pure virtual.
This means we can not directly instantiate a class/structure of this type. Instead, we derive a class from IMyComInterface and IYourComInterface. Don't worry about this for now our objective in this chapter is to study IDL, not to build a COM interface.