Click here to Skip to main content
12,998,654 members (129,798 online)
Rate this:
Please Sign up or sign in to 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
Posted 17-Aug-12 2:56am
Updated 17-Aug-12 3: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.
losmac 17-Aug-12 18:32pm
Agree ;)
Would you post it as the answer, just to close the question?
losmac 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170622.1 | Last Updated 17 Aug 2012
Copyright © CodeProject, 1999-2017
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