Microsoft KB Archive/185674

= PRB: Default Property Causes DISP_XXXX_ID Methods/Props to Fail =

Article ID: 185674

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 5.0 Enterprise Edition

 Microsoft Visual C++ 5.0 Professional Edition 

-



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.

<div class="status_section">

STATUS
This feature is by design.

<div class="moreinformation_section">

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: <pre class="fixed_text">  DISP_FUNCTION_ID DISP_PROPERTY_ID DISP_PROPERTY_NOTIFY_ID DISP_PROPERTY_EX_ID DISP_PROPERTY_PARAM_ID

<div class="references_section">