bug in MFC Ocx BEGIN_DISPATCH_MAP
来源:互联网 发布:asp网络验证 编辑:程序博客网 时间:2024/06/05 17:30
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
}
- bug in MFC Ocx BEGIN_DISPATCH_MAP
- ocx function and the order of BEGIN_DISPATCH_MAP
- MFC Ocx: Using ActiveX Controls in Nondialog Windows
- MFC 扩展和OCX
- MFC 制作OCX插件
- MFC OCX多线程问题
- 修改MFC OCX IID
- MFC写OCX插件
- MFC Activex OCX接口
- MFC OCX开发笔记
- imgedit.ocx win98 tiff bug
- 载入mfc生成的ocx
- MFC ActiveX (OCX) 创建技术
- mfc之ocx控件制作
- 修改MFC OCX的GUID
- csharp.delphi event vs mfc ocx event
- How to import Ocx into MFC project
- MFC how to handle ocx event
- 关于spi
- 一次超级联接,可以打开两个页面
- 策划新人如何积累自己的作品
- 从美国电子政务运营模式看IT外包服务
- JavaScript实现模态对话框
- bug in MFC Ocx BEGIN_DISPATCH_MAP
- IT Services Stack: collaboration experiment
- 解决vs2008在vista下本地调试为无法打开网页的问题
- 中国人,我们要努力,加油!
- 5年海外工作经验,硕士归国没有适合我的位置???
- Evolution自动同步Google的日历
- 如何激励研发人员:经典小故事中的启迪
- 匈牙利命名法
- 对漏洞的检查何时休