Can I create a CommandLink that works the same as the submit button?

依然范特西╮ 提交于 2019-12-24 17:12:04

问题


Please understand my lack of writing skills.

I am testing to make a custom credential provider. I want to create a CommandLink that does the same thing with the submit button. I want to log on through the CommandLink separately from the Submit button. Currently, only the custom credential provider is exposed through the providerFilter::Filter(CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus, DWORD dwFlags, GUID* rgclsidProviders, BOOL* rgbAllow, DWORD cProviders). Click [anathor longon button] to log on.

This is my sample code:

 HRESULT CSampleCredential::CommandLinkClicked(DWORD dwFieldID)
 {
     HRESULT hr = S_OK;
     DWORD dwResult = 0;

     if (dwFieldID < ARRAYSIZE(_rgCredProvFieldDescriptors) &&
         (CPFT_COMMAND_LINK == _rgCredProvFieldDescriptors[dwFieldID].cpft))
     {
         HWND hwndOwner = nullptr;
         switch (dwFieldID)
         {
         case SFI_ANATHOR_SUBMIT_LINK:
             dwResult = function_foo();
             if(dwResult == 1) { 
                  Call GetSerialization()...?
                  Run the logon.
             }
             break;
             // ...
         }
     }
 }

回答1:


Because you are writing credential provider, than you are already implementing ICredentialProvider interface and its Advise method:

    virtual HRESULT STDMETHODCALLTYPE Advise( 
        /* [annotation][in] */ 
        _In_  ICredentialProviderEvents *pcpe,
        /* [annotation][in] */ 
        _In_  UINT_PTR upAdviseContext) = 0;

The first argument is pointer to events interface ICredentialProviderEvents which have only one method: CredentialsChanged. Your task is to grab credentials from user (login/password) store them inside your internals and call this method. On the next turn your provider will be called this method:

    virtual HRESULT STDMETHODCALLTYPE GetCredentialCount( 
        /* [annotation][out] */ 
        _Out_  DWORD *pdwCount,
        /* [annotation][out] */ 
        _Out_  DWORD *pdwDefault,
        /* [annotation][out] */ 
        _Out_  BOOL *pbAutoLogonWithDefault) = 0;

Your task is to return the correct values in pdwDefault and pbAutoLogonWithDefault parameters (my suggest is 0 and TRUE). Than your class that implementing ICredentialProviderCredential interface will be immediately called for GetSerialization method.

Here you can return already stored credentials.



来源:https://stackoverflow.com/questions/51073959/can-i-create-a-commandlink-that-works-the-same-as-the-submit-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!