开发者

How are you supposed to read the following documentation?

From IDispatch::GetTypeInfoCount

The return value obtained from the returned HRESULT is one of the following: [S_OK -> Success], [E_NOTIMPL -> Failure]

And the sample at the bottom returns E_INVALIDARG and NOERROR.

As far as I see E_INVALIDARG is not S_OK, nor is it NOERROR, so what do you do? Do you check for invalid pointers or you don't?

It seems that COM is pretty much foundation for everything, and I can't find one good source of information about correct 开发者_开发问答behavior of simple IDispatch. How do you approach such inconsistencies in your production code?


With COM, you should never check for specific return values unless you actually need to have special handling for those values. Instead, you should use the FAILED or SUCCEEDED macros when you just need to know if a call failed or succeeded. i.e.

HRESULT hr = ...;
if (FAILED(hr)) {
   ...

COM calls can often return a much wider range of error codes than is specified in the documentation. The called function is not the only source of errors. Depending on the call is actually made (in-process, out-of-process, DCOM) the COM system itself can return a whole host of errors.


NOERROR is defined to the very same value as S_OK. Checking for a null pointer before dereferencing is good style in any method but in this sample it should return E_POINTER.

Values NOERROR/S_OK and E_NOTIMPL are the most typical you should expect from that method unless you abuse the method, that list can of course omit codes like E_POINTER.

Anyway don't target for specific codes, use SUCCEEDED/FAILED macros.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜