?
Solved

GetActiveObject and Internet Explorer

Posted on 2010-01-05
10
Medium Priority
?
935 Views
Last Modified: 2013-12-08
Hi All

I want to get the URL from the running IE. I attached a small Win32 app that was supposed to do it. I see  the GetActiveObject returns 0x800401e3 - operation unavailable.

I've read MSDN:
Retrieves a pointer to a running object that has been registered with OLE.

So Internet Explorer is noit registered?
Where is the mistake?

I see few threads on EE with GetActiveObject in the accepted solutions.
I tested the same in an MFC application too. More then it, I found the Edit in IE and I cannot get the URL with GetWindowText too.

It is IE 8. I see the problem on Vista and XP.

#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <mshtml.h>
#include <exdisp.h>

int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
					  LPWSTR lpCmdLine, int nCmdShow)
{
	LPUNKNOWN pUnknown;
	IWebBrowser2* pBrowser;
	HRESULT hr = CoInitialize(NULL);
	if (!SUCCEEDED(hr))
		return FALSE;

	//CLSID clsid;                                
	//CLSIDFromProgID( L"InternetExplorer.Application", &clsid);
	//hr = GetActiveObject(clsid, NULL, &pUnknown);
	hr = GetActiveObject(CLSID_InternetExplorer, NULL, &pUnknown);

	if (SUCCEEDED(hr))
	{
		hr = pUnknown->QueryInterface(IID_IWebBrowser2, (LPVOID*)&pBrowser);
		BSTR str = NULL;
		hr = pBrowser->get_LocationURL(&str);
		SysFreeString(str);
		pBrowser->Release();
		pUnknown->Release();
	}

	CoUninitialize();
	return 0;
}

Open in new window

0
Comment
Question by:pgnatyuk
  • 5
  • 4
10 Comments
 
LVL 8

Accepted Solution

by:
milindsm earned 2000 total points
ID: 26179517
0
 
LVL 33

Author Comment

by:pgnatyuk
ID: 26179629
Thank you. Nice article. I knew about it, but never used. I cannot use it now too.
So IE is not registered?
If this is only the answer, I can close this question. I have a bad solution - I got the text from the edit box of the Navigation Bar.
 

HWND FindIEWnd()
{
	HWND hWnd = FindWindow(L"IEFrame", NULL);
	return hWnd;
}

HWND FindURLWnd(HWND hIE)
{
	if (!IsWindow(hIE))
		return NULL;

	HWND hWndURL = NULL;
	HWND hWnd = FindWindowEx(hIE, NULL, L"WorkerW", NULL);
	if (hWnd != NULL)
	{
		hWnd = FindWindowEx(hWnd, NULL, L"ReBarWindow32", NULL);
		if (hWnd != NULL)
		{
			hWnd = FindWindowEx(hWnd, NULL, L"Address Band Root", NULL);
			if (hWnd != NULL)
			{
				hWndURL = FindWindowEx(hWnd, NULL, L"Edit", NULL);
			}
		}
	}
	return hWndURL;
}

Open in new window

0
 
LVL 17

Expert Comment

by:CSecurity
ID: 26179719
Best way is BHO. You can also give thread injection or dll injection a try.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 8

Expert Comment

by:milindsm
ID: 26179892
@pgnatyuk
This is quite risky solution. Don't expect that it will always give you correct results...!!!
0
 
LVL 33

Author Comment

by:pgnatyuk
ID: 26179926
Yes, I know. It is not a real project. I agree with you.
0
 
LVL 8

Expert Comment

by:milindsm
ID: 26179935
But why not BHO ??? Are you getting any errors????
0
 
LVL 33

Author Comment

by:pgnatyuk
ID: 26180004
I've said - it is not a real project.
I thought that the correct way is to use IWebBrowser2. It didn't work because of GetActiveObject. I didn't expect that. I didn't want to spend time on BHO.
Thanks from the article.
0
 
LVL 33

Author Closing Comment

by:pgnatyuk
ID: 31672864
Thanks
0
 
LVL 8

Expert Comment

by:milindsm
ID: 26206970
Thanks...!!! Please rate the article as well if you found it useful...!!!
0
 
LVL 33

Author Comment

by:pgnatyuk
ID: 26277635
Actually here is the correct (or, at least, the expected) answer:
Connecting to Running Instances of Internet Explorer:
http://www.codeproject.com/KB/shell/ietoolbartutorial.aspx
CodeProject: http://www.codeproject.com/KB/shell/iehelper.aspx
MSND:
1. ShellWindows: http://msdn.microsoft.com/en-us/library/bb773974(VS.85).aspx
2. Internet Explorer object: http://msdn.microsoft.com/en-us/library/aa752084(VS.85).aspx
 
 
0

Featured Post

Industry Leaders: 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

#Citrix #Internet Explorer #Enterprise Mode #IE 11 #IE 8
Several part series to implement Internet Explorer 11 Enterprise Mode
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

569 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