Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pointless 'MIDL_INTERFACE' Macro in winapi?

Tags:

c++

mingw

winapi

After browsing some old code, I noticed that some classes are defined in this manner:

MIDL_INTERFACE("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")
Classname: public IUnknown {
    /* classmembers ... */
};

However, the macro MIDL_INTERFACE is defined as:

#define MIDL_INTERFACE(x) struct

in C:/MinGW/include/rpcndr.h (somewhere around line 17). The macro itself is rather obviously entirely pointless, so what's the true purpose of this macro?


2 Answers

In the Windows SDK version that macro expands to

 struct __declspec(uuid(x)) __declspec(novtable)

The first one allows use of the __uuidof keyword which is a nice way to get the guid of an interface from the typename. The second one suppresses the generation of the v-table, one that is never used for an interface. A space optimization.

like image 56
Hans Passant Avatar answered Feb 04 '26 21:02

Hans Passant


This is because MinGW does not support COM (or rather, supports it extremely poorly). MIDL_INTERFACE is used when defining a COM component, and it is generated by the IDL compiler, which generates COM type libraries and class definitions for you.

On MSVC, this macro typically expands to more complicated initialization and annotations to expose the given C++ class to COM.

like image 35
Billy ONeal Avatar answered Feb 04 '26 19:02

Billy ONeal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!