Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > Visual C++
|
Visual C++ Questions specific to Microsoft's Visual C++. For questions not specific to this Microsoft version, use the C++ Programming forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual C++ section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 16th, 2005, 12:28 PM
Registered User
 
Join Date: Nov 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Casting System::Object __gc * to System.Double[]

Hello,

I'm using Visual C++ .NET 2003. I have a function which returns, say,
  System::Object __gc *rms
(this function is a member of a COM object).

Console::Write(rms) prints System.Double[], but I don't know how to get the values. I know I should get four doubles, but whatever I try, I get an Index out of bounds message.

Michel Aristegui
 
Old November 19th, 2005, 04:13 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

I dont have the entire code that you have at your end. But i belive if the underlying type is indeed System::Double[], then simple casting would work.

Try something like this, if you havent already

    System::Double ss[] = new System::Double[4];

    ss = (System::Double[])rms;
    Console::WriteLine(ss[0]);

Be sure about the underlying type of the returned value before casting though.

Regards
Ankur Verma
 
Old November 19th, 2005, 05:04 AM
Registered User
 
Join Date: Nov 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,

Thanks for your reply.

ss[0] gives me a Double, but I can't get the other three. ss[1] doesn't work (index out of bounds).

Michel

 
Old November 19th, 2005, 12:51 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

Hi Michel, as I said I didnt have the complete code. So I wrote a minimal function that returns the pointer of the said type.
Now at my end I'm being able to access all four of the nodes. Just Debug though the code and see in any of the Watch windows if the returned pointer is in consistent state and indeed has all those four nodes. That is if havent done that already. Do write back, this is intresting stuff.

Regards
Ankur Verma





Similar Threads
Thread Thread Starter Forum Replies Last Post
System.InvalidCastException; System.Reflection.Tar Jophie BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 January 16th, 2008 03:29 PM
Insert System date and System Time -Form _TextBox cnkumar74 VB How-To 14 February 14th, 2007 10:52 AM
Accessing System Resources of a Remote System harsh_hot J2EE 0 February 9th, 2006 01:13 AM
SQL Double Booking System URGENT help needed! chris_smith_51 SQL Language 0 December 11th, 2004 04:27 PM
File System Object kumar_rajeshk Pro VB 6 7 April 28th, 2004 01:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.