C++ cli VS C++;调用请求/委托无效的问题 我是C++新手,IM使用VS2010。 有人可以检查下面的代码并帮助解决它吗?每次函数UpdateDataGrid(unsigned char CANPacket[15]) 调用时,将在新窗口中显示以下消息,并且应用程序将关闭 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*'.

C++ cli VS C++;调用请求/委托无效的问题 我是C++新手,IM使用VS2010。 有人可以检查下面的代码并帮助解决它吗?每次函数UpdateDataGrid(unsigned char CANPacket[15]) 调用时,将在新窗口中显示以下消息,并且应用程序将关闭 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*'.,c++-cli,serial-port,invoke,C++ Cli,Serial Port,Invoke,我必须在这个项目中使用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 S

我必须在这个项目中使用
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

        }

    }
}
}]
换线

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

您已经有了一个
无符号字符
指针,请将其传递出去。使用
gcnew
可以创建另一个,这是不必要的

gcnew
行也会导致错误。必须使用
Byte
参数构造
Byte*
。你的也是字节*

this->Invoke(d,CANPacket));