Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

connection points and a VARIANT argument

Posted on 2002-04-10
4
Medium Priority
?
367 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 800 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

926 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