当前位置:编程学习 > C#/ASP.NET >>

C sharp怎么调用DLL?

有个叫大漠插件的DLL文件,我想调用它怎没弄?

求大虾帮帮忙 3Q

DllImport("MY.LLL"] 这个方法貌似没用
据DLL作者说 DLL使用VC6写的 --------------------编程问答-------------------- 项目上右击,选择“添加引用”,然后切换到“浏览”选项卡,选择你要引用的DLL即可 --------------------编程问答-------------------- 在程序集中添加引用 --------------------编程问答--------------------  楼上两个合起来是正解 --------------------编程问答-------------------- 用VS打开工程,会有一个References的文件夹,点击右键 选择 Add References 即可。 --------------------编程问答-------------------- 额 我引用了 也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)”要求对象引用

怎么办?
--------------------编程问答-------------------- 好人们 求求你们 我急用 --------------------编程问答-------------------- 说明这个Dm.Idmsoft成员是非静态的,你要构造:

Dm.Idmsoft soft =new Dm.Idmsoft();//可能还有参数
soft.BindWindow(0, "dx", "dx", "dx", 0); --------------------编程问答-------------------- 添加引用是正解。各人建议用类对象视图看。这个跟C++风格比较类似。 --------------------编程问答-------------------- 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了
--------------------编程问答-------------------- 虽然7楼的那位大虾还是没对 但是这个也让我想到了方法
代码:
 long hwnd;      
  string jub;        
 Dm.dmsoft soft = new Dm.dmsoft();//          
  hwnd = soft.FindWindow("wndclass_desked_gsk", null);
   --------------------编程问答-------------------- 虽然7楼的那位大虾还是没对 但是这个也让我想到了方法
代码:
 long hwnd;      
  string jub;        
 Dm.dmsoft soft = new Dm.dmsoft();//          
  hwnd = soft.FindWindow("wndclass_desked_gsk", null);
   --------------------编程问答-------------------- 学习一下 --------------------编程问答-------------------- 顺便问下 创建实例soft在button1的单击事件中 怎么弄成全局的?
也就是在程序的任何地方 都能使用soft这个对象来调用dm.dll内的函数库
--------------------编程问答-------------------- dll可以用很多编程语言写的,也可以在其他语言调用它,楼上有很多兄弟都给你说对了,很实用,也很常用。 --------------------编程问答-------------------- 在你的Form1类,添加成员变量:

  private Dm.dmsoft soft=null; --------------------编程问答-------------------- 声明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;
            }
        }
    }
}
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,