none
Do not get the Authenticate event from interface IAuthenticate RRS feed

  • Pregunta

  • I'm maintaining a legacy program using Visual C + + 6.0. I want to bypass the username or password dialog box of Explorer for which I followed the article http://support.microsoft.com/kb/320153.
    But my problem is that I never get the Authenticate event

    thanks in advance

    Here is my code:

    // File header:

    class CWebBrowser : public CWnd
    {
    private:
        CWnd * m_pParent;
    ...
    protected:
        DECLARE_DYNCREATE(CWebBrowser)

    public:
        CLSID const& GetClsid(int control = 0)    // 0 = WB, 1 = IE
        {
            // 0002DF01-0000-0000-C000-000000000046
            static CLSID const clsid_IE
                = { 0x0002DF01, 0x0000, 0x0000, { 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } };

            // 8856f961-340a-11d0-a96b-00c04fd705a2
            static CLSID const clsid_WB
                = { 0x8856f961, 0x340a, 0x11d0, { 0xa9, 0x6b, 0x00, 0xc0, 0x4f, 0xd7, 0x05, 0xa2 } };

            return control ? clsid_IE : clsid_WB;
        }

        CWebBrowser();
        ~CWebBrowser();

    // Operations
    public:
    ....

    protected:
    ...
        afx_msg void OnBeforeNavigate(LPDISPATCH pDisp, VARIANT FAR* URL, VARIANT FAR* Flags, VARIANT FAR* TargetFrameName, VARIANT FAR* PostData, VARIANT FAR* Headers, BOOL FAR* Cancel);
        afx_msg void OnNavigateComplete(LPDISPATCH pDisp, VARIANT FAR* URL);
        afx_msg void OnNewWindow(LPDISPATCH FAR* ppDisp, BOOL FAR* Cancel);
        afx_msg void OnDownloadBegin();
        afx_msg void OnDownloadComplete();
        afx_msg void OnDocumentComplete(LPDISPATCH pDisp, VARIANT FAR* URL);
        afx_msg void OnQuit();
        afx_msg void OnWindowClosing(BOOL IsChildWindow, BOOL FAR* Cancel);
       afx_msg void OnActivate( UINT nState, CWnd* pWndOther, BOOL bMinimized );
       afx_msg void OnTitleChange(LPCTSTR lpszText);

        DECLARE_MESSAGE_MAP()
        DECLARE_EVENTSINK_MAP()
        DECLARE_DISPATCH_MAP()



        DECLARE_INTERFACE_MAP()

        BEGIN_INTERFACE_PART(OleClientSite, IOleClientSite)
            STDMETHODIMP SaveObject(void);
            STDMETHODIMP GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker, IMoniker** ppmk);
            STDMETHODIMP GetContainer(IOleContainer** ppContainer);
            STDMETHODIMP ShowObject(void);
            STDMETHODIMP OnShowWindow(BOOL fShow);
            STDMETHODIMP RequestNewObjectLayout(void);
        END_INTERFACE_PART(OleClientSite)

        ///////////////////////////////////////
        //// Implement IServiceProvider
        BEGIN_INTERFACE_PART(ServiceProvider, IServiceProvider)
            STDMETHOD(QueryService)(REFGUID,REFIID,void**);
        END_INTERFACE_PART(ServiceProvider)

        ///////////////////////////////////////
        //// Implement IAuthenticate

        BEGIN_INTERFACE_PART(Authenticate, IAuthenticate)

            STDMETHODIMP Authenticate(
                HWND __RPC_FAR *phwnd,
                LPWSTR __RPC_FAR *pszUsername,
                LPWSTR __RPC_FAR *pszPassword);

        END_INTERFACE_PART(Authenticate)
    };

    //

    BEGIN_INTERFACE_MAP(CWebBrowser, CWnd)
        INTERFACE_PART(CWebBrowser, DIID_HTMLDocumentEvents, Dispatch)
        INTERFACE_PART(CWebBrowser, DIID_DWebBrowserEvents2, Dispatch)
        INTERFACE_PART(CWebBrowser, IID_IServiceProvider, ServiceProvider)
        INTERFACE_PART(CWebBrowser, IID_IAuthenticate, Authenticate)
        INTERFACE_PART(CWebBrowser, IID_IOleClientSite, OleClientSite)
    END_INTERFACE_MAP()


    STDMETHODIMP_(ULONG) CWebBrowser::XOleClientSite::AddRef()   
    {   
         METHOD_PROLOGUE(CWebBrowser, OleClientSite)   

        return pThis->InternalAddRef();   
    }   
       
    STDMETHODIMP_(ULONG) CWebBrowser::XOleClientSite::Release()   
    {   
        METHOD_PROLOGUE(CWebBrowser, OleClientSite)   

        return pThis->InternalRelease();   
    }   
       
    STDMETHODIMP CWebBrowser::XOleClientSite::QueryInterface(   
        REFIID iid, LPVOID* ppvObj)   
    {   
         METHOD_PROLOGUE(CWebBrowser, OleClientSite)   

        return pThis->InternalQueryInterface(&iid, ppvObj);   
    }   
       
    STDMETHODIMP CWebBrowser::XOleClientSite::SaveObject()   
    {   
        METHOD_PROLOGUE(CWebBrowser, OleClientSite)   

        return E_NOTIMPL;   
    }   
       
    STDMETHODIMP CWebBrowser::XOleClientSite::GetMoniker(   
        DWORD dwAssign, DWORD dwWhichMoniker, LPMONIKER* ppMoniker)   
    {   
        return E_NOTIMPL;   
    }   
       
    STDMETHODIMP CWebBrowser::XOleClientSite::GetContainer(   
        LPOLECONTAINER* ppContainer)   
    {   
        return E_NOTIMPL;   
    }   
       
    STDMETHODIMP CWebBrowser::XOleClientSite::ShowObject()   
    {   
        METHOD_PROLOGUE(CWebBrowser, OleClientSite)   

        return E_NOTIMPL;   
    }   
       
    STDMETHODIMP CWebBrowser::XOleClientSite::OnShowWindow(BOOL fShow)   
    {   
        METHOD_PROLOGUE(CWebBrowser, OleClientSite)   

        return E_NOTIMPL;   
    }   
       
    STDMETHODIMP CWebBrowser::XOleClientSite::RequestNewObjectLayout()   
    {   
        return E_NOTIMPL;   
    }   


    /////////////////////////////////////////////////////////////
    // ServiceProvider Methods
    ULONG FAR EXPORT CWebBrowser::XServiceProvider::AddRef()
    {
        METHOD_PROLOGUE(CWebBrowser, ServiceProvider)
        return pThis->ExternalAddRef();
    }

    ULONG FAR EXPORT CWebBrowser::XServiceProvider::Release()
    {                            
        METHOD_PROLOGUE(CWebBrowser, ServiceProvider)

        return pThis->ExternalRelease();
    }

    HRESULT FAR EXPORT CWebBrowser::XServiceProvider::QueryInterface(REFIID riid,
        void** ppvObj)
    {
        METHOD_PROLOGUE(CWebBrowser, ServiceProvider)

        HRESULT hr = (HRESULT)pThis->ExternalQueryInterface(&riid, ppvObj);
        return hr;
    }

    STDMETHODIMP CWebBrowser::XServiceProvider::QueryService(REFGUID guidService,  
        REFIID riid,
        void** ppvObject)
    {
        METHOD_PROLOGUE(CWebBrowser, ServiceProvider);

        if (guidService == IID_IAuthenticate &&
            riid == IID_IAuthenticate)
        {
            HRESULT hr = (HRESULT)pThis->ExternalQueryInterface(&riid, ppvObject);
            return hr;
        }
        else
        {
            *ppvObject = NULL;

        }
        return E_NOINTERFACE;
    }

    //
    // IAuthenticate
    //
    ULONG FAR EXPORT CWebBrowser::XAuthenticate::AddRef()
    {
        METHOD_PROLOGUE(CWebBrowser, Authenticate)
        return pThis->ExternalAddRef();
    }

    ULONG FAR EXPORT CWebBrowser::XAuthenticate::Release()
    {                            
        METHOD_PROLOGUE(CWebBrowser, Authenticate)
        return pThis->ExternalRelease();
    }

    HRESULT FAR EXPORT CWebBrowser::XAuthenticate::QueryInterface(REFIID
        riid, void **ppvObj)
    {
        METHOD_PROLOGUE(CWebBrowser, Authenticate)
        HRESULT hr = (HRESULT)pThis->ExternalQueryInterface(&riid, ppvObj);
        return hr;
    }

    HRESULT FAR EXPORT CWebBrowser::XAuthenticate::Authenticate(
        /* [out] */ HWND *phwnd,
        /* [out] */ LPWSTR *pszUsername,
        /* [out] */ LPWSTR *pszPassword)
    {
        METHOD_PROLOGUE(CWebBrowser, Authenticate)

        CString strUsername = "user";
        CString strPassword = "password";
        
        WCHAR *wszDlgUser = (WCHAR *) CoTaskMemAlloc(255 * sizeof(WCHAR));
        WCHAR *wszDlgPassword = (WCHAR *) CoTaskMemAlloc(255 * sizeof(WCHAR));
        MultiByteToWideChar(GetACP(), 0, (const char*)strUsername, -1, wszDlgUser, 255);
        MultiByteToWideChar(GetACP(), 0, (const char*)strPassword, -1, wszDlgPassword, 255);
        *pszUsername = wszDlgUser;
        *pszPassword = wszDlgPassword;
        *phwnd = NULL;

        return S_OK;

    viernes, 22 de febrero de 2013 13:45

Respuestas