Skip to content

Instantly share code, notes, and snippets.

@kumatti1
Last active August 28, 2015 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kumatti1/a923097674c1804f0bfd to your computer and use it in GitHub Desktop.
Save kumatti1/a923097674c1804f0bfd to your computer and use it in GitHub Desktop.
IEのURL取得
//#define CINTERFACE
#include <exdisp.h>
#include <windows.h>
#include <Objbase.h>
#include <Shlwapi.h>
void hoge()
{
IShellWindows *psw;
HRESULT hr;
VARIANT Vnt;
IDispatch *pDisp;
IWebBrowser2 *pIE;
BSTR bstr;
long i;
WCHAR Buf[MAX_PATH];
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(
&CLSID_ShellWindows,
NULL,
CLSCTX_ALL,
&IID_IShellWindows,
(void**)&psw);
}
if (psw)
{
long cnt;
psw->lpVtbl->get_Count(psw, &cnt);
if (cnt != 0)
{
for (i = 0; i < cnt; i++)
{
Vnt.vt = VT_I4;
Vnt.lVal = i;
psw->lpVtbl->Item(psw, Vnt, &pDisp);
if (pDisp)
{
pDisp->lpVtbl->QueryInterface(pDisp, &IID_IWebBrowser2, (void**)&pIE);
if (pIE)
{
pIE->lpVtbl->get_FullName(pIE, &bstr);
lstrcpyW(Buf, PathFindFileNameW(bstr));
if (lstrcmpW(L"iexplore.exe", Buf) == 0)
{
pIE->lpVtbl->get_LocationURL(pIE, &bstr);
MessageBoxW(0, (LPCWSTR)bstr, 0, MB_OK);
}
SysFreeString(bstr);
VariantClear(&Vnt);
pIE->lpVtbl->Release(pIE);
}
pDisp->lpVtbl->Release(pDisp);
}
}
}
psw->lpVtbl->Release(psw);
}
CoUninitialize();
}
void main()
{
hoge();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment