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

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top