您的位置:首页 > 其它

ocx function and the order of BEGIN_DISPATCH_MAP

2008-01-16 09:43 465 查看
the order of function and event is vatal:

******************
If you add Ocx function/event, MFC will NOT arrange the right order for you!!!!!!!!!!
you should separate the function group and event group, or the dispid will mixed up and
InvokeHelper will not work
******************

BEGIN_DISPATCH_MAP(CMyOcxCtrl1Ctrl, COleControl)
DISP_FUNCTION_ID(CMyOcxCtrl1Ctrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
DISP_FUNCTION_ID(CMyOcxCtrl1Ctrl, "MyIntMtd", dispidMyIntMtd, MyIntMtd, VT_UI4, VTS_R8 VTS_UI4)
DISP_FUNCTION_ID(CMyOcxCtrl1Ctrl, "MyVoidFunc", dispidMyVoidFunc, MyVoidFunc, VT_EMPTY, VTS_NONE)
DISP_FUNCTION_ID(CMyOcxCtrl1Ctrl, "MyTestOcxFunc", dispidMyTestOcxFunc, MyTestOcxFunc, VT_EMPTY, VTS_NONE)

DISP_FUNCTION_ID(CMyOcxCtrl1Ctrl, "OnMyEvent1", dispidOnMyEvent1, OnMyEvent1, VT_EMPTY, VTS_NONE)
DISP_FUNCTION_ID(CMyOcxCtrl1Ctrl, "OnMyEvent2", dispidOnMyEvent2, OnMyEvent2, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()

-------------------------------------------------
reference:
-------------------------------------------------

COleDispatchImpl::Invoke()
{
...
const AFX_DISPMAP_ENTRY* pEntry = pThis->GetDispEntry(dispid);
...
}

const AFX_DISPMAP_ENTRY* PASCAL CCmdTarget::GetDispEntry(MEMBERID memid)
{
const AFX_DISPMAP* pDerivMap = GetDispatchMap();
const AFX_DISPMAP* pDispMap;
const AFX_DISPMAP_ENTRY* pEntry;
.....

pDispMap = pDerivMap;
#ifdef _AFXDLL
for (;;)
#else
while (pDispMap != NULL)
#endif
{
// find AFX_DISPMAP_ENTRY where (pEntry->lDispID == memid)
pEntry = pDispMap->lpEntries;
while (pEntry->nPropOffset != -1)
{
if (pEntry->lDispID == memid)
return pEntry;

++pEntry;
}
// check base class
#ifdef _AFXDLL
if (pDispMap->pfnGetBaseMap == NULL)
break;
pDispMap = (*pDispMap->pfnGetBaseMap)();
#else
pDispMap = pDispMap->pBaseMap;
#endif
}
}

const AFX_DISPMAP* CCmdTarget::GetDispatchMap() const
{
return &CCmdTarget::dispatchMap; //dispatchMap point to the struct defined by the BEGIN_DISPATCH_MAP
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐