Serious problem with using AtlAxWin to host Internet Explorer Browser Control 
Author Message
 Serious problem with using AtlAxWin to host Internet Explorer Browser Control

I have narrowed this down to the simplest code that demonstrates the
problem. I know the code below is bad Windows code, but it demonstrates my
problem. Also, sorry for the cross-post, but there are a lot of places that
seem to cover this topic.

I am using the AtlAxWin registered class to host the MSIE control. In the
code below, I have commented out the URL to google.com. If I uncomment that
code, the browser is displayed normal and the google site appears. However,
the documentation says you can pass HTML to initialize the control, prefaced
with mshtml:. That works, however, if you initialize the control this way,
the call to pUnknown->QueryInterface() for the IWebBrowser2 object will fail
and return a NULL pointer. If I comment out the line that shows HTML and
instead use the URL to www.google.com, the call to
pUnknown->QueryInterface() returns a valid pointer. What is really weird, if
I pass the HTML instead of the URL, the control is created and displays the
HTML I pass, even though I could not get the pointer to the IWebBrowser2
object. Even stranger, when you choose the "Show Source" from the MSIE
window, the source is shows is not for the HTML that it is displaying. Very
weird. I am testing this with MSIE 6.0 on Windows 2000 Pro, all service
packs applied. Visual C++ 6.0 with SP5 installed. I appreciate any help you
can give.

Todd

/* Include ATL control containment.*/
#include <atldef.h>
 #define _ATL_DLL_IMPL
#include <atliface.h>

#include <exdisp.h>

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
 /* Initialize ATL control containment code.*/
 AtlAxWinInit();

 /* Create the web browser window.*/
 HWND hWnd = ::CreateWindow(
  "AtlAxWin",
  //" http://www.*-*-*.com/ ",
  "mshtml:<h1>Hello world</h1>",
  WS_OVERLAPPEDWINDOW | WS_VISIBLE,
  100,
  100,
  600,
  600,
  NULL,
  NULL,
  hInstance,
  NULL);

 ShowWindow(hWnd, SW_SHOWNORMAL);
 UpdateWindow(hWnd);

 IUnknown* pUnknown = NULL;
 AtlAxGetControl(hWnd, &pUnknown);

 IWebBrowser2* pBrowser = NULL;
 pUnknown->QueryInterface(IID_IWebBrowser2, (void**)&pBrowser);

 MSG msg;

 while ( GetMessage(&msg, NULL, 0, 0) )
  DispatchMessage(&msg);

 return 0;

Quote:
}



Tue, 18 May 2004 01:14:25 GMT  
 Serious problem with using AtlAxWin to host Internet Explorer Browser Control
Hello Todd,

The answer is simple - have a look at "CreateNormalizedObject" function from
AtlHost.h, line 60. it creates HTML document object (CLSID_HTMLDocument) for
MSHTML: protocol, and WebBrowser control (CLSID_WebBrowser) for
www.google.com URL. So query for IID_IHTMLDocument2 in first case to access
object model.

--
Best regards,
Vadim Melnik,
_____________________
http://www.docsultant.com/


Quote:
> I have narrowed this down to the simplest code that demonstrates the
> problem. I know the code below is bad Windows code, but it demonstrates my
> problem. Also, sorry for the cross-post, but there are a lot of places
that
> seem to cover this topic.

> I am using the AtlAxWin registered class to host the MSIE control. In the
> code below, I have commented out the URL to google.com. If I uncomment
that
> code, the browser is displayed normal and the google site appears.
However,
> the documentation says you can pass HTML to initialize the control,
prefaced
> with mshtml:. That works, however, if you initialize the control this way,
> the call to pUnknown->QueryInterface() for the IWebBrowser2 object will
fail
> and return a NULL pointer. If I comment out the line that shows HTML and
> instead use the URL to www.google.com, the call to
> pUnknown->QueryInterface() returns a valid pointer. What is really weird,
if
> I pass the HTML instead of the URL, the control is created and displays
the
> HTML I pass, even though I could not get the pointer to the IWebBrowser2
> object. Even stranger, when you choose the "Show Source" from the MSIE
> window, the source is shows is not for the HTML that it is displaying.
Very
> weird. I am testing this with MSIE 6.0 on Windows 2000 Pro, all service
> packs applied. Visual C++ 6.0 with SP5 installed. I appreciate any help
you
> can give.

> Todd

> /* Include ATL control containment.*/
> #include <atldef.h>
>  #define _ATL_DLL_IMPL
> #include <atliface.h>

> #include <exdisp.h>

> int APIENTRY WinMain(HINSTANCE hInstance,
>                      HINSTANCE hPrevInstance,
>                      LPSTR     lpCmdLine,
>                      int       nCmdShow)
> {
>  /* Initialize ATL control containment code.*/
>  AtlAxWinInit();

>  /* Create the web browser window.*/
>  HWND hWnd = ::CreateWindow(
>   "AtlAxWin",
>   //"http://www.google.com",
>   "mshtml:<h1>Hello world</h1>",
>   WS_OVERLAPPEDWINDOW | WS_VISIBLE,
>   100,
>   100,
>   600,
>   600,
>   NULL,
>   NULL,
>   hInstance,
>   NULL);

>  ShowWindow(hWnd, SW_SHOWNORMAL);
>  UpdateWindow(hWnd);

>  IUnknown* pUnknown = NULL;
>  AtlAxGetControl(hWnd, &pUnknown);

>  IWebBrowser2* pBrowser = NULL;
>  pUnknown->QueryInterface(IID_IWebBrowser2, (void**)&pBrowser);

>  MSG msg;

>  while ( GetMessage(&msg, NULL, 0, 0) )
>   DispatchMessage(&msg);

>  return 0;
> }



Tue, 18 May 2004 02:02:07 GMT  
 Serious problem with using AtlAxWin to host Internet Explorer Browser Control
I took  a look at the code and see what you mean. This is my first time
playing with the MSIE control and interfaces. Given the IHTMLDocument2
interface (which I can get), how do I get the IWebBrowser2 interface? I
tried querying for it from the IHTMLDocument2 object, but it returned NULL.
What is the relationship, or can you point me to someplace on the net that
discusses it? Thanks,

Todd


Quote:
> Hello Todd,

> The answer is simple - have a look at "CreateNormalizedObject" function
from
> AtlHost.h, line 60. it creates HTML document object (CLSID_HTMLDocument)
for
> MSHTML: protocol, and WebBrowser control (CLSID_WebBrowser) for
> www.google.com URL. So query for IID_IHTMLDocument2 in first case to
access
> object model.

> --
> Best regards,
> Vadim Melnik,
> _____________________
> http://www.docsultant.com/



> > I have narrowed this down to the simplest code that demonstrates the
> > problem. I know the code below is bad Windows code, but it demonstrates
my
> > problem. Also, sorry for the cross-post, but there are a lot of places
> that
> > seem to cover this topic.

> > I am using the AtlAxWin registered class to host the MSIE control. In
the
> > code below, I have commented out the URL to google.com. If I uncomment
> that
> > code, the browser is displayed normal and the google site appears.
> However,
> > the documentation says you can pass HTML to initialize the control,
> prefaced
> > with mshtml:. That works, however, if you initialize the control this
way,
> > the call to pUnknown->QueryInterface() for the IWebBrowser2 object will
> fail
> > and return a NULL pointer. If I comment out the line that shows HTML and
> > instead use the URL to www.google.com, the call to
> > pUnknown->QueryInterface() returns a valid pointer. What is really
weird,
> if
> > I pass the HTML instead of the URL, the control is created and displays
> the
> > HTML I pass, even though I could not get the pointer to the IWebBrowser2
> > object. Even stranger, when you choose the "Show Source" from the MSIE
> > window, the source is shows is not for the HTML that it is displaying.
> Very
> > weird. I am testing this with MSIE 6.0 on Windows 2000 Pro, all service
> > packs applied. Visual C++ 6.0 with SP5 installed. I appreciate any help
> you
> > can give.

> > Todd

> > /* Include ATL control containment.*/
> > #include <atldef.h>
> >  #define _ATL_DLL_IMPL
> > #include <atliface.h>

> > #include <exdisp.h>

> > int APIENTRY WinMain(HINSTANCE hInstance,
> >                      HINSTANCE hPrevInstance,
> >                      LPSTR     lpCmdLine,
> >                      int       nCmdShow)
> > {
> >  /* Initialize ATL control containment code.*/
> >  AtlAxWinInit();

> >  /* Create the web browser window.*/
> >  HWND hWnd = ::CreateWindow(
> >   "AtlAxWin",
> >   //"http://www.google.com",
> >   "mshtml:<h1>Hello world</h1>",
> >   WS_OVERLAPPEDWINDOW | WS_VISIBLE,
> >   100,
> >   100,
> >   600,
> >   600,
> >   NULL,
> >   NULL,
> >   hInstance,
> >   NULL);

> >  ShowWindow(hWnd, SW_SHOWNORMAL);
> >  UpdateWindow(hWnd);

> >  IUnknown* pUnknown = NULL;
> >  AtlAxGetControl(hWnd, &pUnknown);

> >  IWebBrowser2* pBrowser = NULL;
> >  pUnknown->QueryInterface(IID_IWebBrowser2, (void**)&pBrowser);

> >  MSG msg;

> >  while ( GetMessage(&msg, NULL, 0, 0) )
> >   DispatchMessage(&msg);

> >  return 0;
> > }



Tue, 18 May 2004 03:22:17 GMT  
 Serious problem with using AtlAxWin to host Internet Explorer Browser Control

Quote:
> I took  a look at the code and see what you mean. This is my first time
> playing with the MSIE control and interfaces. Given the IHTMLDocument2
> interface (which I can get), how do I get the IWebBrowser2 interface? I
> tried querying for it from the IHTMLDocument2 object, but it returned
NULL.
> What is the relationship, or can you point me to someplace on the net that
> discusses it? Thanks,

You can't get IWebBrowser2 interface for separate MSHTML object. I'd
recommend you MSDN documentation, [1]. It describes IE browser architecture
and illustrates differences between WebBrowser control and MSHTML engine
object.

[1]
http://msdn.microsoft.com/workshop/browser/overview/overview.asp?fram...
Architectural_Overvi

Cheers,
--
Cheers,Vadim Melnik,
____________________
http://www.docsultant.com/

Quote:

> Todd



> > Hello Todd,

> > The answer is simple - have a look at "CreateNormalizedObject" function
> from
> > AtlHost.h, line 60. it creates HTML document object (CLSID_HTMLDocument)
> for
> > MSHTML: protocol, and WebBrowser control (CLSID_WebBrowser) for
> > www.google.com URL. So query for IID_IHTMLDocument2 in first case to
> access
> > object model.

> > --
> > Best regards,
> > Vadim Melnik,
> > _____________________
> > http://www.docsultant.com/



> > > I have narrowed this down to the simplest code that demonstrates the
> > > problem. I know the code below is bad Windows code, but it
demonstrates
> my
> > > problem. Also, sorry for the cross-post, but there are a lot of places
> > that
> > > seem to cover this topic.

> > > I am using the AtlAxWin registered class to host the MSIE control. In
> the
> > > code below, I have commented out the URL to google.com. If I uncomment
> > that
> > > code, the browser is displayed normal and the google site appears.
> > However,
> > > the documentation says you can pass HTML to initialize the control,
> > prefaced
> > > with mshtml:. That works, however, if you initialize the control this
> way,
> > > the call to pUnknown->QueryInterface() for the IWebBrowser2 object
will
> > fail
> > > and return a NULL pointer. If I comment out the line that shows HTML
and
> > > instead use the URL to www.google.com, the call to
> > > pUnknown->QueryInterface() returns a valid pointer. What is really
> weird,
> > if
> > > I pass the HTML instead of the URL, the control is created and
displays
> > the
> > > HTML I pass, even though I could not get the pointer to the
IWebBrowser2
> > > object. Even stranger, when you choose the "Show Source" from the MSIE
> > > window, the source is shows is not for the HTML that it is displaying.
> > Very
> > > weird. I am testing this with MSIE 6.0 on Windows 2000 Pro, all
service
> > > packs applied. Visual C++ 6.0 with SP5 installed. I appreciate any
help
> > you
> > > can give.

> > > Todd

> > > /* Include ATL control containment.*/
> > > #include <atldef.h>
> > >  #define _ATL_DLL_IMPL
> > > #include <atliface.h>

> > > #include <exdisp.h>

> > > int APIENTRY WinMain(HINSTANCE hInstance,
> > >                      HINSTANCE hPrevInstance,
> > >                      LPSTR     lpCmdLine,
> > >                      int       nCmdShow)
> > > {
> > >  /* Initialize ATL control containment code.*/
> > >  AtlAxWinInit();

> > >  /* Create the web browser window.*/
> > >  HWND hWnd = ::CreateWindow(
> > >   "AtlAxWin",
> > >   //"http://www.google.com",
> > >   "mshtml:<h1>Hello world</h1>",
> > >   WS_OVERLAPPEDWINDOW | WS_VISIBLE,
> > >   100,
> > >   100,
> > >   600,
> > >   600,
> > >   NULL,
> > >   NULL,
> > >   hInstance,
> > >   NULL);

> > >  ShowWindow(hWnd, SW_SHOWNORMAL);
> > >  UpdateWindow(hWnd);

> > >  IUnknown* pUnknown = NULL;
> > >  AtlAxGetControl(hWnd, &pUnknown);

> > >  IWebBrowser2* pBrowser = NULL;
> > >  pUnknown->QueryInterface(IID_IWebBrowser2, (void**)&pBrowser);

> > >  MSG msg;

> > >  while ( GetMessage(&msg, NULL, 0, 0) )
> > >   DispatchMessage(&msg);

> > >  return 0;
> > > }



Tue, 18 May 2004 04:04:17 GMT  
 Serious problem with using AtlAxWin to host Internet Explorer Browser Control
Thanks for your help, I really appreciate it. Off for some more reading...
:)

Todd


Quote:
> > I took  a look at the code and see what you mean. This is my first time
> > playing with the MSIE control and interfaces. Given the IHTMLDocument2
> > interface (which I can get), how do I get the IWebBrowser2 interface? I
> > tried querying for it from the IHTMLDocument2 object, but it returned
> NULL.
> > What is the relationship, or can you point me to someplace on the net
that
> > discusses it? Thanks,

> You can't get IWebBrowser2 interface for separate MSHTML object. I'd
> recommend you MSDN documentation, [1]. It describes IE browser
architecture
> and illustrates differences between WebBrowser control and MSHTML engine
> object.

> [1]

http://msdn.microsoft.com/workshop/browser/overview/overview.asp?fram...

- Show quoted text -

Quote:
> Architectural_Overvi

> Cheers,
> --
> Cheers,Vadim Melnik,
> ____________________
> http://www.docsultant.com/

> > Todd



> > > Hello Todd,

> > > The answer is simple - have a look at "CreateNormalizedObject"
function
> > from
> > > AtlHost.h, line 60. it creates HTML document object

(CLSID_HTMLDocument)

- Show quoted text -

Quote:
> > for
> > > MSHTML: protocol, and WebBrowser control (CLSID_WebBrowser) for
> > > www.google.com URL. So query for IID_IHTMLDocument2 in first case to
> > access
> > > object model.

> > > --
> > > Best regards,
> > > Vadim Melnik,
> > > _____________________
> > > http://www.docsultant.com/



> > > > I have narrowed this down to the simplest code that demonstrates the
> > > > problem. I know the code below is bad Windows code, but it
> demonstrates
> > my
> > > > problem. Also, sorry for the cross-post, but there are a lot of
places
> > > that
> > > > seem to cover this topic.

> > > > I am using the AtlAxWin registered class to host the MSIE control.
In
> > the
> > > > code below, I have commented out the URL to google.com. If I
uncomment
> > > that
> > > > code, the browser is displayed normal and the google site appears.
> > > However,
> > > > the documentation says you can pass HTML to initialize the control,
> > > prefaced
> > > > with mshtml:. That works, however, if you initialize the control
this
> > way,
> > > > the call to pUnknown->QueryInterface() for the IWebBrowser2 object
> will
> > > fail
> > > > and return a NULL pointer. If I comment out the line that shows HTML
> and
> > > > instead use the URL to www.google.com, the call to
> > > > pUnknown->QueryInterface() returns a valid pointer. What is really
> > weird,
> > > if
> > > > I pass the HTML instead of the URL, the control is created and
> displays
> > > the
> > > > HTML I pass, even though I could not get the pointer to the
> IWebBrowser2
> > > > object. Even stranger, when you choose the "Show Source" from the
MSIE
> > > > window, the source is shows is not for the HTML that it is
displaying.
> > > Very
> > > > weird. I am testing this with MSIE 6.0 on Windows 2000 Pro, all
> service
> > > > packs applied. Visual C++ 6.0 with SP5 installed. I appreciate any
> help
> > > you
> > > > can give.

> > > > Todd

> > > > /* Include ATL control containment.*/
> > > > #include <atldef.h>
> > > >  #define _ATL_DLL_IMPL
> > > > #include <atliface.h>

> > > > #include <exdisp.h>

> > > > int APIENTRY WinMain(HINSTANCE hInstance,
> > > >                      HINSTANCE hPrevInstance,
> > > >                      LPSTR     lpCmdLine,
> > > >                      int       nCmdShow)
> > > > {
> > > >  /* Initialize ATL control containment code.*/
> > > >  AtlAxWinInit();

> > > >  /* Create the web browser window.*/
> > > >  HWND hWnd = ::CreateWindow(
> > > >   "AtlAxWin",
> > > >   //"http://www.google.com",
> > > >   "mshtml:<h1>Hello world</h1>",
> > > >   WS_OVERLAPPEDWINDOW | WS_VISIBLE,
> > > >   100,
> > > >   100,
> > > >   600,
> > > >   600,
> > > >   NULL,
> > > >   NULL,
> > > >   hInstance,
> > > >   NULL);

> > > >  ShowWindow(hWnd, SW_SHOWNORMAL);
> > > >  UpdateWindow(hWnd);

> > > >  IUnknown* pUnknown = NULL;
> > > >  AtlAxGetControl(hWnd, &pUnknown);

> > > >  IWebBrowser2* pBrowser = NULL;
> > > >  pUnknown->QueryInterface(IID_IWebBrowser2, (void**)&pBrowser);

> > > >  MSG msg;

> > > >  while ( GetMessage(&msg, NULL, 0, 0) )
> > > >   DispatchMessage(&msg);

> > > >  return 0;
> > > > }



Tue, 18 May 2004 05:10:29 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Internet Explorer Events with Browser Control in MFC ?

2. Problem trying to implement custom class factory for an Internet Explorer Browser Helper Object

3. Problem trying to implement custom class factory for an Internet Explorer Browser Helper Object

4. Using CAxWindow to host a browser control

5. Creating Windows Forms Controls for Internet Explorer using Managed C++

6. Using windows forms controls in internet explorer

7. MFX ActiveX control using Internet Explorer like container

8. Problem Hosting ActiveX Controls Using ATL AXHost (CAxWindow2) using VC7

9. Web Browser Control/Explorer Control/HTML Control

10. Please help me again......about debugging together with browser Internet Explorer 4.0

11. Internet Explorer Browser Class

12. Retrieve IHtmlDocument2 interface from a hosted web browser control

 

 
Powered by phpBB® Forum Software