πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.web
Article #989

Connecting IE to a running instance.

#989
From: Enrique
Date: Fri, 07 Oct 2005 23:22
123 lines
5934 bytes
I'm trying to connect to a running instance of Internet Explorer, and then
intercept its events.
I know this is a recurrent question/problem, and there is a lot of
information. But i'm very new and I could not make it work.
I was thinking of using the TCppInternetExplorer to connect to IE.
But I think the BCB help is wrong, it says:
////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
Call ConnectTo to attach to an existing instance of InternetExplorer. The
intf parameter specifies the interface of the server to which you want to
connect. Typically, this value is obtained from a call to GetActiveObject,
which returns an IUnknown interface you can bind to an IWebBrowser2
interface wrapper using the assignment operator:

IUnknown *pUnk;
HResult Result = GetActiveObject(CLSID_InternetExplorer, NULL, &pUnk);
if (Result == S_OK)
{
  IWebBrowser2Ptr WB = pUnk;
  InternetExplorer1->ConnectKind = ckAttachtoInterface;
  InternetExplorer1->ConnectTo(WB);
}

Before calling ConnectTo, set the ConnectKind property to
ckAttachToInterface.
////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
And searching in google i found that GetActiveObject doesn't work with IE.

MSDN has a sample code but I can't understand it (and "translate" it to
BCB):
----------------------------------------------------------------------------
-----------------------------------------------------------
It say:
Add references to Shdocvw.dll and Mshtml.dll to the project:
#import <mshtml.dll> // Internet Explorer 4.0x
#import <mshtml.tlb> // Internet Explorer 5
#import <shdocvw.dll>

I do:
Project - Import Type Library - Microsoft HTML Object Library (version
4.0) - Create Unit. (then i include the unit to my form)
Project - Import Type Library - Microsoft Internet Controls (Version 1.1) -
Create Unit. (it gives me an error: "A class named 'TCppWebBrowser' is
already installed")
----------------------------------------------------------------------------
-----------------------------------------------------------
Then, MSDN:
Declare an instance of an IShellWindows pointer in your view class:
SHDocVw::IShellWindowsPtr m_spSHWinds;
I do that in my TForm header, public section.
But it gives to me compile errors:
E2090 :  Qualifier 'SHDocVw' is not a class or namespace name
So I add the proccesor line:
#import <shdocvw.dll>
and i receive Multiple declaration errors, the multiple declarations are in
"utilcls.h" and "comdef.h"
utilcls.h is included in MSHTML_TLB.h, and i canοΏ½t find comdef.h (i think
it's included by shdocvw.dll)
So I comment the line #include "MSHTML_TLB.h"
Now it compile.
----------------------------------------------------------------------------
-----------------------------------------------------------
MSDN:
Create an instance of a ShellWindows object in your view's constructor:
m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows));
I add this in TForm constructor.
Errors:
E2316 : ShellWindows is not a member of 'SHDocVw'
I don't know how to solve this.
----------------------------------------------------------------------------
-----------------------------------------------------------
finally, MSDN (I add comments in lines that I don't understand (almost all
:-))
Use the ShellWindows object in your view's OnInitialUpdate function:
void CConnectIEView::OnInitialUpdate()    //What's this method? can i create
my own in TForm?
{
   CFormView::OnInitialUpdate(); //and this??

   ASSERT(m_spSHWinds != NULL); //BCB doesn't know ASSERT

   CString strCount;   //BCB doesn't know CString, can i use AnsiString? (or
string...)
   long nCount = m_spSHWinds->GetCount();

   strCount.Format("%i", nCount);
   m_strWinCount = strCount;

   UpdateData(FALSE);  //BCB doesn't know UpdateData

   IDispatchPtr spDisp;
   for (long i = 0; i < nCount; i++)
   {
      _variant_t va(i, VT_I4);  //_variant_t? i must use Variant? or
TVariant?
      spDisp = m_spSHWinds->Item(va);

      SHDocVw::IWebBrowser2Ptr spBrowser(spDisp);    //linker error!
      if (spBrowser != NULL)
      {
         m_ctlListLoc.AddString(spBrowser->GetLocationName());    //what is
m_ctlListLoc??

         MSHTML::IHTMLDocument2Ptr spDoc(spBrowser->GetDocument());
         if (spDoc != NULL)
         {
             m_ctlListTitle.AddString(spDoc->Gettitle());
//and  m_ctlListTitle?
         }
      }
   }
}
----------------------------------------------------------------------------
----------------------------------------------------
Therefore... I don't know how to do it =)
I really need some help.
Thanks you to read me.
enrique.

PD: is it easier to connect if i create the IE instance from my app?... I
mean, the user clicks on a link (_blank taget) on my CppWebBrowser and then
an IE instance is created automatically... and i want to control it too.
Technical Details
Message-ID: <43471a45@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,2fc8286bda6a7885,start
X-Google-Attributes: gidfeeec,public
X-Google-Language: ENGLISH,ASCII
Reply-To: "Enrique" <enridp@yahoo.com.ar>
From: "Enrique" <enridp@yahoo.com.ar>
Newsgroups: borland.public.cppbuilder.internet.web
Subject: Connecting IE to a running instance.
Date: Fri, 7 Oct 2005 20:22:52 -0300
Lines: 126
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 200.43.250.147
Message-ID: <43471a45@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1128733253 200.43.250.147 (7 Oct 2005 18:00:53 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail