C# 调用C++DLL出了大问题
来源:百度知道 编辑:UC知道 时间:2024/05/27 02:34:40
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 WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("DLLDemo.dll", EntryPoint = "Max", CharSet = CharSet.Ansi)]
static extern int Max(int iNum1, int iNum2);
[DllImport("DLLDemo.dll", EntryPoint = "Min", CharSet = CharSet.Ansi)]
static extern int Min(int iNum1, int iNum2);
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("5合3中比较小的是:" + Min(5, 3).ToString());
}
}
}
错误:System.DllNotFoundException: 无法加载 DLL“DLLDemo.dll”: 找不到指定的模块。 (异常来自 HRESULT:0x8007007E)。
DLLDemo
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 WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("DLLDemo.dll", EntryPoint = "Max", CharSet = CharSet.Ansi)]
static extern int Max(int iNum1, int iNum2);
[DllImport("DLLDemo.dll", EntryPoint = "Min", CharSet = CharSet.Ansi)]
static extern int Min(int iNum1, int iNum2);
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("5合3中比较小的是:" + Min(5, 3).ToString());
}
}
}
错误:System.DllNotFoundException: 无法加载 DLL“DLLDemo.dll”: 找不到指定的模块。 (异常来自 HRESULT:0x8007007E)。
DLLDemo
你用绝对路径好了。
EntryPoint = "Max
确保里面的函数名正确
要在前面加标识的。。能能识别出来
你的DLLDemo.dll在哪个路径吗?路径有问题吧
System.DllNotFoundException 应该是没找到的错误,检查路径对不对
是找不到指定的模块