我有一个小问题,我会先解释一下。我正在尝试使用 C++/CLI 将与 C# dll 一起使用的 C# 代码转换为 C++,因此我的 C++ 应用程序可以与 C# dll 一起使用。以下是 C# 代码的一部分
private void USB_OnSpecifiedDeviceRemoved(object sender, EventArgs e)
{
this.DevicePresent = false;
}
this.USB.OnSpecifiedDeviceRemoved += new EventHandler(this.USB_OnSpecifiedDeviceRemoved);
以下是我的 C++ 转换
usb.OnSpecifiedDeviceRemoved += System::EventHandler(this->USB_OnSpecifiedDeviceRemoved(nullptr,nullptr));
void MissileLauncher::USB_OnSpecifiedDeviceRemoved(System::Object sender, System::EventArgs e)
{
}
当我运行我的 C++ 代码时,我收到以下错误
1>------ Build started: Project: CallToCSharp, Configuration: Debug Win32 ------
1> MissileLauncher.cpp
1>MissileLauncher.cpp(109): error C2664: 'MissileLauncher::USB_OnSpecifiedDeviceRemoved' : cannot convert parameter 1 from 'nullptr' to 'System::Object'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>MissileLauncher.cpp(109): fatal error C1903: unable to recover from previous error(s); stopping compilation
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
为什么会这样?有任何想法吗?