Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I choose between E_NOTIMPL and E_NOINTERFACE?

Tags:

c++

oop

com

hresult

I have managed to confuse myself whether I should return E_NOTIMPL or E_NOINTERFACE from my COM server methods.

I have a class with two functions I have overridden from the class I inherited from, both of those functions do nothing since they aren't really supported at the moment, so I ask should I use "not implemented" or "no interface" for these functions return values?

Does anyone have a general rule of thumb of when to use each?

like image 835
Jtello Avatar asked Jun 18 '12 23:06

Jtello


3 Answers

If you failed to implement an entire interface, then your QueryInterface could explicitly return E_NOINTERFACE, so that nobody attempts to call any of its methods, or you could just make all of the methods could return E_NOTIMPL (it does actually make sense to do this in some edge cases). If you partially implement an interface, then you shouldn't return E_NOINTERFACE at all.

like image 52
Neil Avatar answered Nov 07 '22 16:11

Neil


If a class does not provide a complete implementation of a requested interface the return E_NOINTERFACE. If a class does not implement the body/logic of an interface function then return E_NOTIMPL.

like image 3
Captain Obvlious Avatar answered Nov 07 '22 16:11

Captain Obvlious


You do (formally) implement the interface, so E_NOINTERFACE is not for you. It happens that you have methods not usefully implemented, so you should return E_NOTIMPL.

like image 3
sharptooth Avatar answered Nov 07 '22 15:11

sharptooth