Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

In Visual C++, I want to know how to extract a String from a VARIANT so I can use it as a String (CString) (The Variant is the return value of the CCWGPIB::Read() function)

I am using the GPIB ActiveX from the ComponentWork in Visual C++ (Class CCWGPIB).

I read data from the GPIB control using the
CCWGPIB::Read() function and I want to put the result into a Edit Box. I put the result from the Read function into a VARIANT variable but I am unable to extract the string from it.

My code to read data looks like this:

OLeVariant v_Buffer;
v_Buffer = m_GPIB.Read(v_BufferSize);

The result should be "National Instrument ..." if I write the "*IDN?" command but the only thing I was able to extract from v_Buffer is a "N", but when I debbug the prog
ram the variable contain something like {0x016c19a"National Instrument.....}
I want to know how to extract the whole string from the VARIANT so I can show it on the screen.

Thank alot
you can E-Mail me at ericclermont@hotmail.com

P.S. Excuse me for the quality of the writing, I speek French so my English is not very good...
0 Kudos
Message 1 of 4
(3,831 Views)
Ok well... So I have solve my own problem, but I post this in case you enconter the same problem.

I have tried different things to correct my problem and I have found that it is possible to extract the String into a BSTR variable. Then I can use the BSTR to print the String returned on the edit box.
My code now looks like this and it works well.

BSTR str_Buffer;
str_Buffer = m_GPIB.Read(v_BufferSize).puiVal;

m_Resultat = str_Buffer;
m_Resultat.TrimRight("\n");
UpdateData(false);
0 Kudos
Message 2 of 4
(3,830 Views)
If you have Measurement Studio and this is not a legacy project with a lot of existing code, you should use ComponentWorks++ instead of the ComponentWorks ActiveX control. ComponentWorks++ contains native C++ classes for doing GPIB and VISA programming. In addition to other benefits, these classes use C++ data types rather than the ActiveX data types that you get with the VC-generated wrappers for the ActiveX controls.

Even if your project is such that you don't want to port all your code to use the C++ classes, there is a CNiVariant class which makes it easier to use any ActiveX control in VisualC++.

One more tip for debugging. In the watch window, follow the name of the BSTR variable with ", su" (no quotes) to see the ASCII characters in the string as you debug
.
Message 3 of 4
(3,830 Views)
Please explain how to use ComponentWorks++ instead of ComponentWorks ActiveX control from within Visual C++.
0 Kudos
Message 4 of 4
(3,830 Views)