Solved

connection points and a VARIANT argument

Posted on 2002-04-10
4
359 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Cross compile release version of c++ program for linux 2 138
passing data from one form to another form in c++ 27 88
c++, dynamic object by json 1 60
C++ help/ Toy problem 19 50
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. …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

763 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