Solved

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

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

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…
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 clear a vector as well as how to detect empty vectors in C++.
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.

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now