Microsoft KB Archive/179691

= The dispatch identifiers change when you add properties to existing Automation objects by using ClassWizard =

Article ID: 179691

Article Last Modified on 6/2/2005

-

APPLIES TO

 The ClassWizard, when used with:  Microsoft Visual C++ 4.0 Standard Edition

 Microsoft Visual C++ 4.1 Subscription

 Microsoft Visual C++ 4.2 Enterprise Edition

 Microsoft Visual C++ 4.2 Professional Edition</li></ul>

 Microsoft Visual C++ 5.0 Enterprise Edition</li></ul>

 Microsoft Visual C++ 5.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Enterprise Edition</li></ul>

 Microsoft Visual C++ 6.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q179691

<div class="symptoms_section">

SYMPTOMS
When adding properties by using ClassWizard to existing Automation objects, the dispatch identifiers (DISPIDs) of any methods will change.

Although changing DISPIDs does not usually cause a problem when originally building an Automation server, it can cause incompatibility problems when updating existing Automation objects. Automation clients that were built using early binding will no longer work with the updated server.

<div class="cause_section">

CAUSE
ClassWizard adds properties to MFC's "dispatch map" before methods. Because, by default, DISPIDs are assigned to interfaces based on the order in which they are added to the map, adding a property changes the IDs of all the existing methods.

<div class="resolution_section">

RESOLUTION
Add properties and methods to the dispatch map and the .odl file without using ClassWizard.

You should add these additional properties outside the ClassWizard comments at the end of the dispatch map.

<div class="status_section">

STATUS
Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

<div class="moreinformation_section">

MORE INFORMATION
There are several MFC dispatch DISP_XXXX_ID macros that allow you to specify a specific DISPID: <pre class="fixed_text">  DISP_FUNCTION_ID DISP_PROPERTY_ID DISP_PROPERTY_NOTIFY_ID DISP_PROPERTY_EX_ID DISP_PROPERTY_PARAM_ID These macros can be useful in maintaining existing DISPID numbering.

Here is an sample dispatch map from a sample control: ////////////////////////////////////////////////////////////////////////   // Dispatch map: BEGIN_DISPATCH_MAP(CTestCtrl, COleControl) //AFX_DISPATCH_MAP DISP_FUNCTION_ID(CTestCtrl, "AboutBox", DISPID_ABOUTBOX,                     AboutBox, VT_EMPTY, VTS_NONE) END_DISPATCH_MAP Here is the same dispatch map using the DISP_XXX_ID macros to specify specific DISPIDs: ////////////////////////////////////////////////////////////////////////   // Dispatch map: BEGIN_DISPATCH_MAP(CTestCtrl, COleControl) //AFX_DISPATCH_MAP DISP_PROPERTY_NOTIFY_ID(CTestCtrl, "Property1", 1,                             m_property1, OnProperty1Changed, VT_I2) DISP_PROPERTY_EX_ID(CTestCtrl, "Property2", 2, GetProperty2,                         SetProperty2, VT_I2) DISP_FUNCTION_ID(CTestCtrl, "Method1", 3, Method1, VT_I2, VTS_I2) DISP_FUNCTION_ID(CTestCtrl, "Method2", 4, Method2, VT_I4, VTS_NONE) DISP_FUNCTION_ID(CTestCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox,                      VT_EMPTY, VTS_NONE) END_DISPATCH_MAP

<div class="references_section">