Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++/CLI
hi,
 
i was trying to read the text/string from an ini file and i want to put it in textBox1->Text
i did some research and tried these
 
void MarshalString ( System::String^ s, std::string& os )
{   
using namespace System::Runtime::InteropServices;   
const char* chars = (const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer();   
os = chars;   
Marshal::FreeHGlobal(IntPtr((void*)chars));
}
 
button1:
.....
string std_string = pt.get<std::string>("Section1.Value1");
String^ str = "";
				 
MarshalString(str, std_string);
textBox1->Text = str;
 
but it gives me this error:
Additional information: External component has thrown an exception.
 
any better ways to do it? thank you in advance
Posted 17-Aug-12 3:56am
Edited 17-Aug-12 4:04am
v3
Comments
Sergey Alexandrovich Kryukov at 17-Aug-12 12:52pm
   
This is a conversion std:string to w_char[] to System.String. Could also be a case of a string compiled as non-Unicode. Basically, this is the answer. My 5.
--SA
losmac at 17-Aug-12 18:32pm
   
Agree ;)
Sergey Alexandrovich Kryukov at 20-Aug-12 1:20am
   
Would you post it as the answer, just to close the question?
--SA
losmac at 17-Aug-12 18:31pm
   
Code looks OK, but - probably - textBox1 is throwing an exception.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,142
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 17 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100