Solved

connection points and a VARIANT argument

Posted on 2002-04-10
4
358 Views
Last Modified: 2008-01-09
I have created a component that acquires data from some instrumentation. When the data acquisition is complete I want to notify the client of the component that the acquisition is complete. Using connection points, I pass the acquired data to the client using a multi-dimensional safe array in a VARIANT.  

Here is the interface definition;

...
...

dispinterface _ICamEvents
{
     properties:
     methods:
     [id(1), helpstring("waiting for external trigger")] HRESULT ExternalTrigger();
     [id(2), helpstring("data acquisition complete")] HRESULT AcquisitionComplete([in] VARIANT rawdata);
};

...
...


I compile the project with no problems. Then when I implement the connection point and compile I get the following eror messages;

d:\components\atdv420\atdv420cp.h(51) : warning C4305: 'argument' : truncation from 'struct tagVARIANT *' to 'bool'
        d:\components\atdv420\atdv420cp.h(35) : while compiling class-template member function 'long __thiscall CProxy_ICamEvents<class CDV420>::Fire_AcquisitionComplete(struct tagVARIANT)'
d:\components\atdv420\atdv420cp.h(51) : warning C4800: 'struct tagVARIANT *' : forcing value to bool 'true' or 'false' (performance warning)
        d:\components\atdv420\atdv420cp.h(35) : while compiling class-template member function 'long __thiscall CProxy_ICamEvents<class CDV420>::Fire_AcquisitionComplete(struct tagVARIANT)'


Here is the proxy generated code;


HRESULT Fire_AcquisitionComplete(VARIANT rawdata)
{
     CComVariant varResult;
     T* pT = static_cast<T*>(this);
     int nConnectionIndex;
     CComVariant* pvars = new CComVariant[1];
     int nConnections = m_vec.GetSize();
         
     for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++)
     {
          pT->Lock();
          CComPtr<IUnknown> sp = m_vec.GetAt(nConnectionIndex);
          pT->Unlock();
          IDispatch* pDispatch = reinterpret_cast<IDispatch*>(sp.p);
          if (pDispatch != NULL)
          {
               VariantClear(&varResult);
               pvars[0] = &rawdata;
               DISPPARAMS disp = { pvars, NULL, 1, 0 };
               pDispatch->Invoke(0x2, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, &varResult, NULL, NULL);
          }
     }
     delete[] pvars;
     return varResult.scode;
}


If I change the line of code from

pvars[0] = &rawdata;

to the following;

pvars[0] = rawdata;

Everything works fine and I can access the data from the client. Am I doing something wrong or is this an error with the proxy generator?
0
Comment
Question by:johndixson
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
job_s earned 200 total points
ID: 6933468
You are right .That is the problem of the proxy code generator.

CComVariant class only supports these types as RHS for = operator

If we give as &Variant it will treat as a bool

note no *VARIANT

CComVariant& operator =( const CComVariant& varSrc );
CComVariant& operator =( const VARIANT& varSrc );
CComVariant& operator =( LPCOLESTR lpsz );
CComVariant& operator =( LPCSTR lpsz );
CComVariant& operator =( BSTR bstrSrc );
CComVariant& operator =( bool bSrc );
CComVariant& operator =( int nSrc );
CComVariant& operator =( BYTE nSrc );
CComVariant& operator =( short nSrc );
CComVariant& operator =( long nSrc );
CComVariant& operator =( float nSrc );
CComVariant& operator =( double nSrc );
CComVariant& operator =( CY cySrc );
CComVariant& operator =( IDispatch* pSrc );
CComVariant& operator =( IUnknown* pSrc );

0
 

Author Comment

by:johndixson
ID: 6933978
Does this mean it's invalid to modify the code? Or it this acceptable?
0
 
LVL 3

Expert Comment

by:job_s
ID: 6933985
I mean Ur right.U must modify the code to work it correctly.
0
 

Author Comment

by:johndixson
ID: 6933997
Thanks, it just adds a little uncertainty to an already complex problem!
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question