DOCUMENT:Q185674 17-JUL-2001 [visualc] TITLE :PRB: Default Property Causes DISP_XXXX_ID Methods/Props to Fail PRODUCT :Microsoft C Compiler PROD/VER:winnt:5.0 OPER/SYS: KEYWORDS:kbole kbActiveX kbAutomation kbCtrl kbMFC kbVC500 kbGrpDSMFCATL kbNoUpdate ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - The Microsoft Foundation Classes (MFC), used with: - Microsoft Visual C++, 32-bit Enterprise Edition, version 5.0 - Microsoft Visual C++, 32-bit Professional Edition, 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. (c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Kelly Marie Ward, Microsoft Corporation Additional query words: automation ====================================================================== Keywords : kbole kbActiveX kbAutomation kbCtrl kbMFC kbVC500 kbGrpDSMFCATL kbNoUpdate Technology : kbAudDeveloper kbMFC Version : winnt:5.0 Issue type : kbprb Solution Type : kbnofix ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 2001.