小编Gre*_*egD的帖子

困惑的DLL入口点(入口点未找到异常)

我正在尝试学习如何在C#中使用DLL.我有一个非常简单的DLL只是为了测试基础知识.

// MainForm.cs


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Runtime.InteropServices;

namespace DLL_Test
{
        public partial class Form1 : Form
        {
            [DllImport("TestDLL.dll",
                        EntryPoint="?Add@@YGHHH@Z",
                        ExactSpelling = true,
                        CallingConvention = CallingConvention.StdCall)]
            public static extern int Add(int a, int b);

            public Form1()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                int num;
                try
                {
                    num = Add(2, 3);
                    richTextBox1.AppendText(num.ToString() + "\n");
                }
                catch (DllNotFoundException ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                catch (EntryPointNotFoundException ex) …
Run Code Online (Sandbox Code Playgroud)

c# c++ dll visual-studio-2010

9
推荐指数
1
解决办法
3万
查看次数

标签 统计

c# ×1

c++ ×1

dll ×1

visual-studio-2010 ×1