Determining URL from ActiveX Control | CodeGuru

Determining URL from ActiveX Control

This is a simple technique to determine the URL of the web page in which the ActiveX control is hosted. Introduction I had to develop ActiveX controls for web based applications. Some of these controls were manipulating the local resources. To disable malicious use of these control by others through scripting, I had to implement […]

Written By
CodeGuru Staff
CodeGuru Staff
Jan 14, 2001
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

This is a simple technique to determine the URL of the web page in which the ActiveX control is hosted.

Introduction

I had to develop ActiveX controls for web based applications.
Some of these controls were manipulating the local resources.
To disable malicious use of these control by others through scripting,
I had to implement security check.
I decided to implement a simple security scheme where I determine the url in which the control is hosted.
If the url comes from our domain, I enabled its functionality.

I used GetMoniker method of IOleClientSite Interface.The IMoniker interface has GetDisplayName() method,

which returns a user-readable representation of the moniker.

Code:

 HRESULT hrResult	= S_FALSE;
 IOleClientSite *pClientSite = NULL;
 IMoniker* pMoniker	= NULL;
 LPOLESTR sDisplayName;
 // If using ATL to develop, use the m_spClientSite data
 // member of CComControl class.
 // If using MFC, use the following code: 
 // (member function of COleControl class 
 // – don’t forget to call release)
 // pClientSite = GetClientSite();
 hrResult = m_spClientSite->GetMoniker(OLEGETMONIKER_TEMPFORUSER,
                                       OLEWHICHMK_CONTAINER,
                                       &pMoniker);
 if(SUCCEEDED(hrResult))
 {
  hrResult = pMoniker->GetDisplayName(NULL,
                                      NULL,
                                      &sDisplayName);
  pMoniker->Release();
 }
 //TODO : relevant processing with sDisplayName and
 //free sDisplayName using SysFreeString()
CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.