2021-10-29

ISupportsErrorInfo.InterfaceSupportsErrorInfo(REFIID riid) implementation

I am a babysitter now overlooking a huge old-time (started in last century) code base for Windows, using C++ and C#, largely using COM as a glue.

I noticed that ISupportsErrorInfo::InterfaceSupportsErrorInfo() implementations (around 400 of them, wow) are just naive, exactly as here:

STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid)
{
    static const IID* arr[] =
    {
        &IID_IStore,
    };
    
    for (int i=0; i<sizeof(arr)/sizeof(arr[0]); i++)
    {
        if (InlineIsEqualGUID(*arr[i], riid))
            return S_OK;
    }
    
    return S_FALSE;
}

It looks to me that, once upon a time, someone (MVP, evangelist) has written a book about COM and then everybody later just copied these lines without thinking.

First of all, why do I need an array if I only have one item in it? Without an array, I don't need a for-loop.

To me, it looks like one line will be fine, eg.

return MyCoolHelper::InterfaceSupportsErrorInfo(riid, IID_IStore);

Maybe you have seen a decent implementation of it that supports 1 or more IID-s?



from Recent Questions - Stack Overflow https://ift.tt/3mqkoMm
https://ift.tt/eA8V8J

No comments:

Post a Comment