The issue might lie in this statement: *ppv = this; Because you use a C-cast to type void*, type information is lost. The pointer does not point to the correct virtual table of the interface that you want to return. Try the following instead:
STDMETHOD (QueryInterface)(REFIID riid, void** ppv)
{
HRESULT hr;
if (IID_ICredentialProviderSetUserArray == riid)
{
*ppv = dynamic_cast<ICredentialProviderSetUserArray>( this );
reinterpret_cast<IUnknown*>(*ppv)->AddRef();
hr = S_OK;
}
else if (IID_IUnknown == riid ||
IID_ICredentialProvider == riid )
{
*ppv = dynamic_cast<ICredentialProvider>( this );
reinterpret_cast<IUnknown*>(*ppv)->AddRef();
hr = S_OK;
}
else
{
*ppv = NULL;
hr = E_NOINTERFACE;
}
return hr;
}