Last active
April 10, 2025 07:14
-
-
Save kumatti1/ab4acf3d50e7328340b4 to your computer and use it in GitHub Desktop.
(C++)DISPID_AMBIENT_DLCONTROL
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
#include <Shlwapi.h> | |
#include <windows.h> | |
#include <Exdisp.h> | |
//#include <OleIdl.h> | |
#import <shdocvw.dll> | |
#import <mshtml.tlb> | |
#import <Winhttp.dll> | |
#using <System.dll> | |
#using <System.Windows.Forms.dll> | |
using namespace System; | |
using namespace System::Windows::Forms; | |
using namespace System::Runtime::InteropServices; | |
using namespace System::Security::Permissions; | |
#define URL L"https://www.google.co.jp/" | |
[ComImport,Guid("00000118-0000-0000-C000-000000000046"), | |
InterfaceType(ComInterfaceType::InterfaceIsIUnknown)] | |
interface class IOleClientSite2 | |
{ | |
}; | |
public ref class Hoge : IOleClientSite2 | |
{ | |
public: | |
[DispId(-5512)]//DISPID_AMBIENT_DLCONTROL | |
long _DL_CTL() | |
{ | |
return 0x400;//NO_DLACTIVEXCTLS | |
} | |
}; | |
_COM_SMARTPTR_TYPEDEF(IOleClientSite, __uuidof(IOleClientSite)); | |
_COM_SMARTPTR_TYPEDEF(IOleObject , __uuidof(IOleObject)); | |
_COM_SMARTPTR_TYPEDEF(IStream , __uuidof(IStream)); | |
_COM_SMARTPTR_TYPEDEF(IPersistStreamInit , __uuidof(IPersistStreamInit)); | |
HRESULT test() | |
{ | |
HRESULT hr = S_OK; | |
try{ | |
MSHTML::IHTMLDocument2Ptr pDoc; | |
hr = pDoc.CreateInstance( L"htmlfile" ); | |
if (FAILED(hr)) _com_issue_error(hr); | |
auto obj = gcnew Hoge; | |
IDispatchPtr pDisp; | |
pDisp.Attach( static_cast<IDispatch*>(Marshal::GetIDispatchForObject(obj).ToPointer() )); | |
IOleClientSitePtr pSite( pDisp ); | |
IOleObjectPtr pOleObject( pDoc ); | |
pOleObject->SetClientSite( pSite ); | |
IPersistStreamInitPtr pStreamInt( pDoc ); | |
WinHttp::IWinHttpRequestPtr pHTTP; | |
hr = pHTTP.CreateInstance(__uuidof( WinHttp::WinHttpRequest ) ); | |
if (FAILED(hr)) _com_issue_error(hr); | |
pHTTP->Open( L"GET", URL, VARIANT_FALSE ); | |
_variant_t VarTmp; | |
pHTTP->Send( VarTmp ); | |
_variant_t VarBody = pHTTP->ResponseStream; | |
IStreamPtr pStm( VarBody ); | |
pStreamInt->Load( pStm ); | |
while(TRUE) | |
{ | |
_bstr_t bstr( pDoc->readyState ); | |
if(lstrcmpW(bstr,L"complete") == 0) | |
break; | |
Application::DoEvents(); | |
} | |
_bstr_t bstr( pDoc->title ); | |
MessageBoxW(nullptr, bstr, L"", MB_OK); | |
//実装した(実装してないけど) | |
//IOleClientSiteのメンバが呼び出される前に | |
//解放する | |
pOleObject->SetClientSite( nullptr ); | |
} | |
catch (_com_error& e) { | |
hr = e.Error(); | |
} | |
return hr; | |
} | |
int WINAPI WinMain(HINSTANCE, HINSTANCE, PSTR, int) | |
{ | |
CoInitialize(NULL); | |
test(); | |
CoUninitialize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment