Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual Studio 2003 convert System::String to char array

Status
Not open for further replies.

karateboy02

Programmer
Jul 26, 2007
12
US
I am trying to convert from a System::String to a char array. I have found a code snippet that works in Visual Studio 2005 but when I try to run the same exact code in Visual Studio 2003 I get several errors. The code looks like:


System::String *orig = this->textBox1->Text;
pin_ptr<const wchar_t> wch = PtrToStringChars(orig);

size_t origsize = wcslen(wch) + 1;
const size_t newsize = 100;
size_t convertedChars = 0;
char nstring[newsize];
wcstombs_s(&convertedChars, nstring, origsize, wch, _TRUNCATE);


Where nstring should be where the string ends up. The errors that I get are:

(143): error C2065: 'pin_ptr' : undeclared identifier
(143): error C2059: syntax error : 'const'
(146): error C2065: 'wch' : undeclared identifier
(150): error C2065: '_TRUNCATE' : undeclared identifier
(150): error C3861: 'wcstombs_s': identifier not found, even with argument-dependent lookup
(150): error C3861: 'wch': identifier not found, even with argument-dependent lookup

Any help would be much appreciated.
 
you could try
Code:
char* wch = (char*)(void*)Marshal::StringToHGlobalAns(this->textBox1->Text);
//Do stuff with wch
Marshal::FreeHGlobal(wch); // dont forget to free the created char*
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top