Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.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
Visual studio 2010 Microsoft Visual C++;2010年Win表格申请表 < P>为开发串口接收数据,处理微软Visual C++ 2010的表单应用程序!p>_Visual Studio 2010_Visual C++ - Fatal编程技术网

Visual studio 2010 Microsoft Visual C++;2010年Win表格申请表 < P>为开发串口接收数据,处理微软Visual C++ 2010的表单应用程序!p>

Visual studio 2010 Microsoft Visual C++;2010年Win表格申请表 < P>为开发串口接收数据,处理微软Visual C++ 2010的表单应用程序!p>,visual-studio-2010,visual-c++,Visual Studio 2010,Visual C++,为了接收数据,我使用Read方法,提供输入缓冲区。但在读取数据时,获取System.ArgumentNullException(缓冲区不能为null)异常。下面是代码的一部分。有人能帮我解释为什么我在处理这个异常吗 this->sp1->Open(); array<wchar_t>^ buf2; this->sp1->Read(buf2,1,1024); this->sp1->Close(); this->sp1->Open(); 数组^b

为了接收数据,我使用Read方法,提供输入缓冲区。但在读取数据时,获取System.ArgumentNullException(缓冲区不能为null)异常。下面是代码的一部分。有人能帮我解释为什么我在处理这个异常吗

this->sp1->Open();

array<wchar_t>^ buf2;

this->sp1->Read(buf2,1,1024);

this->sp1->Close();
this->sp1->Open();
数组^buf2;
此->sp1->读取(buf2,11024);
此->sp1->关闭();

您的缓冲区没有初始大小。尝试:

array<wchar_t>^ buffer = gcnew array<wchar_t>(1024);
array^buffer=gcnewarray(1024);

buf2
未初始化,因此为空

array<wchar_t>^ buf2 = gcnew array<wchar_t>(1024);
array^buf2=gcnewarray(1024);