Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-09-23
4
Medium Priority
?
430 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 35

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 35

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 35

Accepted Solution

by:
sarabande earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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 difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

972 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