How to Monitor Events in Explorer

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
prangelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZoppoCommented:
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
prangelAuthor Commented:
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
ZoppoCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
prangelAuthor Commented:
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
ZoppoCommented:
hm, ok, thanks a lot ... sorry that you had to solve the problem yourself :o)

have a nice day,

regards,

ZOPPO
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.