C# 调用大漠插件的方法 转
转自http://blog.csdn.net/lsgy2008/article/details/8216484
1、把大漠插件 dm.dll 转成.net程序集。方法:在Visual Studio 命令提示 中输入 Tlbimp D:\dm.dll /out: D:\dmNet.dll 即可。
2、注册dm.dll。把源dm.dll注册一下。代码
- /// <summary>
- /// 注册
- /// </summary>
- /// <param name="strCmd"></param>
- /// <returns></returns>
- static string AutoRegCom(string strCmd)
- {
- strCmd = "regsvr32 D:\\dm.dll /s";
- 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;
- }
- }
/// <summary> /// 注册 /// </summary> /// <param name="strCmd"></param> /// <returns></returns> static string AutoRegCom(string strCmd) { strCmd = "regsvr32 D:\\dm.dll /s"; 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; } }
源码实例:
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using dmNet;
- namespace dmTest
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- AutoRegCom("regsvr32 D:\\dm.dll /s");
- }
- private void button1_Click(object sender, EventArgs e)
- {
- dmsoft dm = new dmsoft();
- textBox1.Text = dm.FindWindow("", "t").ToString();
- dm.MoveTo(30, 30);
- }
- /// <summary>
- /// 注册
- /// </summary>
- /// <param name="strCmd"></param>
- /// <returns></returns>
- static string AutoRegCom(string strCmd)
- {
- strCmd = "regsvr32 D:\\dm.dll /s";
- 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;
- }
- }
- }
- }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using dmNet; namespace dmTest { public partial class Form1 : Form { public Form1() { InitializeComponent(); AutoRegCom("regsvr32 D:\\dm.dll /s"); } private void button1_Click(object sender, EventArgs e) { dmsoft dm = new dmsoft(); textBox1.Text = dm.FindWindow("", "t").ToString(); dm.MoveTo(30, 30); } /// <summary> /// 注册 /// </summary> /// <param name="strCmd"></param> /// <returns></returns> static string AutoRegCom(string strCmd) { strCmd = "regsvr32 D:\\dm.dll /s"; 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; } } } }
今天试了一下,C#用大漠编写程序 挺多的方法都不支持比如启动程序,输入字符串,大漠对C#的支持性不是很好。不知道其他朋友有没有试过的,大家一起交流下。