tags:

views:

190

answers:

1

When I define an interface in IDL which does not derive from anything, the MIDL precompiler warns as such (Visual C++ 2008) :
warning MIDL2271 : [object] interfaces must derive from another [object] interface such as IUnknown (...)

And if I derive my interface from another which does not derive from IUnknown, MIDL fails :
error MIDL2257 : only IUnknown may be used as the root interface (...)

Now, my question : Is this a limitation in COM or the MIDL precompiler?

I have been looking at the D3D10 headers recently, and d3d10.h obviously has been generated using IDL (MIDL adds a comment to this effect). And all the interfaces derive from IUnknown in one way or another.

However, the peripheral headers (d3d10shader.h, d3d10effect.h, etc.) contain manually defined COM interfaces, some of which would trigger the warning or the error described here. I can only assume they had to define them manually to avoid those limitations.

Am I right? Why does the MIDL prevent pure interfaces?

+1  A: 

An interface that does not derive from IUnknown is not COM. This is the basic building bloc that allow memory managing and interface discovery.

There might be interfaces not deriving from IUnknown. However those are not COM, they are just a normal pointer.

Emmanuel Caradec