FIX: ClassWizard Uses DISPID_CAPTION as Custom Caption Property (185671)
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 Q185671 SYMPTOMS
When loading an ActiveX control that has a custom "Get/Set methods" Caption
property, into a Visual Basic form, Visual Basic won't persist the value of
the Caption properly.
CAUSE
ClassWizard uses the DISPID for the stock Caption property (DISPID_CAPTION)
as the DISPID for the custom Get/Set methods "Caption" property. When such
a control is loaded to a form in Visual Basic and a save operation is
performed, Visual Basic is confused so it saves the "Caption" property
twice in the .frm file. When Visual Basic reads it in again, it encounters
the first persisted property.
RESOLUTION
Give a unique DISPID to the custom "Get/Set methods" Caption property so
that Visual Basic does not use the stock Caption property DISPID:
- In the .odl file, change the following line (where the ID is equal to a
nonconflicting DISPID). For example, change the following
[id(DISPID_CAPTION)] BSTR Caption;
to the following:
[id(2)] BSTR Caption; - Add an enumeration to the .h file of the COleControl-derived class:
enum {
//{{AFX_DISP_ID(CPersistctrlCtrl)
// ... more dispid enumeration goes here
dispidCaption = 2L // ADD THIS!!! - same DISPID as in step 1
//}}AFX_DISP_ID
};
- Change the following line in the .cpp file of the COleControl-derived
class. For example, change the following
DISP_PROPERTY_EX_ID(CMyActiveXCtrl, "Caption", DISPID_CAPTION,
GetCaption, SetCaption, VT_BSTR)
to the following:
DISP_PROPERTY_EX(CMyActiveXCtrl, "Caption",
GetCaption, SetCaption, VT_BSTR)
Change the following
BoundPropertyChanged(DISPID_CAPTION);
to the following:
BoundPropertyChanged(dispidCaption); - Recompile the control project in Visual C++.
- In the Visual Basic application, delete the control from the form. Save
these changes to delete the multiple caption persisted properties. Then,
add the control back to the form.
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed
at the beginning of this article. This problem was corrected in Visual C++
version 6.0.
REFERENCES
For a list of Stock Properties Supported by ClassWizard, please refer to
"ActiveX Controls: Adding Stock Properties" in Visual Basic's books online.
Modification Type: | Major | Last Reviewed: | 11/18/2003 |
---|
Keywords: | kbBug kbCtrl kbfix kbIntl kbIntlDev kbNoUpdate kbVC600fix kbVS600fix kbwizard KB185671 kbAudDeveloper |
---|
|