DotNetRussell
DotNetRussell

Reputation: 9857

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

}

Upvotes: 3

Views: 6718

Answers (2)

DotNetRussell
DotNetRussell

Reputation: 9857

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")]

Upvotes: 1

JaredPar
JaredPar

Reputation: 754505

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.

Upvotes: 6

Related Questions