C sharp怎么调用DLL?

My_love_you 2011-10-14 05:50:17
有个叫大漠插件的DLL文件,我想调用它怎没弄?

求大虾帮帮忙 3Q

DllImport("MY.LLL"] 这个方法貌似没用
据DLL作者说 DLL使用VC6写的
...全文
478 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
shuichao124 2012-10-11
  • 打赏
  • 举报
回复
先在解决方案资源管理器中添加引用,
例子如下
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 Dm;//定义大漠空间

namespace Plug
{
public partial class Form1 : Form
{
dmsoft dm = new dmsoft();//实例化大漠对象
public Form1()
{
InitializeComponent();
}
//Form[设计]中双击添加Load事件
private void Form1_Load(object sender, EventArgs e)
{
MessageBox.Show(dm.Ver());//弹出版本号
}
//Form[设计]中右键》属性》事件列表中添加FormClosing事件
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("确定要关闭程序吗?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
{
dm.UnBindWindow();//释放大漠对象
e.Cancel = true;
}
}
}
}
yojinlin 2011-10-15
  • 打赏
  • 举报
回复
學習了。
山东蓝鸟贵薪 2011-10-15
  • 打赏
  • 举报
回复
继续学习中
让自己的知识方面再进一步
davidxie2 2011-10-15
  • 打赏
  • 举报
回复
标记下
山东蓝鸟贵薪 2011-10-15
  • 打赏
  • 举报
回复
声明DLL及参数
调用DLL
引用参数
返回
sdl2005lyx 2011-10-15
  • 打赏
  • 举报
回复
在你的Form1类,添加成员变量:

private Dm.dmsoft soft=null;
qinzugan 2011-10-15
  • 打赏
  • 举报
回复
dll可以用很多编程语言写的,也可以在其他语言调用它,楼上有很多兄弟都给你说对了,很实用,也很常用。
My_love_you 2011-10-15
  • 打赏
  • 举报
回复
顺便问下 创建实例soft在button1的单击事件中 怎么弄成全局的?
也就是在程序的任何地方 都能使用soft这个对象来调用dm.dll内的函数库
ningweidong 2011-10-15
  • 打赏
  • 举报
回复
学习一下
My_love_you 2011-10-15
  • 打赏
  • 举报
回复
虽然7楼的那位大虾还是没对 但是这个也让我想到了方法
代码:
long hwnd;
string jub;
Dm.dmsoft soft = new Dm.dmsoft();//
hwnd = soft.FindWindow("wndclass_desked_gsk", null);
My_love_you 2011-10-15
  • 打赏
  • 举报
回复
虽然7楼的那位大虾还是没对 但是这个也让我想到了方法
代码:
long hwnd;
string jub;
Dm.dmsoft soft = new Dm.dmsoft();//
hwnd = soft.FindWindow("wndclass_desked_gsk", null);
My_love_you 2011-10-15
  • 打赏
  • 举报
回复
Dm.Idmsoft soft =new Dm.Idmsoft();//可能还有参数
soft.BindWindow(0, "dx", "dx", "dx", 0);

额 这个报错:D:\My Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs(23,31): 错误 CS0144: 无法创建抽象类或接口“Dm.Idmsoft”的实例

在VB中 新建一个对象类型的变量dm 用shell函数把COM接口的DLL注册到系统后
然后一句:Set dm = CreateObject("dm.dmsoft") 创建对象就OK了
qq328848298 2011-10-14
  • 打赏
  • 举报
回复
添加引用是正解。各人建议用类对象视图看。这个跟C++风格比较类似。
sdl2005lyx 2011-10-14
  • 打赏
  • 举报
回复
说明这个Dm.Idmsoft成员是非静态的,你要构造:

Dm.Idmsoft soft =new Dm.Idmsoft();//可能还有参数
soft.BindWindow(0, "dx", "dx", "dx", 0);
My_love_you 2011-10-14
  • 打赏
  • 举报
回复
好人们 求求你们 我急用
My_love_you 2011-10-14
  • 打赏
  • 举报
回复
额 我引用了 也using dm了 写了句代码:
Dm.Idmsoft.BindWindow(0, "dx", "dx", "dx", 0); //对象浏览器里面复制来的
调用dm.dll里面的函数 说:
D:\My Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs(23,13): 错误 CS0120: 非静态的字段、方法或属性“Dm.Idmsoft.BindWindow(int, string, string, string, int)”要求对象引用

怎么办?
指间的风 2011-10-14
  • 打赏
  • 举报
回复
用VS打开工程,会有一个References的文件夹,点击右键 选择 Add References 即可。
China_yuanli 2011-10-14
  • 打赏
  • 举报
回复
楼上两个合起来是正解
blncle 2011-10-14
  • 打赏
  • 举报
回复
在程序集中添加引用
etherealkite 2011-10-14
  • 打赏
  • 举报
回复
项目上右击,选择“添加引用”,然后切换到“浏览”选项卡,选择你要引用的DLL即可

110,534

社区成员

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

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

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