C#调用C++Dll例程

来源:互联网 发布:淘宝客服的沟通技巧 编辑:程序博客网 时间:2024/04/28 13:13
New1.txt BODY {background: #FFFFFF} A:link { color: #0000FF} A:visited { color: #0000FF} A:Active { color: #0000FF} .bold {font-weight: bold} .italic {font-style: italic} .underline {text-decoration: underline}
//Form1.cs内容:using System;using System.Windows.Forms;using System.Runtime.InteropServices;using System.Text;namespace WindowsFormsApplication1{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        //申明DLL中函数         [DllImport("KB_Dll.dll", EntryPoint = "InputKey")]        //不加密输入密码        private static extern int InputKey(string m_comm, string extCom, int time_out, int Cmd, StringBuilder Pwd);//不加密输入密码//[Out,MarshalAs(UnmanagedType.LPArray)]        private void button1_Click(object sender, EventArgs e)        {            string m_comm = "USB_vid4754&pid9020";            string extCom="NULL";            int timeout=20;            int Cmd;                        StringBuilder Pwd = new StringBuilder(300);            Cmd = 1;            int recv = 0;            recv = InputKey(m_comm, extCom, timeout, Cmd, Pwd);            MessageBox.Show(Pwd.ToString());                    }        private void Form1_Load(object sender, EventArgs e)        {        }    }}
原创粉丝点击