๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Connecting IE to a running instance.

#992
From: Enrique
Date: Mon, 10 Oct 2005 19:43
267 lines
8339 bytes
thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks
thanks thanks thanks thanks, thank you !!!
It works ! (adding "$(BCB)\include\atl" to the include path)
But it gives an access violation error when I close the program. Commenting
the sentence: CoUninitialize(); this error doesn't appear. Any ideas? it's
neccessary call to CoUninitialize();?

bye ! and thanks again !

"gizmo" <_gizmo@mail.ru> escribi๏ฟฝ en el mensaje
news:434a0cb3$1@newsgroups.borland.com...
>
> "Enrique" <enridp@yahoo.com.ar> wrote:
>
> [skip]
>
> >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")
>
> The #import directive is included for Microsoft compatibility only. Its
use is generally not recommended. You should use the Import Type Library
command or TLIBIMP.EXE when importing type libraries.
> Do it:
> $(BCB)\BIN\TLIBIMP.EXE -c:\windows\system32\shdocvw.dll
>
>
>---------------------------------------------------------------------------
-
> >-----------------------------------------------------------
> >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.
>
> in this case:
> SHDocVw_TLB::ShellWindows
>
>
>---------------------------------------------------------------------------
-
> >-----------------------------------------------------------
> >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?
>
> throw this...
>
> >{
> >   CFormView::OnInitialUpdate(); //and this??
>
> and this...
>
> >
> >   ASSERT(m_spSHWinds != NULL); //BCB doesn't know ASSERT
>
> and this...
>
> >
> >   CString strCount;   //BCB doesn't know CString, can i use AnsiString?
(or
> >string...)
>
> Yes, AnsiString
>
> >   long nCount = m_spSHWinds->GetCount();
> >
> >   strCount.Format("%i", nCount);
> >   m_strWinCount = strCount;
> >
> >   UpdateData(FALSE);  //BCB doesn't know UpdateData
>
> all is MFC...throw
>
> >
> >   IDispatchPtr spDisp;
> >   for (long i = 0; i < nCount; i++)
> >   {
> >      _variant_t va(i, VT_I4);  //_variant_t? i must use Variant? or
> >TVariant?
>
> yes...
>
> >      spDisp = m_spSHWinds->Item(va);
> >
> >      SHDocVw::IWebBrowser2Ptr spBrowser(spDisp);    //linker error!
>
> need add to project SHDocVw_TLB.cpp.
>
> >      if (spBrowser != NULL)
> >      {
> >         m_ctlListLoc.AddString(spBrowser->GetLocationName());    //what
is
> >m_ctlListLoc??
>
> use TListBox...
>
> >
> >         MSHTML::IHTMLDocument2Ptr spDoc(spBrowser->GetDocument());
> >         if (spDoc != NULL)
> >         {
> >             m_ctlListTitle.AddString(spDoc->Gettitle());
> >//and  m_ctlListTitle?
> >         }
> >      }
> >   }
> >}
>
> sorry my english is bad...
> Your can do it:
>
>
> #ifndef MainH
> #define MainH
>
//--------------------------------------------------------------------------
-
> #include <Classes.hpp>
> #include <Controls.hpp>
> #include <StdCtrls.hpp>
> #include <Forms.hpp>
> // for CComPtr
> #include <atlbase.h>
> // ShellWindows
> #include <exdisp.h>
> // MSHTML
> #include <mshtml.h>
>
>
//--------------------------------------------------------------------------
-
> class TForm1 : public TForm
> {
> __published: // IDE-managed Components
>     TPanel *Panel1;
>     TButton *Button1;
>     TListBox *ListBox1;
>     TMemo *Memo1;
>     TSplitter *Splitter1;
>     void __fastcall FormCreate(TObject *Sender);
>     void __fastcall FormDestroy(TObject *Sender);
> private: // User declarations
>     CComPtr<IShellWindows> m_spSHWinds;
> public: // User declarations
>     __fastcall TForm1(TComponent* Owner);
> };
>
//--------------------------------------------------------------------------
-
> extern PACKAGE TForm1 *Form1;
>
//--------------------------------------------------------------------------
-
> #endif
>
>
//--------------------------------------------------------------------------
-
>
> #include <vcl.h>
> #pragma hdrstop
>
> #include "Main.h"
>
//--------------------------------------------------------------------------
-
> #pragma package(smart_init)
> #pragma resource "*.dfm"
> TForm1 *Form1;
>
//--------------------------------------------------------------------------
-
> __fastcall TForm1::TForm1(TComponent* Owner)
>     : TForm(Owner)
> {
>
> }
>
//--------------------------------------------------------------------------
-
> void __fastcall TForm1::FormCreate(TObject *Sender)
> {
>     // initialize COM
>     CoInitialize(NULL);
>
>     if (FAILED(m_spSHWinds.CoCreateInstance( __uuidof( ShellWindows))))
>         ShowMessage("Couldn't create object ShellWindows");
>
>     // get count windows
>     LONG nCount;
>     m_spSHWinds->get_Count( &nCount);
>
>     for (int i=0; i<nCount; i++)
>     {
>         // get next window
>         CComPtr<IDispatch> pDisp;
>         m_spSHWinds->Item( CComVariant(i), &pDisp);
>         CComQIPtr<IWebBrowser2> pIE( pDisp);
>         if (pIE == NULL)
>             ShowMessage("Unable to query Internet Explorer object");
>
>         // get URL
>         USES_CONVERSION;
>         CComBSTR bsUrl;
>         pIE->get_LocationURL( &bsUrl);
>         LPTSTR lpstrUrl = W2T(bsUrl);
>
>         // trying htmldoc
>         CComPtr<IDispatch> pDispDoc;
>         pIE->get_Document( &pDispDoc);
>         CComQIPtr<IHTMLDocument2> pHtmlDoc( pDispDoc);
>
>         // if Ok, - Internet Explorer
>         if (pHtmlDoc)
>         {
>             //pHtmlDoc->put_bgColor( CComVariant( L"blue"));
>             ListBox1->Items->Add(lpstrUrl);
>             // connect events
>             //...
>         }
>         // else - Explorer
>         else
>         {
>             //ListBox1->Items->Add("  Window Explorer: ");
>             // close window
>             //pIE->Quit();
>         }
>     }
> }
>
//--------------------------------------------------------------------------
-
> void __fastcall TForm1::FormDestroy(TObject *Sender)
> {
>     CoUninitialize();
> }
>
//--------------------------------------------------------------------------
-
>
>
Technical Details
Message-ID: <434b0204@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!proxad.net!194.117.148.138.MISMATCH!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <43471a45@newsgroups.borland.com> <434a0cb3$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,2fc8286bda6a7885
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
References:  <43471a45@newsgroups.borland.com> <434a0cb3$1@newsgroups.borland.com>
Subject: Re: Connecting IE to a running instance.
Date: Mon, 10 Oct 2005 16:43:53 -0300
Lines: 269
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.99.23
Message-ID: <434b0204@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1128989188 200.43.99.23 (10 Oct 2005 17:06:28 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!proxad.net!194.117.148.138.MISMATCH!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail