Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

BUG: ATL Control in Office Document Prevents Another Control's Events from Working


View products that this article applies to.

This article was previously published under Q241861

↑ Back to the top


Symptoms

An ATL Control inserted into an Office 97, Office 2000, or Office XP document (that is, an Excel spreadsheet, PowerPoint presentation, or Word document) causes VBA to not receive events for other controls in the same document. The other controls may fire events, but the VBA code in the event handlers will not run. If the ATL control is removed, events for the other controls work as expected.

↑ Back to the top


Cause

When a control is inserted into a document, VBA checks for an outgoing event interface in the type library for the control. If an outgoing event interface is not supplied, it effects the behavior of event handling for the rest of the controls in the document.

↑ Back to the top


Resolution

For Visual Basic applications to function properly, an outgoing event interface must appear in the control's coclass definition. The event interface does not have to be used or implemented, but the even interface must be in the type library.

By default, when you create a new ATL control, Full or Composite, an event interface is not generated if the "Support Connection Points" checkbox is not selected under the Attributes tab from the ATL Object Wizard.

If an event interface was not added with the help of the ATL Object Wizard, you will need to add the event interface to the control manually. You can do this by manually editing the wizard generated IDL code for the ATL control.

The following two code snippets need to be added to the IDL code:
//Add this before the library block in your IDL code
//Begin new code
	[
	  uuid(DC2EF6F1-136F-11d3-8C6C-00C04F542A77),
	  helpstring("IUseATLInExcelEvents Interface"),
	]
	dispinterface IUseATLInExcelEvents 
	{
	};
//End new code
				
//You need to update the coclass to show an event interface
//Just add the code below marked with //Begin new code and //End new code.
//The rest of the code was just provided as a reference point on where
//to add the new code.
[
	uuid(6734BB80-136B-11D3-8C6C-00C04F542A77),
	version(1.0),
	helpstring("ATLVBATest 1.0 Type Library")
]
library ATLVBATESTLib
{
	importlib("stdole32.tlb");
	importlib("stdole2.tlb");

	[
		uuid(6734BB8D-136B-11D3-8C6C-00C04F542A77),
		helpstring("ATLVBA2 Class")
	]
	coclass ATLVBA2
	{
		[default] interface IUseATLInExcel;
//Add the following line to any coclasses in the IDL file that are controls
//and do not have a default, source interface.
//Begin new code
		[default, source] dispinterface IUseATLInExcelEvents;
//End new code
	};
};
				
Once the control is rebuilt and re-registered, it should behave correctly when inserted into Excel. If it still does not behave correctly, you may want to look at the the following KB article:
185473� Changes to Custom ActiveX Controls Are Not Used

↑ Back to the top


Status

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

↑ Back to the top


References

Step 5 of the ATL Tutorial in MSDN. It is located in the index under: ATL Tutorial.

↑ Back to the top


Keywords: kbbug, kbctrlcreate, kbpending, KB241861

↑ Back to the top

Article Info
Article ID : 241861
Revision : 7
Created on : 1/25/2007
Published on : 1/25/2007
Exists online : False
Views : 564