WINFORM如何调用.DLL的函数

bulls5988 2010-12-22 04:13:49
WINFORM如何调用.DLL的函数.给我了一个READCARD.DLL并给了说明,每个函数和参数代表了什么.
现在要做串口通讯程序.如何调用DLL中的函数.
...全文
188 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
bulls5988 2010-12-22
  • 打赏
  • 举报
回复
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;


这样引用有问题吗?
bulls5988 2010-12-22
  • 打赏
  • 举报
回复
为什么我引用using System.Runtime.InteropServices;之后

没有 DllImport 只有 DllImportAttribute 呢?
guoyanhong1111 2010-12-22
  • 打赏
  • 举报
回复
1.引入命名空间
using System.Runtime.InteropServices
2.写调用的方法
[DllImport("READCARD.DLL", EntryPoint = "STK_DownLoadList")]
private static extern int STK_DownLoadList(参数);

就这样OK啊!
wuyq11 2010-12-22
  • 打赏
  • 举报
回复
DllImport
public static extern ..
说明就应该有介绍
ly1129 2010-12-22
  • 打赏
  • 举报
回复
楼上正解
shighui 2010-12-22
  • 打赏
  • 举报
回复
[DllImport("user32", EntryPoint = "SendMessageA")]
public static extern int SendMessage(int Hwnd, int wMsg, int wParam, ref COPYDATASTRUCT lParam);


添加命名空间引用:using System.RunTime.InterPort;什么的。
wangsong145 2010-12-22
  • 打赏
  • 举报
回复
两种方式:
1、引用DLL
2、通过如下方法:
[DllImport("user32", EntryPoint = "SendMessageA")]
public static extern int SendMessage(int Hwnd, int wMsg, int wParam, ref COPYDATASTRUCT lParam);
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 yhtapmys 的回复:]
先添加引用
[/Quote]
READCARD.DLL这样的DLL,一般估计是C或C++写,应该使用DLLIMPORT
ruoshuipian 2010-12-22
  • 打赏
  • 举报
回复
添加引用,或者使用assembly反射。
yhtapmys 2010-12-22
  • 打赏
  • 举报
回复
先添加引用

111,125

社区成员

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

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

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