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
}
******************
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
}
相关文章推荐
- add line order to each line and remove the last match of each line
- the connections of post-order(LRH) and pre Order(HLR)
- The run order about Loaded event and OnApplyTemplate in custom control of Silverlight 2 beta 2
- ruby merge array of hashes based on the key and order it by number of key/value pair
- Determine whether the concatenation of a and b in this order is a square number.
- Counting the active session number and tune up concurrent performance of MapGuide/AIMS
- A Guide to Blocks & Grand Central Dispatch (and the Cocoa API's making use of them)
- Given preorder and inorder traversal of a tree, construct the binary tree.
- Linux and C[2]: What is the function of inet_aton or inet ntoa ?
- How to get and set the drawing order of layers in globe(获取并设置Globe图层的叠加次序:)
- the initialization of ANN weights and activation function
- The Future of Middleware and the BizTalk Roadmap
- Get the average socre of the student.(The exmaple of group, having and order by).求学生平均分(group, having 和 order by使用示例).
- This function has none of Deterministic,no sql,or reads sql data in its declaration and binary logging is enabled(you *might* want to use the less safe log_bin_trust_function_creators variable
- const at the end of function and passing const object in a function call
- The study of map() and reduce() function in Python(20170913)
- The Standard Librarian: I/O and Function Objects: Containers of Pointers
- How do I add new state and change the workflow of Purchase Order?
- (NOT CLEAR)Question 44: What member function of std::fstream could a C++ developer invoke in order to change the target output f
- Given constant integers x and t, write a function that takes no argument and returns true if the function has been called x number of times in last t secs.