1 Replies - 265 Views - Last Post: 26 June 2017 - 05:20 PM

#1 hexagod  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 242
  • Joined: 29-October 16

No Instance of Overloaded Function "Utility::marshal_as" Match

Posted 26 June 2017 - 03:09 PM

Trying to use marshal strings to convert a managed String^ to std::string and get the following error message from the compiler. I've had this problem before and I can't remember how I fixed it. I'm going to post this here so that the next time this happens I will be able to look it up on here for reference sake and I will probably not be the last person to have this problem.

no instance of overloaded function "Utility::marshal_as" matches the argument list Utility c:\xxxxx\xxxx\xxxxxx\Utility (v2 Backup) - Copy (2)\Utility\MyForm.h 1937

#include <stdlib.h>
#include <msclr\marshal_cppstd.h>
#include <Windows.h>
#include <iostream>
	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	using namespace std;
	using namespace msclr::interop;
String^ textBox1info;


private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) 
{
	textBox1info = textBox1->Text;
	string textBox1infostd = marshal_as<std::string>(textBox1info);

}



Problem was: apparently you have to define the managed string inside the button in order to use marshal string converter.

can anyone explain to me why?

{
	String^ textBox1info = textBox1->Text;
	string textBox1infostd = marshal_as<std::string>(textBox1info); 

}


Is This A Good Question/Topic? 0
  • +

Replies To: No Instance of Overloaded Function "Utility::marshal_as" Match

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 5922
  • View blog
  • Posts: 20,246
  • Joined: 05-May 12

Re: No Instance of Overloaded Function "Utility::marshal_as" Match

Posted 26 June 2017 - 05:20 PM

As explained in the documentation, some marshalling requires a context. In your first version of the code, the global variable does not give enough context.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1