使用Windows V2凭据提供程序的钻石继承

时间:2015-12-16 18:48:39

标签: c++ winapi credential-providers

以下情况:

我有一个工作的V1 CP,它实现了IConnectableCredentialProviderCredential接口。这种依赖关系对于访问我需要的IQueryContinueWithStatus接口是必要的。

class CCredential : public IConnectableCredentialProviderCredential
{
    [...]

IConnectableCredentialProviderCredential实施ICredentialProviderCredential

使用此代码段完成COM IUknown查询方法:

IFACEMETHODIMP QueryInterface(__in REFIID riid, __deref_out void** ppv)
{
    static const QITAB qitOnlyCredUI[] =
    {
        QITABENT(CCredential, ICredentialProviderCredential),
        { 0 },
    };

    static const QITAB qitFull[] =
    {
        QITABENT(CCredential, ICredentialProviderCredential), // IID_ICredentialProviderCredential
        QITABENT(CCredential, IConnectableCredentialProviderCredential), // IID_IConnectableCredentialProviderCredential            
        { 0 },
    };

[...]

现在我想将提供程序迁移为V2 CP并实现ICredentialProviderCredential2接口,但保持与IQueryContinueWithStatus接口兼容。此外,删除QITABENT(CCredential, ICredentialProviderCredential)是不可取的,因为如果请求CredUI,则qitOnlyCredUI是必需的,这不支持IQueryContinueWithStatus

class CCredential : public IConnectableCredentialProviderCredential,
                    public ICredentialProviderCredential2,
                    public ICredentialProviderCredentialWithFieldOptions
{
    [...]

ICredentialProviderCredential2实施ICredentialProviderCredential

实现COM QueryInterface方法,如:

IFACEMETHODIMP QueryInterface(__in REFIID riid, __deref_out void** ppv)
{
    static const QITAB qitOnlyCredUI[] =
    {
        QITABENT(CCredential, ICredentialProviderCredential),
        { 0 },
    };

    static const QITAB qitFull[] =
    {
        QITABENT(CCredential, ICredentialProviderCredential), // IID_ICredentialProviderCredential
        QITABENT(CCredential, ICredentialProviderCredential2), // IID_ICredentialProviderCredential2
        QITABENT(CCredential, IConnectableCredentialProviderCredential), // IID_IConnectableCredentialProviderCredential            
        QITABENT(CCredential, ICredentialProviderCredentialWithFieldOptions), //IID_ICredentialProviderCredentialWithFieldOptions
        { 0 },
    };

这是钻石问题的开始,因为ICredentialProviderCredential2IConnectableCredentialProviderCredential都实施ICredentialProviderCredential

尝试编译肯定会导致编译器抱怨ICredentialProviderCredential基类的模糊定义。

有关如何实现这一目标的任何想法?

1 个答案:

答案 0 :(得分:1)

您需要为您的案例使用QITABENTMULTI()宏。它记录在shlwapi.h中。我不知道为什么它不在MSDN上。