PRB: Default Property Causes DISP_XXXX_ID Methods/Props to Fail

ID: Q185674


The information in this article applies to:
  • The Microsoft Foundation Classes (MFC), included with:
    • Microsoft Visual C++, 32-bit Editions, version 5.0


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.


MORE INFORMATION

Although ClassWizard maintains dispatch IDs for properties and methods in the .odl file, DISPIDs are not specified for entries in the dispatch map unless they are specified manually using one of the DISP_XXXX_ID macros:


   DISP_FUNCTION_ID
   DISP_PROPERTY_ID
   DISP_PROPERTY_NOTIFY_ID
   DISP_PROPERTY_EX_ID
   DISP_PROPERTY_PARAM_ID 


REFERENCES

For more information on MFC's dispatch maps, DISP macros, and default DISPID numbering, see MFC Technote #39 in the Visual C++ documentation.

© Microsoft Corporation 1998, All Rights Reserved.
Contributions by Kelly Marie Ward, Microsoft Corporation

Additional query words: automation

Keywords : kbole kbMFC kbVC500
Version : winnt:5.0
Platform : winnt
Issue type : kbprb


Last Reviewed: January 12, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.