简体   繁体   中英

C++ DLL “Cannot Find Entry Point”

So I looked at the other questions on SO in regards to this. For some reason I am still getting this issue.

"Cannot Find Entry Point"

My 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;
    }
}

My 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();
}

}

The most likely causes for this error are the following

  1. The GetPos method is not defined in an extern "C" block. This causes the name to get emitted as a C++ mangled name and hence the name is wrong on the DllImport attribute
  2. The MyoWrapper.dll file is not in the same path as the executable and hence it can't be found

Given that the error is "entry point" I'm going to wager that #1 is the cause.

The solution wasn't to bad.

I am attempting to turn a program with a main into a DLL so obviously the method I wanted to expose wasn't the entry point. Once I exposed all of the methods and set main as the entry point in C# it worked just fine.

[DllImport("MyoWrapper.dll", EntryPoint = "main")]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM