Conversion between array<String^>^ and const char *const* and back?
-
Attempting to dig into C++/CLI by wrapping VLC with it. You'd know the very fist thing I run across is conversions between arrays in C++/CLI and C++. Are there any 'conversion' libraries/utilities out there?? Thanks,
ed ~"Watch your thoughts; they become your words. Watch your words they become your actions. Watch your actions; they become your habits. Watch your habits; they become your character. Watch your character; it becomes your destiny." -Frank Outlaw.
-
Attempting to dig into C++/CLI by wrapping VLC with it. You'd know the very fist thing I run across is conversions between arrays in C++/CLI and C++. Are there any 'conversion' libraries/utilities out there?? Thanks,
ed ~"Watch your thoughts; they become your words. Watch your words they become your actions. Watch your actions; they become your habits. Watch your habits; they become your character. Watch your character; it becomes your destiny." -Frank Outlaw.
Ed K wrote:
Conversion between array<String^>^ and const char *const* and back
You don't need any library functions to do this. It's simple enough to write. Converting
String^
tochar*
String^ str = "Hello world!";
IntPtr p = Marshal::StringToHGlobalAnsi(str);
char *nativeString = static_cast<char*>(p.ToPointer());
Marshal::FreeHGlobal(p);Converting
char*
toString^
const char* native = "hello world";
String^ managed = gcnew String(f);Now you know the basic conversions and it will be easy to create
const char *const*
from a managed string array. :)Best wishes, Navaneeth
-
Ed K wrote:
Conversion between array<String^>^ and const char *const* and back
You don't need any library functions to do this. It's simple enough to write. Converting
String^
tochar*
String^ str = "Hello world!";
IntPtr p = Marshal::StringToHGlobalAnsi(str);
char *nativeString = static_cast<char*>(p.ToPointer());
Marshal::FreeHGlobal(p);Converting
char*
toString^
const char* native = "hello world";
String^ managed = gcnew String(f);Now you know the basic conversions and it will be easy to create
const char *const*
from a managed string array. :)Best wishes, Navaneeth
If you are using .Net 3.5 or newer, you can use the marshalling library: http://msdn.microsoft.com/en-us/library/bb384865.aspx[^] For your example, the marshal_context methods are probably most appropriate, then you can leave RAII to clear up the HGlobal stuff internally. You will still need to loop over the array elements though.
-
If you are using .Net 3.5 or newer, you can use the marshalling library: http://msdn.microsoft.com/en-us/library/bb384865.aspx[^] For your example, the marshal_context methods are probably most appropriate, then you can leave RAII to clear up the HGlobal stuff internally. You will still need to loop over the array elements though.
ian__lindsay wrote:
For your example, the marshal_context methods are probably most appropriate, then you can leave RAII to clear up the HGlobal stuff internally.
Correct. Beauty of stack semantics! :)
Best wishes, Navaneeth
-
Ed K wrote:
Conversion between array<String^>^ and const char *const* and back
You don't need any library functions to do this. It's simple enough to write. Converting
String^
tochar*
String^ str = "Hello world!";
IntPtr p = Marshal::StringToHGlobalAnsi(str);
char *nativeString = static_cast<char*>(p.ToPointer());
Marshal::FreeHGlobal(p);Converting
char*
toString^
const char* native = "hello world";
String^ managed = gcnew String(f);Now you know the basic conversions and it will be easy to create
const char *const*
from a managed string array. :)Best wishes, Navaneeth
N a v a n e e t h wrote:
It's simple enough to write.
Really? why does C++ need another type of string for each new string? after all, a string is a string. :laugh:
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
N a v a n e e t h wrote:
It's simple enough to write.
Really? why does C++ need another type of string for each new string? after all, a string is a string. :laugh:
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Luc Pattyn wrote:
why does C++ need another type of string for each new string? after all, a string is a string.
Not sure I got you :confused:
Best wishes, Navaneeth
-
Luc Pattyn wrote:
why does C++ need another type of string for each new string? after all, a string is a string.
Not sure I got you :confused:
Best wishes, Navaneeth
It seems C++ offers more string types than I have strings in a typical app. Just wondering why that is. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
It seems C++ offers more string types than I have strings in a typical app. Just wondering why that is. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Luc Pattyn wrote:
It seems C++ offers more string types than I have strings in a typical app. Just wondering why that is.
Ok. I guess you are talking about the various string types shown in the
marshal_context
MSDN page.std::string
is the only string type that C++ standard provides. Rest everything is non-standard. When it comes to C++/CLI,System::String^
is the standard string type.CString
is Microsoft's implementation for MFC. :)Best wishes, Navaneeth