Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
User interface C++;? 当我在C++中使用GUI时,我认为文本字段是作为托管字符串存储的。我需要一种将它们转换为标准整数、浮点和字符串的方法。有什么帮助吗?_User Interface_C++ Cli_Unmanaged_Managed - Fatal编程技术网

User interface C++;? 当我在C++中使用GUI时,我认为文本字段是作为托管字符串存储的。我需要一种将它们转换为标准整数、浮点和字符串的方法。有什么帮助吗?

User interface C++;? 当我在C++中使用GUI时,我认为文本字段是作为托管字符串存储的。我需要一种将它们转换为标准整数、浮点和字符串的方法。有什么帮助吗?,user-interface,c++-cli,unmanaged,managed,User Interface,C++ Cli,Unmanaged,Managed,您可以使用将System.String转换为非托管字符*。打完电话后一定要把它放出来。要将字符串转换为数值,可以使用常规的.NET解析函数,如Int32.Parse要在本机代码中使用托管内存,必须先将托管内存的内容复制到本机内存中 例如: 从托管内存复制内容的步骤如下: const int len = 50; BYTE *destination = new BYTE[nLength]; System::Byte source[] = new System::Byte[len]; System:

您可以使用将System.String转换为非托管字符*。打完电话后一定要把它放出来。要将字符串转换为数值,可以使用常规的.NET解析函数,如
Int32.Parse

要在本机代码中使用托管内存,必须先将托管内存的内容复制到本机内存中

例如:

从托管内存复制内容的步骤如下:

const int len = 50;
BYTE *destination = new BYTE[nLength];
System::Byte source[] = new System::Byte[len];

System::Runtime::InteropServices::Marshal::
  Copy(source, 0, IntPtr((void *)destination, len);
因为我们处理的是托管内存,所以垃圾收集可能会将托管数据转移并移动到另一个位置,如果我们试图定位要转换的数据,所有这些都将丢失

因此,我们希望通过使用_pin将其从托管转换为非托管,将其“固定在内存中”:

const int len = 50;
BYTE *source              = new BYTE[len];
System::Byte destination[]     = new System::Byte[len];
BYTE __pin *managedData = &(destination[0]);

::memcpy(source, managedData, len);

您只需通过以下方式将System::String^对象转换为MFC CString

CString* name = new CString(managedName);
其中managedName是一个托管字符串