先在解决方案资源管理器中添加引用, 例子如下 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; } } } }
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)”要求对象引用怎么办?
soft.BindWindow(0, "dx", "dx", "dx", 0);
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了
代码:
long hwnd;
string jub;
Dm.dmsoft soft = new Dm.dmsoft();//
hwnd = soft.FindWindow("wndclass_desked_gsk", null);
代码:
long hwnd;
string jub;
Dm.dmsoft soft = new Dm.dmsoft();//
hwnd = soft.FindWindow("wndclass_desked_gsk", null);
也就是在程序的任何地方 都能使用soft这个对象来调用dm.dll内的函数库
调用DLL
引用参数
返回
例子如下
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;
}
}
}
}