Solved

connection points and a VARIANT argument

Posted on 2002-04-10
4
357 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Quicksort a dynamic deque 33 72
I could not build boost code, 10 88
C++ error cannot convert from std::string to const char * 6 185
Unable to start eclipse ? 17 141
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

777 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