Solved

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

Posted on 2011-09-23
4
418 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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

770 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