C# 调用自己写的DLL 文件一直报错说无法找到入口点,求大神帮忙

箭神小傲 2013-07-01 03:44:27
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的入口
...全文
877 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
生活的过路人 2014-06-11
  • 打赏
  • 举报
回复
补充:由于用C#做成的DLL是一种“伪DLL",不能通过regsvr32进行注册,如果你要在其他的.NET项目中使用该DLL,只要在项目中进行引用就可以了。
生活的过路人 2014-06-11
  • 打赏
  • 举报
回复
你可以先将Calss1那个dll文件,添加引用,然后在用包名.类名的方式就可以调用Swap方法了
箭神小傲 2013-07-03
  • 打赏
  • 举报
回复
因为是非托管的DLL,所以上面的方法根本就是错误的,更不存在注册的问题,5楼稍微靠了一点边,份就给你吧,
箭神小傲 2013-07-02
  • 打赏
  • 举报
回复
那上面的那段代码 我要如何修改?或者告诉我下 我该往哪个方向去学习?
  • 打赏
  • 举报
回复
dll在编写的时候有没有函数导出?
叫我猫爷_ 2013-07-01
  • 打赏
  • 举报
回复
DLL是否没包含在项目中?
tcmakebest 2013-07-01
  • 打赏
  • 举报
回复
你写的DLL与系统连接库DLL是不同的,你只要在项目中添加引用,就可以用了。 如果想模拟成系统DLL的形式,必须按照COM组件的方式编写,那样比较复杂。
箭神小傲 2013-07-01
  • 打赏
  • 举报
回复
我在代码和BIN 文件中都有放,就是不知道 调用方法和 调用的方法参数哪里出了问题,还是我的DLL本身就有问题
xingn 2013-07-01
  • 打赏
  • 举报
回复
1.DLL中是否有存在调用的方法。 2.DLL中调用的方法参数是否正确。 3.DLL是否需要指定路径
箭神小傲 2013-07-01
  • 打赏
  • 举报
回复
如果是在引用中加载好像又没问题,我想做成外部导入的
满CD的程序猿 2013-07-01
  • 打赏
  • 举报
回复
regsvr32 x.dll 看看是不是需要注册下

110,475

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧