一、引用Ddm.dll
在VS中:項目--添加引用--COM--DM.DLL 這步很關鍵。
二、注冊大漠插件
這是注冊DLL到系統的一個方法,注冊大漠則調用 AutoRegCom("regsvr32 -s dm.dll");
三、實例化大漠對象
Dm.dmsoft dm = new Dm.dmsoft();
四、調用大漠的方法
命名空間:WindowsFormsApp2
在窗體下加一個:button1
具體代碼如下:
namespace WindowsFormsApp2 { public partial class Form1 : Form { Dm.dmsoft dm = new Dm.dmsoft(); public Form1() { InitializeComponent(); AutoRegCom("regsvr32 -s dm.dll"); } private void button1_Click(object sender, EventArgs e) { MessageBox.Show(dm.Ver()); } 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; } }
調用:
private void button2_Click(object sender, EventArgs e) { int hwnd = dm.FindWindow("", "GaugeStudio");//獲取標題為“GaugeStudio”的窗體句柄 _ = dm.BindWindow(hwnd, "dx2", "windows3", "windows", 0);//win10下的后台綁定 dm.MoveTo(30, 30);//鼠標移動到GaugeStudio窗體的30,30位置 dm.LeftClick();//鼠標單擊左鍵 }