如何使用DllImport引入dll

gaoweipeng7851 2008-09-07 09:52:21
(1)我现在有个vc开发的dll文件,其中封装了一个函数addsum(int a,int b)实现加法,如何通过DllImport引入到.net的bs应用程序中??(c#的),在后台代码中得到这个函数及相应的参数??请给出相应的代码,万分感谢!急!
(2)vc开发的什么类型的dll可以加到.net中使用?
...全文
292 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
ZengHD 2008-09-08
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 supper168 的回复:]
可以,
[/Quote]
我不信
春天的气息 2008-09-08
  • 打赏
  • 举报
回复
可以,
ZengHD 2008-09-08
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 ZengHD 的回复:]
引用 10 楼 wanyeyinfeng 的回复:
引用 7 楼 ZengHD 的回复:
引用 6 楼 supper168 的回复:
可以,

我不信


还真固执呢,明确的说,可以的哦

我试试先
[/Quote]
能用

using System;
using System.Web;
using System.Web.UI;
using System.Runtime.InteropServices;

public partial class _Default : System.Web.UI.Page
{
[DllImport("kernel32.dll")]
public static extern int WinExec(string exeName, int operType);
protected void Button1_Click(object sender, EventArgs e)
{
WinExec(@"c:\windows\system32\notepad.exe", 5);
}
}
ZengHD 2008-09-08
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 wanyeyinfeng 的回复:]
引用 7 楼 ZengHD 的回复:
引用 6 楼 supper168 的回复:
可以,

我不信


还真固执呢,明确的说,可以的哦
[/Quote]
我试试先
吟风 2008-09-08
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 ZengHD 的回复:]
引用 6 楼 supper168 的回复:
可以,

我不信
[/Quote]

还真固执呢,明确的说,可以的哦
吟风 2008-09-08
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 gaoweipeng 的回复:]
引用 2 楼 dk385 的回复:
标准的DLL就可被.net调用。

C# code[DllImport("xxx.dll", EntryPoint = "addsum", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void addsum(int a, int b);

还得问下,这个代码加在哪啊?
[/Quote]

加在你的类里面就可以的。
gaoweipeng7851 2008-09-08
  • 打赏
  • 举报
回复
如何实现啊??
zt_100094 2008-09-08
  • 打赏
  • 举报
回复
标准的DLL就可被.net调用。

C# code[DllImport("xxx.dll", EntryPoint = "addsum", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void addsum(int a, int b);
纷享刘晨 2008-09-08
  • 打赏
  • 举报
回复
写在声明方法的地方

12楼的大哥,又看见你了啊
hm7921936 2008-09-08
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 gaoweipeng 的回复:]
引用 2 楼 dk385 的回复:
标准的DLL就可被.net调用。

C# code[DllImport("xxx.dll", EntryPoint = "addsum", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void addsum(int a, int b);

还得问下,这个代码加在哪啊?
[/Quote]

加在声明类成员变量的地方
ZengHD 2008-09-07
  • 打赏
  • 举报
回复
BS也能使用VC写的DLL吗?
gaoweipeng7851 2008-09-07
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 dk385 的回复:]
标准的DLL就可被.net调用。

C# code[DllImport("xxx.dll", EntryPoint = "addsum", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void addsum(int a, int b);
[/Quote]
还得问下,这个代码加在哪啊?
luluyy 2008-09-07
  • 打赏
  • 举报
回复
你可以这样导入`更方便快捷`~~ 先把那个DLL放到你程序的根目录下`~ 比如DLL叫做 a.dll 放到根目录下后~你using a.dll就行了`
家鸣 2008-09-07
  • 打赏
  • 举报
回复
标准的DLL就可被.net调用。
[DllImport("xxx.dll", EntryPoint = "addsum", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] 
public static extern void addsum(int a, int b);
gaoweipeng7851 2008-09-07
  • 打赏
  • 举报
回复
没人知道吗???

110,572

社区成员

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

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

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