ZFGC

Resources => Coding => Topic started by: therabidwombat on July 19, 2006, 05:01:51 am

Title: Using Managed C++
Post by: therabidwombat on July 19, 2006, 05:01:51 am
Okay, so for whatever reason, you're using managed C++. And you have a managed String (String ^) or an array of wide characters (widechar_t). For whatever reason, you need to convert that data into a char*. Well, you look through code on the internet, and you find a lot of discussion on how to do it, but no one really has a simple answer. They're all functions that, when you plug them into your code, you find don't actually work. So what do you do?

You use this function:

(char*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(YOUR DATA HERE).ToPointer();

Now, the question that I have: Why couldn't they have simply put this in the System::Convert namespace, like all the other convert functions? Wouldn't that have been really cool? It would have saved me four hours of coding and googling, that's for sure.

Although really, I don't know why it took me so long to find it. If you look at the function name, it's really quite a simple path to follow exploring your intellisense to find that.

(No seriously, whoever originally found that function deserves a medal or something.)

Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved