Microsoft KB Archive/250847

= BUG: ATL Connection Point Wizard Generated Code for Event with VARIANT Argument Gives C4305 Warning =

Article ID: 250847

Article Last Modified on 12/11/2003

-

APPLIES TO


 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition
 * Microsoft ActiveX Template Library 3.0

-



This article was previously published under Q250847



SYMPTOMS
The ATL Connection Point wizard generates a proxy class that implements a connection point for an out going interface. If an out going interface has an event that takes an argument of type VARIANT, then the wizard generates the wrong code in the out going call (Fire method) for that event. The Visual C++ compiler gives these two warnings when you call this fire method in your code

warning C4305: 'argument' : truncation from 'struct tagVARIANT *' to 'bool'

warning C4800: 'struct tagVARIANT *' : forcing value to bool 'true' or 'false' (performance warning)



CAUSE
Implementing the Connection Point wizard generates the wrong code in the Fire_ method for the event that takes VARIANT as parameter. For Event1, with VARIANT parameter Param1, it generates this code

pVars[0] = &Param1; instead of this pVars[0] = Param1; in Fire_Event1 method of the proxy class.



RESOLUTION
To work around this problem manually remove the "&" before the Param1.



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



Steps to Reproduce Behavior
 Create a new ATL DLL/EXE project. Insert a simple object with Connection Point support. Add a method named Event1 to source(event) interface that takes a VARIANT as parameter Compile the project. Right-click the ATL class and click Implement Connection Point to bring up the Connection Point wizard.</li> Select the event interface and click OK.</li>  Create a test method on the ATL object's incoming interface with VARIANT as a parameter and call it "Fire_Event1". STDMETHODIMP CTestQ::Test(VARIANT var) {   Fire_Event1(var); return S_OK; }

</li> Compile your application to see the warnings C4305 and C4800.</li></ol>

<div class="references_section">