Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Webbrowser2 using ATL (http://www.go4expert.com/forums/webbrowser2-using-atl-t12824/)

cvarga 9Aug2008 22:49

Webbrowser2 using ATL
 
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;
}
}
}


All times are GMT +5.5. The time now is 14:06.