Help and Support

Article ID: 241810 - Last Review: June 6, 2005 - Revision: 3.0

IDispEventImpl event handlers may give strange values for parameters in Visual C++

This article was previously published under Q241810

On This Page

Expand all | Collapse all

SYMPTOMS

When using IDispEventImpl in a client that is sinking events with parameters that have different data types with different sizes, the handlers of the events will get incorrect values for the event parameters. The following sample IDL code will cause problems when sinking the event in an ATL client.

[//attributes omitted for brevity.
]
dispinterface _ISomeEvents
{
  properties:
  methods:
  [id(1), helpstring("method Event1")] HRESULT Event1([in] short s, [in] double d);
};

CAUSE

The cause is errors in the GetFuncInfoFromId() function in the IDispEventImpl class, which is located in Atlcom.h.

The following code (in Atlcom.h, line 3918) is in error:
for (int i=0; i<pFuncDesc->cParams; i++)
{
  info.pVarTypes[i] = pFuncDesc->lprgelemdescParam[pFuncDesc->cParams - i - 1].tdesc.vt;
  if (info.pVarTypes[i] == VT_PTR)
     info.pVarTypes[i] = pFuncDesc->lprgelemdescParam[pFuncDesc->cParams - i - 1].tdesc.lptdesc->vt | VT_BYREF;
  if (info.pVarTypes[i] == VT_USERDEFINED)
     info.pVarTypes[i] = GetUserDefinedType(spTypeInfo,pFuncDesc->lprgelemdescParam[pFuncDesc->cParams-i-1].tdesc.hreftype);
}

The code should instead be:
for (int i=0; i<pFuncDesc->cParams; i++)
{
  info.pVarTypes[i] = pFuncDesc->lprgelemdescParam[i].tdesc.vt;
  if (info.pVarTypes[i] == VT_PTR)
     info.pVarTypes[i] = pFuncDesc->lprgelemdescParam[i].tdesc.lptdesc->vt | VT_BYREF;
  if (info.pVarTypes[i] == VT_USERDEFINED)
     info.pVarTypes[i] = GetUserDefinedType(spTypeInfo,pFuncDesc->lprgelemdescParam[i].tdesc.hreftype);
}

RESOLUTION

Workarounds

There are three workarounds for this problem:
  • Provide the type information for the sink method by using the SINK_ENTRY_INFO() macro instead of SINK_ENTRY() or SINK_ENTRY_EX(). For additional information on how to use this macro, click the article number below to view the article in the Microsoft Knowledge Base:
    194179  (http://support.microsoft.com/kb/194179/EN-US/ ) SAMPLE: AtlEvnt.exe Creates ATL Sinks Using IDispEventImpl
  • Override the virtual function GetFuncInfoFromId() in your IDispEventImpl-derived class. The new function should be identical to the original except for the five altered lines in the code shown in the Cause section of this article.
  • Change the incorrect code in Atlcom.h for the IDispEventImpl::GetFuncInfoFromId() function:

    1. Copy the file Atlcom.h in your project directory and name it Atlcom-fix.h.
    2. Change the reference to Atlcom.h in StdAfx.h to Atlcom-fix.h.
    3. In Atlcom-fix.h, change the code for the IDispEventImpl::GetFuncInfoFromId() function as described in the Cause section of this article.
    4. Save Atlcom-fix.h.
    5. From the Build menu, select, Rebuild All. Do this on a Debug or ReleaseMinDependency build so that the modified code described previously will be linked into your code.

STATUS

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

APPLIES TO
  • Microsoft ActiveX Template Library 3.0, when used with:
    • Microsoft Visual C++ 6.0 Enterprise Edition
    • Microsoft Visual C++ 6.0 Professional Edition
    • Microsoft Visual C++, 32-bit Learning Edition 6.0
Keywords: 
kbtshoot kbbug kbconnpts kbpending kbactivexevents KB241810

Article Translations