2011-11-02 2 views
0

저는 C++과 Im의 새로운 VS2010입니다. 누군가 아래 코드를 확인하고 해결할 수 있습니까? UpdateDataGrid(unsigned char CANPacket[15]) 함수가 호출 될 때마다 다음 메시지가 새 창에 표시되고 응용 프로그램이 닫힙니다.VS C++ InvokeRequired/delegate 관련 문제 void

An unhandled exception of type 'System.ArgumentException' occurred in System.Windows.Forms.dll 
Additional information: Object of type 'System.Byte' cannot be converted to type 'System.Byte*'. 

나는 unsinged char 데이터 형식을 사용할 필요하지 String^이 프로젝트이다. 내 코드를 수정할 방법이 있습니까?

//Piece of my code 

namespace VCCDC { 

using namespace System; 
using namespace System::ComponentModel; 
using namespace System::Collections; 
using namespace System::Windows::Forms; 
using namespace System::Data; 
using namespace System::Drawing; 
using namespace System::Threading; 

public ref class Form1 : public System::Windows::Forms::Form 
{ 
    delegate void UpdateDataGridCallback(unsigned char CanPacket[15]); 


    private: void UpdateDataGrid(unsigned char CANPacket[15]) { 

     if (this->dataGridView1->InvokeRequired) { 

      UpdateDataGridCallback^ d = gcnew UpdateDataGridCallback(this,&VCCDC::Form1::UpdateDataGrid); 
      this->Invoke(d,gcnew unsigned char(CANPacket[15])); 
     } 

     else { 
      //Update dataGridView1 with new data 

     } 

    } 
} 
}] 

답변

0

변경

this->Invoke(d,CANPacket)); 

당신은 이미 unsigned char 포인터를 가지고있는 라인

this->Invoke(d,gcnew unsigned char(CANPacket[15])); 

, 그것을 통해 전달합니다. gcnew을 사용하면 다른 것을 만들려고하는데 이는 불필요합니다.

이 오류로 인한 오류는 gcnew 행입니다. Byte 매개 변수를 사용하여 Byte*을 구성해야합니다. 귀하의 콘텐츠도 Byte*입니다.