C#P\Invoke DLL没有入口点进入C ++? [英] C# P\Invoke DLL no entry point into C++?

查看:214
本文介绍了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.

这篇关于C#P\Invoke DLL没有入口点进入C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆