Retrieving current URL

I have a running instance of IE and I want to know what is the current URL that this IE is displaying. This is a stand alone IE (not WebBrowser control).
Thanks.
yelinyAsked:
Who is Participating?
 
gvgCommented:
You can get an instance of IE this way.

IWebBrowserApp*      webApp;

HRESULT hr = CoCreateInstance( __uuidof( InternetExplorer ), NULL, CLSCTX_SERVER, IID_IWebBrowserApp, (void**)&webApp);

webApp->put_Visible( VARIANT_TRUE );
webApp->get_LocationURL( &url );

You might have to include EXDISP.H if it is not already included.

But this creates a new instance of IE.  

When creating IE via COM you don't have any options ( that I know of ) to tell COM that you want a current running IE.  It is up to IE ClassFactory to either give you a old one or create a new one.  If you know any COM way to get the old one or if you can configure IE to give you the old one you are done.

Gunnar Valur
0
 
jhanceCommented:
First, read this:

http://support.microsoft.com/support/kb/articles/q176/7/92.asp

With that information, you can get the URL using the:

IWebBrowser2::get_LocationURL

interface.
0
 
yelinyAuthor Commented:
Thank you jhance.
I followed the instructions in this kb article, but it doesn't compile.
This is why I don't find your answer the perfect one.
I will appreaciate your help to solve the compilation error.
I get a message saying:
Cannot open type library file: 'mshtml.dll': Error loading type library/DLL.

I added the #import statments in the application's view header file.

Do you have any clue?

0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
jhanceCommented:
>I followed the instructions in this kb
>article, but it doesn't compile.

It's not a complete application in the article.  It just shows the key points on how to get the pointer to a running IE object.
0
 
yelinyAuthor Commented:
I know this is not a complete code.
This is why I said that I followed the instructions.
I added these parts of code in the classes that this article says to put it in.
I thought maybe you tried this in the past and you know why doen't it compile.
Thank you for your help.
With your permision I'll leave the question open for now in order to let others read it and response.
Thanks.
0
 
jhanceCommented:
gvg,

Your technique will create _an_ instance of IE, but the question was getting the interface to a running instance of IE.  Not the same problem.
0
 
yelinyAuthor Commented:
I couldn't compile the code that was proposed as a solution.
0
 
yelinyAuthor Commented:
I couldn't compile the code that was proposed as a solution.
0
 
yelinyAuthor Commented:
gvg's solution was good enough for me (at the moment).
If you'll post it as an answer you'll earn the points.
Thank you both for the effort.
0
 
jhanceCommented:
You don't have to have gvg post an answer.  EE has added the "Accept Comment as Answer" feature some time ago.  Just click on that link next to his comment that you wish to accept.

BTW, I still think that his answer (while a correct statement) doesn't answer your question.  But hey, they're your points....
0
 
yelinyAuthor Commented:
First jhance thanks for the information. I did use this feature (Accept comment as answer).
Although gvg's answer wasn't the best one, he brought me to a point where I can go on with my study of this subject. I think this is why EE gave us the option to grade an answer.
Thanks and good luck.
0
 
gvgCommented:
yeliny,

Since you were a good sport and gave me points I thought I should figure this out.

I used the article and it works for me.
If you have IE 5 be sure to only.

#import <shdocvw.dll>
#import <mshtml.tlb>

SHDocVw::IShellWindowsPtr m_spSHWinds;       
m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows));

CString strCount;
long nCount = m_spSHWinds->GetCount();

IDispatchPtr spDisp;
   
for (long i = 0; i < nCount; i++)
{
  _variant_t va(i, VT_I4);
  spDisp = m_spSHWinds->Item(va);

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

    MSHTML::IHTMLDocument2Ptr spDoc(spBrowser->GetDocument());
                  
    if (spDoc != NULL)
    {
//    m_ctlListTitle.AddString(spDoc->Gettitle());
    }
  }
}

If you have more questions feel free to ask gvg@flaga.is
0
 
gvgCommented:
My point was that is you don't have to import <mshtml.dll> if you can import the mshtml.tlb since it has the same class information.


0
 
gvgCommented:
Only one more comment.

In IE 4 the Type Library was linked into the MSHTML.DLL but in IE 5 they split to DLL into DLL functionality ( the DLL ) and into Type Library ( the TLB )

Gunnar Valur
0
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.

All Courses

From novice to tech pro — start learning today.