Skip to main content
GameDev.net gamedev.net
🔒 Locked

String^ to char[]

Started by phi Oct 11, 2006 at 6:13 AM 2 replies 1.1k views
Original Post
phi
phi
Hi, I'm using VC++ .NET with FMOD. When a button is pressed, the file dialog box is opened. The user then selects the file and presses OK. I can obtain the pathname of the selected file and it's stored in String^ like so: String^ fPath = openFileDialog1->FileName; //where openFileDialog1 is the name of the dialog box and FileName is a method of that class. However, when I try and import this into FMOD's createSound system, I get a "cannot convert String^ to char[] * " error message. How do I fix this problem? Also, what does the ^ stand for after the String? Thanks
Emmanuel Deloget
Emmanuel Deloget
Quote:
Original post by phi
Hi,
I'm using VC++ .NET with FMOD. When a button is pressed, the file dialog box is opened. The user then selects the file and presses OK. I can obtain the pathname of the selected file and it's stored in String^ like so:
String^ fPath = openFileDialog1->FileName; //where openFileDialog1 is the name of the dialog box and FileName is a method of that class.

However, when I try and import this into FMOD's createSound system, I get a "cannot convert String^ to char[] * " error message. How do I fix this problem? Also, what does the ^ stand for after the String?
Thanks


It means that it is a garbage collected pointer.

System::String to char conversion: check here

Regards,
jpetrie
jpetrie
It also means you are using C++/CLI, instead of C++ (this is a neccessary thing if you want to interface with the managed WinForms APIs, such as the file browser you're using). It isn't a bad thing, but it is something to be aware of.
paic
paic
I use this method (found in the MSDN help) :

using namespace System;using namespace System::Runtime::InteropServices;System::String ^ str = "test";const char * chars = (const char *)(Marshal::StringToHGlobalAnsi(str)).ToPointer();/* do what you want with your chars, and clean it after your done : */Marshal::FreeHGlobal(IntPtr((void*)chars));


Don't forget to clean the const char * variable.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.