Webbrowser2 using ATL

Discussion in 'C' started by cvarga, Aug 9, 2008.

  1. cvarga

    cvarga New Member

    Joined:
    Aug 8, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Hey guys,

    I'm having an issue with the iwebrowser2 interface. I am using atl's ccomptr to create an instance of the interface which works fine, but when I call the navigate2 function it is returning and E_FAIL hresult and I can't figure out why. Here is a sample of the code I am using. I am calling this c++ class from c win32 code and do not want to use MFC do to the issues with afx and win32 applications. If you could help me out I would greatly appreciate it.

    #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers

    /* Class COM Methods */

    //#include <afxdisp.h>
    #include <comdef.h>
    #include <atlbase.h>
    #include <exdisp.h>

    CAtlComModule _Module;

    #include <atlcom.h>

    #include "iexcpp.h"

    /* C++ Code */

    extern Iex *pIex;

    /*Bfun ************************* *Efun*/

    bool Iex::IexCreateBrowser( char * url )
    {
    CComPtr<IWebBrowser2> lpTBrowser;
    // CComPtr<IDispatch> lpTDispatch;
    LPUNKNOWN pUnkOuter = NULL;
    DWORD dwClsContext = CLSCTX_ALL;
    DWORD dwFlags = 0;
    HRESULT hrl = 0;
    VARIANT vEmpty;
    BSTR bstrName;

    VariantInit(&vEmpty);

    CoInitialize(NULL);

    //Create web browser using IWebBrowser2...
    hrl = lpTBrowser.CoCreateInstance( CLSID_WebBrowser, pUnkOuter, dwClsContext );

    if(!SUCCEEDED(hrl))
    return false;

    lpTBrowser->get_FullName( &bstrName );

    if( url == NULL )
    return true;
    else
    { hrl = lpTBrowser->Navigate2( &_variant_t(url), &_variant_t( dwFlags ), &vEmpty, &vEmpty, &vEmpty );
    if(!SUCCEEDED(hrl))
    return false;
    else
    { lpTBrowser->put_Visible( _variant_t( true ) );
    return true;
    }
    }
    }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice