Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to QueryInterface in a OCX?

68 views
Skip to first unread message

Huang Lei

unread,
Aug 1, 1998, 3:00:00 AM8/1/98
to
Win95 , VC5.0
Now I want to get the interface(DUAL IDispatch) a OCX Control
which made by myself. I add it to a dialog and it can show normally.
I write sources in OnOK() button on Click like below:
//*********************
HRESULT hr;
IDispatch *pDispatch;
CWnd* pControlWnd;
// Get CWnd of the OCX Control in Dialog
pControlWnd=this->GetDlgItem(IDC_CCPCBUTTONCTRL1);
// Get the iDispatch interface of the OCX Control
pDispatch = (IDispatch *)pControlWnd->GetControlUnknown();
// Get the Dual Interface defined by me
hr = pDispatch->QueryInterface(IID_ICCPCButton, (PVOID *)g_pButton);
//********************
Error happened in
hr = pDispatch->QueryInterface(IID_ICCPCButton, (PVOID *)g_pButton);
VC5.0 show that I access a illegal address.
I think that the OCX control has a HWND but not has a instance.
How can make the instance with the OCX control using SDK?

Thanks in advance
Huang Lei

Oreste Notelli

unread,
Aug 2, 1998, 3:00:00 AM8/2/98
to
The problem could caused by:
1. Be sure to this before calling the base class OnOK method:
void MyDialog::OnOK()
{
// your code here
CDialog::OK
// DO NOT USE CHILD WINDOWS
}

2. You should get IDispatch interace pointer in this way:
IUnknown* pUnk = pControlWnd->GetControlUnknown();
// DO NOT CAST TO IDispatch: rigth ask dual interface to
// IUnknown:
hr = pUnk->QueryInterface(IID_ICCPCButton, (PVOID *)pButton);

I Hope this will be helpfull.
Bye,
Oreste Notelli

Huang Lei ha scritto nel messaggio <01bdbd99$4aee0240$LocalHost@leland>...

Oreste Notelli

unread,
Aug 2, 1998, 3:00:00 AM8/2/98
to
0 new messages