Hi, Owen. There's a mistake here.
+ hNew = ImageList_Duplicate(iImageList == SHIL_LARGE ? hLarge : hSmall); + + /* Get the interface for the new image list */ + if (hNew) + { + ret = HIMAGELIST_QueryInterface(hNew, riid, ppv); + + if (!SUCCEEDED(ret)) + ImageList_Destroy(hNew); + }
After duplication hNew already has refcount == 1, after HIMAGELIST_QueryInterface is goes to 2, and it isn't what you want. To hide checking riid just remove condition before ImageList_Destroy.