FIX: ATL 7.0 control that you build by using Visual Studio .NET 2002 may crash when inserted on a VBA UserForm (815358)
The information in this article applies to:
- Microsoft Visual Studio .NET (2002), Professional Edition
- Microsoft Visual Basic for Applications 6.0
- Microsoft Visual Basic for Applications 5.0
SYMPTOMSYou can use Visual Studio .NET 2002 to build an ActiveX
Control with the ActiveX Template Library (ATL). However, these controls crash
when they are inserted or resized on a Visual Basic for Applications (VBA)
UserForm. The same control may work correctly in other containers, but the
control fails in a Microsoft Office application or other VBA-enabled
application.
The exact error and exact crash address varies by host
product, by operating system, and by the version of VBA.CAUSEThis problem occurs because of a regression in the code for
IQuickActivate::QuickActivate. IQuickActivate::QuickActivate uses the ControlQueryInterface method to get the IConnectionPointContainer interface of the
control. This is done to set up the IPropertyNotifySink callback that is passed
by the caller in the QACONTAINER structure. In previous versions of ATL, ControlQueryInterface
returned the internal interface for the control. In ATL 7.0, however,
ControlQueryInterface returns the interface that is obtained from the outer
unknown. This behavior occurs if the control is aggregated.
In VBA
UserForms (FM20), the control is aggregated with a VBA control extender. As a
result, the code for ATL 7.0 obtains the connection point container for the
extender and then incorrectly sinks the IPropertyNotifySink to the wrong
object. When a property sink notification is raised by the UserForm, the
property sink notification is sent to the extender and not the control. The
extender treats such notifications as if they came from the control and then
notifies the host of the property change. VBA then raises the event again. This
results is a recursive loop that eventually leads to a crash when the process
runs out of stack space.
RESOLUTION
To resolve this problem, obtain the latest service pack for Microsoft Visual Studio .NET. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
837234 List of bugs that are fixed in Visual Studio .NET 2002 Service Pack 1
WORKAROUNDTo work around this problem, you must either override or
modify the ATL implementation for IQuickActivate::QuickActivate. Then use
_InternalQueryInterface to obtain the connection point for setting up the
advise sink on IPropertyNotifySink. The following lines show the corrected
code: CComPtr<IConnectionPointContainer> pCPC;
// Do not use ControlQueryInterface for getting the IConnectionPointContainer
// because it will get the copy of the extender, and not the internal interface you expect.
// So use _InternalQueryInterface to get the right connection point on this object...
_InternalQueryInterface(__uuidof(IConnectionPointContainer), (void**)&pCPC); STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are
listed at the beginning of this article.
This
problem was first corrected in Visual Studio .NET 2002 Service Pack
1.
Modification Type: | Major | Last Reviewed: | 8/9/2005 |
---|
Keywords: | kbvs2002sp1fix kbvs2002sp1sweep kbbug KB815358 kbAudDeveloper |
---|
|