Last active
August 28, 2015 21:43
-
-
Save kumatti1/a923097674c1804f0bfd to your computer and use it in GitHub Desktop.
IEのURL取得
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//#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