BUG: Microsoft Agent CAPMFC Sample May Cause an 0xC0000005 Access Violation or First Chance Exception (224929)



The information in this article applies to:

  • Microsoft ActiveX SDK
  • The Microsoft Foundation Classes (MFC)

This article was previously published under Q224929

SYMPTOMS

When running the CAPMFC sample and right-clicking a Microsoft Agent character to bring up the context menu associated with the character, you may get an access violation. This occurs when selecting the Advanced Character Properties from the Context menu.

CAUSE

After clicking Advanced Character Properties, CCapMFCDlg::OnCommandAgent() is called. This function has a bug in it. The parameter passed to OnCommandAgent is a IDispatch pointer and should be treated as an [in] parameter that should not be released.

The first line in this function creates a new CAgentCtlUserInput object (which is derived from COleDispatchDriver) and passes the IDispatch pointer passed in to the constructor. By default, COleDispatchDriver objects release any pointers when they are destroyed. Therefore, the IDispatch pointer passed in is released when the CAgentCtlUserInput object's destructor is called.

RESOLUTION

You need to change the OnCommandAgent function, as shown below, so that the IDispatch pointer is not released when the userInput object is destroyed.
void CCapMFCDlg::OnCommandAgent(LPDISPATCH UserInput) 
{
  CAgentCtlUserInput userInput(UserInput);
  CAgentCtlCharacterEx Character;
  CAgentCtlPropertySheet PropertySheet;
  COleVariant vEmpty;

  if (userInput.GetName() == kpszCommandProperties) 
  {
   // Get the property sheet:
   PropertySheet = m_Agent.GetPropertySheet();

   // Show it:
   PropertySheet.SetVisible(TRUE);

   // Get the character:
   _ASSERT(m_pszCurCharID);

   Character = m_Agent.GetCharacters().Character(m_pszCurCharID);

   // Stop it:
   Character.StopAll(vEmpty);

   // Gesture at the property sheet:
  Character.GestureAt(PropertySheet.GetLeft()+(PropertySheet.GetWidth()/2),
                 PropertySheet.GetTop() + (PropertySheet.GetHeight() / 2));
  }
//new code
//This causes the destructor to not call Release() on IDispatch pointer
  userInput.DetachDispatch(); 
//end new code
}
				

STATUS

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

MORE INFORMATION


Steps to Reproduce Behavior

  1. Build the CAPMFC sample and run it under the debugger.
  2. Open a character by choosing File from the Open menu.
  3. Right-click the character to bring up the Context menu.
  4. Select Advanced Character Properties.


Notice a first chance exception in the Debug Output window.

REFERENCES

Agent 2.0 SDK

Modification Type:MinorLast Reviewed:8/19/2005
Keywords:kbAutomation kbbug KB224929