C# 调用自己写的DLL 文件一直报错说无法找到入口点,求大神帮忙
DLL 文件代码(就是输入的两个值对换):
namespace MAXCD
{
public class Class1
{
public static long Swap(ref long i,ref long j)
{
int k;
K = i;
i=j;
j=k;
return i;
return j;
}
}
}
生成的DLL 文件名为KC;
主程序代码:
using System.Runtime.InteropServices; //
namespace MAXCD
{
class Class1
{
[DllImport("KC.dll", EntryPoint = "Swap")]
public static extern long Swap(ref long i, ref long j);
}
}
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; //
using MAXCD;
namespace _22
{
public partial class Form1 : Form
{
[DllImport("user32.dll", EntryPoint = "MessageBoxA")]
static extern int MsgBox(int hWnd, string msg, string caption, int type);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
//---------------------
long num1 = long.Parse("3");
long num2 = long.Parse("10");
Class1.Swap(ref num1, ref num2);//
}
Class1.Swap(ref num1, ref num2);一直报错 无法在KC.Dll 中找到Swap的入口 C# 求大神指点
[解决办法]
1.DLL中是否有存在调用的方法。
2.DLL中调用的方法参数是否正确。
3.DLL是否需要指定路径
[解决办法]
你写的DLL与系统连接库DLL是不同的,你只要在项目中添加引用,就可以用了。
如果想模拟成系统DLL的形式,必须按照COM组件的方式编写,那样比较复杂。
[解决办法]
DLL是否没包含在项目中?
[解决办法]
dll在编写的时候有没有函数导出?