Solved

connection points and a VARIANT argument

Posted on 2002-04-10
4
354 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
Comment Utility
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
Comment Utility
Does this mean it's invalid to modify the code? Or it this acceptable?
0
 
LVL 3

Expert Comment

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

Author Comment

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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now