C#P\Invoke DLL没有入口点进入C ++?

C#P\Invoke DLL没有入口点进入C ++?

问题描述:

我有一个C ++ DLLTheFoo.dll有法美孚()

I have a C++ Dll "TheFoo.dll" with a method "Foo()"

我有机会获得其他的C ++代码通过简单地调用使用此方法

I have access to other C++ code that uses this method by simply calling:

Foo();



我相信方法确实有:

I believe the Method does have the:

 __declspec( dllexport )

所以,用读我已经做了有关的p / Invoke,我想我应该能够简单地从我的C#代码调用相同的方法:

So, with the reading I've done about P/Invoke, i thought i should be able to simply call the same method from my C# code:

namespace PInvokeExample1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

        }


        [DllImport(@"C:\MyFolder\TheFoo.dll")]
        public static extern
            void Foo();

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Foo();

        }



    }
}

当我运行它,我得到一个错误:

When i run it, i get an error:

Unable to find an entry point named 'Foo' in DLL 'C:\MyFolder\TheFoo.dll'.



为什么它没有发现任何想法?

Any ideas why it is not found?

您应该提供您的C ++的更多信息。尝试使用的externC__declspec(dllexport)的来代替。 C ++与出口奇怪的名字因此,使用的externC避免了。

You should provide more information on your C++. Try using extern "C" __declspec(dllexport) instead. C++ exports with strange names so using extern "C" avoids that.