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