Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
CWnd::GetControlUnknown
Collapse the table of content
Expand the table of content

CWnd::GetControlUnknown

Call this member function to retrieve a pointer to an unknown OLE control.

LPUNKNOWN GetControlUnknown( );

Return Value

A pointer to the IUnknown interface of the OLE control represented by this CWnd object. If this object does not represent an OLE control, the return value is NULL.

Remarks

You should not release this IUnknown pointer. Typically, you would use to obtain a specific interface of the control.

The interface pointer returned by GetControlUnknown is not reference-counted. Do not call IUnknown::Release on the pointer unless you have previously called IUnknown::AddRef on it.

Example

BOOL CMytDlg::OnInitDialog() 
{
   CDialog::OnInitDialog();
   
   // IDC_MSACALCTRL1 is the ID of the Calendar control OCX embedded 
   // on this dialog
   CWnd *pWndCal = GetDlgItem(IDC_MSACALCTRL1);

   // Use the IUnknown of the control
   LPUNKNOWN pUnk = pWndCal->GetControlUnknown();

   // From there get the IDispatch interface of control
   LPDISPATCH pDisp = NULL;
   pUnk->QueryInterface(IID_IDispatch, (LPVOID*)&pDisp);

   // use IDispatch method to invoke the control's functionality

   return TRUE;  // return TRUE unless you set the focus to a control
}

See Also

CWnd Overview | Class Members | Hierarchy Chart | IUnknown::Release | IUnknown::QueryInterface

Show:
© 2015 Microsoft