0

I want to recuperate a combobox value as an std::string to use it as a parameter in another function.

std::string mystring = msclr::interop::marshal_as<std::string>(myComboBox->Text->ToString());

but it didn't work. Can someone help me.

  • 1
    you should probably share the error message with us – Alessandro Teruzzi Jan 22 '16 at 16:32
  • The error is that i can't use the combobox value as a paramaeter in my 'function(std::string variable1)'. i need to convert it to std::string first. – user5712010 Jan 23 '16 at 11:02
  • The error i get : 'no suitable constructor exists to convert from "System::String ^" to "std::basic_string, std::allocator>" ' which is not surprising. – user5712010 Jan 23 '16 at 12:18
  • so, your real question is how to converst System::String^ to std::string? Isn't it. This link may help http://stackoverflow.com/questions/1300718/c-net-convert-systemstring-to-stdstring – Alessandro Teruzzi Jan 25 '16 at 09:18
  • I am having the error :' Error C4996 'msclr::interop::error_reporting_helper<_To_Type,_From_Type,false>::marshal_as': This conversion is not supported by the library or the header file needed for this conversion is not included. Please refer to the documentation on 'How to: Extend the Marshaling Library' for adding your own marshaling method. ' – user5712010 Jan 25 '16 at 11:55
  • 1
    i found the solution : IntPtr p = Marshal::StringToHGlobalAnsi(dev); string DeviceName; DeviceName = static_cast(p.ToPointer()); Marshal::FreeHGlobal(p); – user5712010 Jan 26 '16 at 14:56

0 Answers0