IObjectWithSite

Hi, What I am trying to do is place my own button on the explorer tool bar and have it navigate the browser to my web site.  I have created a COM Object using ATL.  This object implements IObjectWithSite.  The problem I am having is that when the button is pressed it calls:

IObjectWithSite::SetSite(IUnknown *pUnkSite)

This is what it is supposed to do but, the problem is the when I try to set my smart pointer:

CComQIPtr<IWebBrowser2, &IID_IWebBrowser2> m_spWebBrowser2;

equal to pUnkSite:

m_spWebBrowser2 = pUnkSite;

it doesn't seem to do anything.  m_spWebBrowser2 remains NULL?  Anyone have any idea what I am doing wrong?  Anything would help at this point.
LVL 1
perrizoAsked:
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.

ZizzerCommented:
Assuming pUnkSite is not NULL, it looks like what's happening is that pUnkSite does not implement IWebBrowser2.  CComQIPtr will automatically call QueryInterface in order to obtain an IWebBrowser2 pointer from pUnkSite, but if the QI call fails, CComQIPtr will silently return NULL instead.

If this is true, you might ask why pUnkSite does not implement IWebBrowser2 (or even whether it should implement IWebBrowser2), but I'd have to look deeper into the problem to answer this, and I think that would be worth more than 150 points.
0
perrizoAuthor Commented:
Zizzer,  I've raised them to 300.  SetSite is supposed to be called with a pointer to IShellBrowser.  I have to admit I am new to this COM stuff and I have no idea wether pUnkSite (IShellBrowser) Implements IWebBrowser2 or not.  Could you give me a little direction before I accept your answer?
0
perrizoAuthor Commented:
Zizzer,  I've raised them to 300.  SetSite is supposed to be called with a pointer to IShellBrowser.  I have to admit I am new to this COM stuff and I have no idea wether pUnkSite (IShellBrowser) Implements IWebBrowser2 or not.  Could you give me a little direction before I accept your answer?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

ZizzerCommented:
Are you using IE4 or IE5?  It sounds like IE5, since you're adding a button to the toolbar.

I have IE4 here at work and just wrote a quick COM object that does not have the problem you describe.  Here's the code I tried:

HRESULT CFoo::SetSite(IUnknown *pUnkSite)
{
   CComQIPtr<IWebBrowser2, &IID_IWebBrowser2> spWebBrowser2;
      spWebBrowser2 = pUnkSite;

   return (spWebBrowser2 == NULL) ? E_INVALIDARG : S_OK;
}

This worked fine when invoked by either iexplore.exe or explorer.exe.

If I have time, I can try this on IE5 when I go home this evening.

If, on the other hand, you're having this problem with IE4, you'll probably have to send me your code since I can't reproduce the problem.

-- Zizzer
0
perrizoAuthor Commented:
Zizzer, I'm using IE5.  How are you making the call with IE4 since you cannot add buttons to the toolbar?  Is this actually the problem?  Does IE5 pass the wrong thing to SetSite?  Like I said before the documentation I have found said that IE passes a pointer to IShellBrowser.

I thought I would raise the points again to make answering this question worth the time your spending on it.
0
ZizzerCommented:
> How are you making the call with IE4
> since you cannot add buttons to the
> toolbar?

I am making the call with IE4 by registering my COM server as a "browser helper object" (BHO).  As you point out, there is no way to add a button to the IE4 toolbar, but IE4 will still create my object if it is registered correctly as a BHO.  See http://msdn.microsoft.com/library/techart/bho.htm#bho_getintouch for an example of what I'm doing.  This code seems to work fine under IE4.

> Is this actually the problem?

I don't think so, but I'm not really sure what the problem is yet, so I can't say for sure.

> Does IE5 pass the wrong thing to
> SetSite?

Possibly.  As I mentioned, I will experiment with IE5 at home if I have the time.

> The documentation I have found said
> that IE passes a pointer to
> IShellBrowser.

I have seen the same documentation.  It seems that the passed-in object implements (or is supposed to implement) both IShellBrowser and IWebBrowser2.  This is a perfectly reasonable thing for a COM object to do.

Thanks for raising the points.  I'll let you know when I have more info.  You can "unlock" the question (if that makes sense -- I'm new to Experts Exchange) if you'd like to solicit help from others in the meantime.

-- Zizzer
0
perrizoAuthor Commented:
Zizzer, after your last comment I went ahead and registered my object as a Browser Helper Object and it worked when the browser initially calls the object as a BHO (i.e. the call to QueryInterface succeeds).  After that, calling my object by pressing the button does not work (i.e. the call to QueryInterface fails returning null).  I realize you can't do anymore until you get home and have time but, I thought I would drop some information.
0
perrizoAuthor Commented:
Opening up for other people for now...
0
Tommy HuiEngineerCommented:
When Windows calls your IObjectWithSite::SetSite(), it passes you the container site's IUnknown. The container site does not directly support IWebBrowser2. However, it does support IServiceProvider. With the IServiceProvider, you can call its QueryService() to see if it supports IWebBrowser2:

  CComQIPtr<IServiceProvider> sp = pUnkSite;
  if (sp) {
    sp->QueryService(IID_IWebBrowserApp, IID_IWebBrowser2, (void**)&webBrowser);
    // use webBrowser as needed.
  }
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
perrizoAuthor Commented:
Thui, your solution seems to work but, after the first call Explorer is not able to make any more calls to the object.  It seems to forget that it is there.  Could you shed some light on this and then I'll release the points to you.
0
Tommy HuiEngineerCommented:
No sure about why this is happening. I would suggest you try debugging your application by defining _ATL_DEBUG_INTERFACES in your first lines of stdafx.h (prior to including any ATL header files) to check if there are interface leaks and/or reference count problems.
0
perrizoAuthor Commented:
Thui, I've accepted your answer... the code was good.  I don't think the failures after the first call are related to my initial question.  I have posted a new question I would appreciate it if you would take a look.  Thanks!
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
C++

From novice to tech pro — start learning today.