C#中调用大漠插件实例

一、引用Ddm.dll

.NET里面可以直接引用,引用方法,添加引用--COM--找到DM,双击即可

二、注册大漠插件

//这是注册DLL到系统的一个方法,注册大漠则调用 AutoRegCom("regsvr32 -s dm.dll");

static string AutoRegCom(string strCmd)
        {
            string rInfo;
            try
            {
                Process myProcess = new Process();
                ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("cmd.exe");
                myProcessStartInfo.UseShellExecute = false;
                myProcessStartInfo.CreateNoWindow = true;
                myProcessStartInfo.RedirectStandardOutput = true;
                myProcess.StartInfo = myProcessStartInfo;
                myProcessStartInfo.Arguments = "/c " + strCmd;
                myProcess.Start();
                StreamReader myStreamReader = myProcess.StandardOutput;
                rInfo = myStreamReader.ReadToEnd();
                myProcess.Close();
                rInfo = strCmd + "\r\n" + rInfo;
                return rInfo;
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }

三、实例化大漠对象

Dm.dmsoft dm = new Dm.dmsoft();

四、调用大漠的方法

直接通过实例化的对象dm调用,如dm.MoveTo(30, 30);

完整代码: 窗体上放一个按钮,点击按钮,调用大漠插件将鼠标移动到(30,30)

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.Diagnostics;
using System.IO;


namespace Player
{
    public partial class Player : Form
    {
        public Player()
        {
            InitializeComponent();
            AutoRegCom("regsvr32 -s dm.dll");
        }


        private void button1_Click(object sender, EventArgs e)
        {
            Dm.dmsoft dm = new Dm.dmsoft();
            dm.MoveTo(30, 30);


        }


        static string AutoRegCom(string strCmd)
        {
            string rInfo;


            try
            {
                Process myProcess = new Process();
                ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("cmd.exe");
                myProcessStartInfo.UseShellExecute = false;
                myProcessStartInfo.CreateNoWindow = true;
                myProcessStartInfo.RedirectStandardOutput = true;
                myProcess.StartInfo = myProcessStartInfo;
                myProcessStartInfo.Arguments = "/c " + strCmd;
                myProcess.Start();
                StreamReader myStreamReader = myProcess.StandardOutput;
                rInfo = myStreamReader.ReadToEnd();
                myProcess.Close();
                rInfo = strCmd + "\r\n" + rInfo;
                return rInfo;
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
    }
}

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页