c#中dll调用错误DllNotFoundException

来源:百度知道 编辑:UC知道 时间:2024/05/10 14:04:25
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace test2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

[DllImport("ez2000.dll", EntryPoint = "openport")]
public extern static void openport(string port);
private void button1_Click(object sender, EventArgs e)
{
string strlll = "5";
openport(strlll);
}
}
}

错误:{"无法加载 DLL“ez2000.dll”: 找不到指定的模块。 (异常来自 HRESULT:0x8007007E)。"}
我把dll文件放exe一起,还复制了一份放system32下了
这个是dll的说明文档1. openport
Description: select the output port
Command: openport(no)

这不是关于打印的dll嘛 你这样写是对的哦,DllImport会首先到路劲下找dll,然后会到system32下找.如果EntryPoint = "openport"没错,那或许是这个dll还调用其它的dll?我做条码打印时也遇到过.

应该是你的dll引用的路径写错了吧,检查一下路径

你的DLL没问题吧

有函数 openport 吗?

如果DLL没有问题 就建议你在解决方案中的“引用”文件夹下单击右键 然后添加你那DLL文件 看看行不行