Domanda

Can you help me resolve this error:

enter image description here

The values I am passing is a type String^ and I am actually passing the values in a template class but shows an error

È stato utile?

Soluzione

To start with it looks like you're trying to pass a managed memory 'username' to an unmanaged function.

String^ s = gcnew String("sample string");
IntPtr ip = Marshal::StringToHGlobalAnsi(s);
const char* str = static_cast<const char*>(ip.ToPointer());

Console::WriteLine("(managed) passing string...");
NativeTakesAString( str );

Marshal::FreeHGlobal( ip );

reference: http://msdn.microsoft.com/en-us/library/22e4dash.aspx

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top