pgnatyuk
asked on
GetActiveObject and Internet Explorer
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.
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;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Best way is BHO. You can also give thread injection or dll injection a try.
@pgnatyuk
This is quite risky solution. Don't expect that it will always give you correct results...!!!
This is quite risky solution. Don't expect that it will always give you correct results...!!!
ASKER
Yes, I know. It is not a real project. I agree with you.
But why not BHO ??? Are you getting any errors????
ASKER
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.
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.
ASKER
Thanks
Thanks...!!! Please rate the article as well if you found it useful...!!!
ASKER
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
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
ASKER
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.
Open in new window