Last active
December 29, 2015 01:49
-
-
Save kumatti1/7596411 to your computer and use it in GitHub Desktop.
C++でInternet Explorer Manager
This file contains hidden or 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
#import "ieframe.dll" | |
#import "mshtml.tlb" | |
#import "Ieautomation.tlb" | |
#include <Windows.h> | |
#define URI L"https://login.yahoo.co.jp/config/login_verify2?.src=ym" | |
HRESULT GetSub() | |
{ | |
using namespace InternetExplorerAutomationLib; | |
HRESULT hr; | |
try { | |
IInternetExplorerManagerPtr pMan; | |
hr = pMan.CreateInstance(__uuidof(InternetExplorerManager)); | |
if (FAILED(hr)) _com_issue_error(hr); | |
SHDocVw::IWebBrowser2Ptr pIE; | |
GUID guid = __uuidof(pIE); | |
pMan->CreateObject(1, nullptr, &guid, (void**) &pIE); | |
pIE->Visible = VARIANT_TRUE; | |
pIE->Navigate(_bstr_t(URI)); | |
while (pIE->Busy == VARIANT_TRUE || pIE->ReadyState != READYSTATE_COMPLETE) | |
::Sleep(100); | |
MSHTML::IHTMLDocument2Ptr pDoc(pIE->Document); | |
MSHTML::IHTMLElementCollectionPtr pCol(pDoc->all); | |
_variant_t varItem(L"login"); | |
MSHTML::IHTMLInputElementPtr pInput; | |
pInput = pCol->item(varItem); | |
pInput->value = _bstr_t(L"id"); | |
_variant_t varItem2(L"passwd"); | |
pInput = pCol->item(varItem2); | |
pInput->value = _bstr_t(L"pw"); | |
// MSHTML::IHTMLFormElementPtr pForm; | |
// pForm = pInput->form; | |
// pForm->submit(); | |
MSHTML::IHTMLElementPtr pElement; | |
_variant_t varItem3( L".save" ); | |
pElement = pCol->item(varItem3 ); | |
pElement->click(); | |
} | |
catch (_com_error& e) { | |
hr = e.Error(); | |
} | |
return hr; | |
} | |
int CALLBACK WinMain( | |
_In_ HINSTANCE hInstance, | |
_In_ HINSTANCE hPrevInstance, | |
_In_ LPSTR lpCmdLine, | |
_In_ int nCmdShow | |
) | |
{ | |
::CoInitialize(nullptr); | |
GetSub(); | |
::CoUninitialize(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment