因此,我查看了有关 SO 的其他问题。出于某种原因,我仍然遇到这个问题。
“找不到入口点”
我的 CPP
extern "C"{
    __declspec(dllexport) int GetPose()
    {
        if (currentPose == myo::Pose::none)
            return 0;
        else if (currentPose == myo::Pose::fist)
            return 1;
        else
            return -1;
    }
}
Run Code Online (Sandbox Code Playgroud)
我的C#
public partial class MainWindow : Window
{
    [DllImport("MyoWrapper.dll", CallingConvention = CallingConvention.StdCall)]
    public static extern int GetPose();
public MainWindow()
{
    InitializeComponent();
    DispatcherTimer timer = new DispatcherTimer();
    timer.Interval = new TimeSpan(100);
    timer.Tick += (sender, args) => 
    {
      int x = GetPose(); 
    };
    timer.Start();
}
}
Run Code Online (Sandbox Code Playgroud)
    导致此错误的最可能原因如下
GetPos方法未在extern "C"块中定义。这会导致名称作为 C++ 损坏的名称发出,因此DllImport属性上的名称是错误的MyoWrapper.dll文件与可执行文件不在同一路径中,因此无法找到它鉴于错误是“入口点”,我敢打赌 #1 是原因。