Solved

How to extract data in CLR C++ .NET console application

Posted on 2011-09-23
4
419 Views
Last Modified: 2012-05-12

So I'm accessing a COM vendor DLL from a VC++ .NET CLR console application and calling a "get" on one of their class properties as follows.

IDACSpectrumPtr pSpectrum;
VARIANT pfIntensities;
pSpectrum->get_Intensities(&pfIntensities); VARIANT debug data
From other languages I know this returns an array of floats.  I also know there are 299 values.  I can see in the debugging information (attached) that the parray element of the returned variant has 299 elements in it -- so I KNOW its there.  The question is, how do I get the data out of it?  So far can't get anything to work.  I saw an example in MFC C++ that uses SafeArrayAccessData to convert a VARIANT, but I do not think that is available to me in a CLR C++ .NET console application.  What is the .NET way to get my data out of a variant?

Thanks very much for any help.
0
Comment
Question by:riceman0
  • 3
4 Comments
 
LVL 33

Expert Comment

by:sarabande
ID: 36598050
i am not expert in clr c++ but i know that you can call GetObjectForNativeVariant passing the VARIANT as IntPtr. the call would return Object^.

i have seen c# code which uses the object returned "as array" and i think there are similar ways in managed c++.

i will look further and return if i found some appropriate code.

Sara
0
 
LVL 33

Expert Comment

by:sarabande
ID: 36598108
it seems you simply can make dynamic_cast on int array cause the Object returned already has right array type.

Sara
0
 

Author Comment

by:riceman0
ID: 36599229
Sounds promising, but in your travels did you see some syntax for that?  

For example,

 float * pc = dynamic_cast<float*>(pfIntensities.parray);

gives me the error

"float *" is an invalid target type for dynamic cast.
0
 
LVL 33

Accepted Solution

by:
sarabande earned 500 total points
ID: 36599524
as told i am not a clr programmer myself.
but i would try like

 int[] arr = dynamic_cast<int[]> (GetObjectForNativeVariant(pfIntensities));

you will find some code when looking for GetObjectForNativeVariant and c++ keywords.

the float probably is not a suitable Array type in managed c++ while 32-bit integer is. the variant is realized as an union and type, rank and element count information is available from variant. so the clr pretty well can create an array object out of that.

Sara
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

829 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