Indicates whether the designer supports a particular ActiveX control in the host's toolbox.
HRESULT IsSupported(
IDataObject *pdo
);
Parameter
pdo
[in] Pointer to a toolbox data object.
Return Values
The designer returns one of the following values:
Return Value | Meaning |
S_OK | The designer supports the specified ActiveX control. |
S_FALSE | The designer does not support the control. |
Comments
The designer implements this method.
Hosts call the IsSupported method, passing a pointer to a single ActiveX control, to find out whether the designer supports the control. The designer returns S_OK to indicate support or S_FALSE to indicate no support. In turn, the host can enable or disable the item in its toolbox. The host calls IsSupported only for ActiveX controls and not for designer-supplied items; the host assumes that the designer will always return S_OK for its own toolbox items.
The designer must call methods of the IDataObject interface to parse the data object to which pdo points. The format of the data object depends on the type of the corresponding toolbox object.
For an ActiveX control, the parameter contains the clipboard format CF_CLSID. This type consists of the object's CLSID represented as a zero-terminated ANSI string, stored as TYMED_GLOBAL. The clipboard format string for CF_CLSID is "CLSID". The data object can also support the CF_CLSIDCLASSNAME clipboard format. This format identifies the ActiveX control with a programmatic name, such as the zero-terminated ANSI string "Button". The name of this clipboard format is "ClsIdClassName".
Example
The following example calls IDataObject::GetData to determine whether the designer supports the specified item. First, it sets up the local variable fe
to specify the desired data format. Then it inspects the returned stgm
structure to ensure that the ActiveX control specified in the data object is not the InTest control, which this designer does not support.
STDMETHOD(IsSupported)(IDataObject* pdo)
{
int iRetVal = 0;
HRESULT hr = S_OK;
FORMATETC fe;
STGMEDIUM stgm;
LPSTR lpszTemp = NULL;
void * pvGlobal = NULL;
// Initialize storage structure before calling IDataObject::GetData().
stgm.hGlobal = NULL;
// Fill in FORMATETC to get data.
fe.cfFormat = m_cfCLSID;
fe.ptd = NULL;
fe.dwAspect = DVASPECT_CONTENT;
fe.lindex = -1;
fe.tymed = TYMED_HGLOBAL;
// Call IDataObject::GetData to get the data.
hr = pdo->GetData(&fe, &stgm);
// Lock the object in memory, retrieve the control's CLSID, and unlock.
pvGlobal = GlobalLock(stgm.hGlobal);
if(!pvGlobal)
{
hr = E_OUTOFMEMORY;
CLEANUP_ON_ERROR(hr);
}
lpszTemp = new char[strlen((char *)pvGlobal) + 1];
if(!lpszTemp)
{
hr = E_OUTOFMEMORY;
CLEANUP_ON_ERROR(hr);
}
strcpy (lpszTemp, (char *)pvGlobal);
GlobalUnlock (stgm.hGlobal);
// Compare the string to see if it is the CLSID of the
// InTest control, which is too buggy for us to support.
if (0 == _tcsnicmp (m_szInTestClsid, lpszTemp, strlen(m_szInTestClsid)))
{
hr = S_FALSE;
}
else
hr = S_OK;
// Release all memory allocated during this method or
// assumed to be handled by this method.
if(lpszTemp)
delete lpszTemp;
return(hr);
}