ActiveX로 웹페이지의 URL가져오기
-응용 예) ActiveX 콘트롤로 특정 도메인 접속이나 특정 파일 경로의 접근을 막을수 있다
ActiveX초기화 상태에서 인터넷 익스플로어는 IOleObject::SetClientSite()로 포인터를 사이트에 넘기는데 이때 URL을 가져올수 있다
1. |
Obtain the client site (IOleClientSite) interface pointer. The container calls IOleObject::SetClientSite() to pass a pointer to the client site. Override this method to cache this pointer. |
2. |
Obtain a moniker to the client site by calling IOleClientSite::GetMoniker(). |
3. |
Call IMoniker::GetDisplayName() to obtain the URL for the current document. |
STDMETHOD(SetClientSite)(IOleClientSite *pClientSite)
{
if (pClientSite != NULL)
{
// Obtain URL from container moniker.
CComPtr<IMoniker> spmk;
LPOLESTR pszDisplayName;
if (SUCCEEDED(pClientSite->GetMoniker(
OLEGETMONIKER_TEMPFORUSER,
OLEWHICHMK_CONTAINER,
&spmk)))
{
if (SUCCEEDED(spmk->GetDisplayName(
NULL, NULL, &pszDisplayName)))
{
USES_CONVERSION;
CComBSTR bstrURL;
bstrURL = pszDisplayName;
ATLTRACE("The current URL is %s\n", OLE2T(bstrURL));
CoTaskMemFree((LPVOID)pszDisplayName);
}
}
}
return IOleObject_SetClientSite(pClientSite);
}
출처 :MSDN