Click here to Skip to main content
14,774,521 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more: (untagged)

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;   

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
Updated 17-Aug-12 4:04am
Sergey Alexandrovich Kryukov 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.
Maciej Los 17-Aug-12 18:32pm
Agree ;)
Would you post it as the answer, just to close the question?
Maciej Los 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)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900