Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > Visual C++
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 16th, 2005, 12:28 PM
Registered User
 
Join Date: Nov 2005
Location: , , .
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
Reply With Quote
  #2 (permalink)  
Old November 19th, 2005, 04:13 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 453
Thanks: 0
Thanked 0 Times in 0 Posts
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
Reply With Quote
  #3 (permalink)  
Old November 19th, 2005, 05:04 AM
Registered User
 
Join Date: Nov 2005
Location: , , .
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

Reply With Quote
  #4 (permalink)  
Old November 19th, 2005, 12:51 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 453
Thanks: 0
Thanked 0 Times in 0 Posts
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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 02:35 AM



All times are GMT -4. The time now is 10:23 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.