PRB: Default Property Causes DISP_XXXX_ID Methods/Props to Fail (185674)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
This article was previously published under Q185674 SYMPTOMS
When using DISP_DEFVALUE to specify a default property in an MFC IDispatch
interface, properties and methods declared with one of the DISP_XXXX_ID
macros fails if the DISPID specified is one greater than the last ID
generated by MFC.
CAUSE
MFC maintains a table of dispatch entries, which it searches when methods
and properties are accessed through IDispatch::Invoke. Because items placed
in the dispatch map without using DISP_XXXX_ID macros do not have DISPIDs
associated with them internally, MFC relies on the order in which they are
placed in the table.
DISP_DEFVALUE causes an extra entry to be placed in the table before any of
the entries specified with the DISP_XXXX_ID macro. If the DISP_XXXX_ID
macro is using a DISPID exactly 1 greater than the last entry, the default
property is invoked instead of the one specified with the DISP_XXXX_ID
macro.
RESOLUTION
Remove the default property, or specify a DISPID in the DISP_XXXX_ID macro
that is at least 2 greater than the number of properties and methods in the
dispatch map not specified using the DISP_XXXX_ID macros.
For example, when using a default property, any DISPIDs used in
DISP_XXXX_ID macros should be 2 greater than the total number of entries in
the dispatch map minus the number specified with DISP_XXXX_ID:
2 + (# of Dispatch Map entries) - (# of DISP_XXXX_ID entries) = DISPID
of first DISP_XXXX_ID macro
If you need to specify a default property and assign to a property or
method a low value DISPID, you may need to use DISP_XXXX_ID macros for all
of the methods and properties in the dispatch map.
STATUS
This feature is by design.
REFERENCES
For more information on MFC's dispatch maps, DISP macros, and default
DISPID numbering, see MFC Technote #39 in the Visual C++ documentation.
Modification Type: | Major | Last Reviewed: | 11/18/2003 |
---|
Keywords: | kbAutomation kbCtrl kbnofix kbNoUpdate kbprb KB185674 |
---|
|