bug in MFC Ocx BEGIN_DISPATCH_MAP
2008-04-21 08:31
393 查看
An wrong BEGIN_DISPATCH_MAP
dispidOnEvent1 = 1,dispidFunction1 = 1
OnEvent1 is ocx event, Function1 is ocx function
BEGIN_DISPATCH_MAP(CMyOcx2Ctrl, COleControl)
DISP_FUNCTION_ID(CMyOcx2Ctrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
DISP_FUNCTION_ID(CMyOcx2Ctrl, "OnEvent1", dispidOnEvent1, OnEvent1, VT_EMPTY, VTS_NONE)
DISP_FUNCTION_ID(CMyOcx2Ctrl, "Function1", dispidFunction1, Function1, VT_EMPTY, VTS_I4)
END_DISPATCH_MAP()
If you call Function1,(dispId = 1), MFC will search dispatch map and find entry id = 1,
thus return entry "OnEvent1", this is error, you have no way to invoke Function1.
Every function interface should place before event interface in BEGIN_DISPATCH_MAP
below is ok.
BEGIN_DISPATCH_MAP(CMyOcx2Ctrl, COleControl)
DISP_FUNCTION_ID(CMyOcx2Ctrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
DISP_FUNCTION_ID(CMyOcx2Ctrl, "Function1", dispidFunction1, Function1, VT_EMPTY, VTS_I4)
DISP_FUNCTION_ID(CMyOcx2Ctrl, "OnEvent1", dispidOnEvent1, OnEvent1, 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
}
dispidOnEvent1 = 1,dispidFunction1 = 1
OnEvent1 is ocx event, Function1 is ocx function
BEGIN_DISPATCH_MAP(CMyOcx2Ctrl, COleControl)
DISP_FUNCTION_ID(CMyOcx2Ctrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
DISP_FUNCTION_ID(CMyOcx2Ctrl, "OnEvent1", dispidOnEvent1, OnEvent1, VT_EMPTY, VTS_NONE)
DISP_FUNCTION_ID(CMyOcx2Ctrl, "Function1", dispidFunction1, Function1, VT_EMPTY, VTS_I4)
END_DISPATCH_MAP()
If you call Function1,(dispId = 1), MFC will search dispatch map and find entry id = 1,
thus return entry "OnEvent1", this is error, you have no way to invoke Function1.
Every function interface should place before event interface in BEGIN_DISPATCH_MAP
below is ok.
BEGIN_DISPATCH_MAP(CMyOcx2Ctrl, COleControl)
DISP_FUNCTION_ID(CMyOcx2Ctrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
DISP_FUNCTION_ID(CMyOcx2Ctrl, "Function1", dispidFunction1, Function1, VT_EMPTY, VTS_I4)
DISP_FUNCTION_ID(CMyOcx2Ctrl, "OnEvent1", dispidOnEvent1, OnEvent1, 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
}
相关文章推荐
- ocx function and the order of BEGIN_DISPATCH_MAP
- MFC BEGIN_MESSAGE_MAP()
- 手写MFC----第四讲 BEGIN_MESSAGE_MAP
- mybatis使用bug:org.apache.ibatis.builder.IncompleteElementException: Could not find parameter map java
- MFC BEGIN_MESSAGE_MAP()
- MFC BEGIN_MESSAGE_MAP()
- MFC中的afx_msg和BEGIN_MESSAGE_MAP
- MFC消息映射BEGIN_MESSAGE_MAP详解
- 手写MFC----第四讲 BEGIN_MESSAGE_MAP
- (zz)MFC消息映射BEGIN_MESSAGE_MAP()
- MFC Ocx: Using ActiveX Controls in Nondialog Windows
- MFC消息映射BEGIN_MESSAGE_MAP详解
- MFC之MFC BEGIN_MESSAGE_MAP()
- MFC BEGIN_MESSAGE_MAP()
- MFC BEGIN_MESSAGE_MAP()
- (zz)MFC消息映射BEGIN_MESSAGE_MAP()
- MFC之BEGIN_MESSAGE_MAP和END_MESSAGE_MAP
- Bug in tiled map extension of AndEngine
- MFC中的afx_msg和BEGIN_MESSAGE_MAP
- MFC BEGIN_MESSAGE_MAP()