?
Solved

How to Monitor Events in Explorer

Posted on 2003-02-20
5
Medium Priority
?
1,062 Views
Last Modified: 2013-11-20
Hi All!

I find that I can create an instance of Windows Explorer and monitor its' internet traffic events like this:

  HRESULT hr = CoCreateInstance( CLSID_ShellBrowserWindow, // Creates an Instance of Windows Explorer.
                                 NULL,
                                 CLSCTX_LOCAL_SERVER,
                                 IID_IWebBrowser2,
                                 (void**)&m_pIE);
 
  m_pIE->put_Visible(VARIANT_TRUE);

  BOOL bAdvised = AfxConnectionAdvise( m_pIE,
                                       DIID_DWebBrowserEvents2,
                                       m_pIEEvents->GetInterface(&IID_IUnknown),
                                       TRUE,
                                       &m_dwCookie);


Great.  But what I want to do is to monitor internet events on an instance of Explorer that is already running.  So I did manage to get this to work:

  CString msg;
  HRESULT hresult;
  VARIANT arg;
  arg.vt = VT_ERROR;
  arg.scode = DISP_E_PARAMNOTFOUND;

  IUnknown *punk = (IUnknown *)NULL;

  CLSID clsid;                                

  CLSIDFromProgID( L"InternetExplorer.Application.1",
                  &clsid);

  hresult = GetActiveObject( clsid,
                            NULL,
                            &punk);

  if(!SUCCEEDED(hresult)){

   AfxMessageBox("Not FOUND", MB_OK);

   return TRUE;

  }

  hresult = punk->QueryInterface( IID_IWebBrowser2,
                                 (LPVOID *)&m_pIE);

  if(!SUCCEEDED(hresult)){
      AfxMessageBox("QueryInterface() failed", MB_OK);
      punk->Release();
      return TRUE;
  }

  punk->Release();

  // Set up the event sink
  BOOL bAdvised = AfxConnectionAdvise( m_pIE,
                                      DIID_DWebBrowserEvents2,
                                      m_pIEEvents->GetInterface(&IID_IUnknown),
                                      TRUE,
                                      &m_dwCookie);

Fine.  That allows me to monitor a previously running version of IE.  But, I haven't been able to find out what the ProgID is for Explorer.exe.  Man do I feel dense.  My brain hurts.  This can't be that hard.  Will sombody please put me out of my misery?

Thank, Larry
0
Comment
Question by:prangel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 7992084
Hi prangel,

with 'ProgID' you mean the 'InternetExplorer.Application.1'
from your code?

If so, why not simply use i.e.

hresult = GetActiveObject( CLSID_InternetExplorer,          NULL,&punk);

hope that helps,

ZOPPO
0
 

Author Comment

by:prangel
ID: 8010493
Hey ZOPPO! Thanks for looking at my little problem.

Yea, I knew that GetActiveObject(CLSID_InternetExplorer . . .  ) works fine.  And when I use CoCreateInstance(CLSID_ShellBrowserWindow . . .  ) to create and control an instance of Windows Explorer (not IE) that works fine too.  But when I try to hook up to an already-runnung instance of Windows Explorer with GetActiveObject(CLSID_ShellBrowserWindow . . .  ), I get back error #-2147221021, 'Operation Unavailable'.  That is what I am trying to do.  I need to do an AfxConnectionAdvise() to a previously running instance of Windows Explorer (not IE) to monitor internet traffic that originates from Windows Explorer.

Thanks for your help,

Larry
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 1500 total points
ID: 8015519
hm... strange, for me it seems to work fine.

BTW, I recieve the same error if I comment out the call
to AfxOleInit() in the win-app-derived InitInstance()
function ... maybe you missed this.

ZOPPO
0
 

Author Comment

by:prangel
ID: 8019808
ZOPPO!

I think that I got a handle on it.  

(By the way AfxOleInit() was in there.)  

As a result of some testing I was doing to figure out why it worked for you and didn't for me, I discovered that an instance of Explorer.exe (Not IE) would respond properly to GetActiveObject(CLSID_InternetExplorer . . .  ).  Weird, but I guess that it is the IE control, contained be Explorer, that is answering the 'phone'.  Not Explorer itself.  So, the key accessing the internet functionaliy in Explorer is to use IE's CLSID, not Explorer's, with GetActiveObject().

I appriciate your help for helping me get on the right track and I am going to award you the points.

Thanks!

Larry
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 8023417
hm, ok, thanks a lot ... sorry that you had to solve the problem yourself :o)

have a nice day,

regards,

ZOPPO
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question