日期:2014-05-18 浏览次数:20846 次
namespace WindowsApplication1 { public delegate void LDTCallBack(int port); class LDT { [DllImport("Sandu.dll", EntryPoint = "Setup_Tel")] public static extern void Setup_Tel(LDTCallBack CallBack, int y); [DllImport("Sandu.dll", EntryPoint = "Begin_Tel")] public static extern int Begin_Tel(int Port, char Power); [DllImport("Sandu.dll", EntryPoint = "End_Tel")] public static extern int End_Tel(int Port); [DllImport("Sandu.dll", EntryPoint = "GetNumber_Tel")] public static extern StringBuilder GetNumber_Tel(int Port); [DllImport("Sandu.dll", EntryPoint = "DevCount_Tel")] public static extern int DevCount_Tel(); } }
public delegate bool CallBack(int hwnd, int lParam); public partial class Form1 : Form { public Form1() { InitializeComponent(); } public void MyCallBack(int port) { if (port == 0) { //设备有改变 } else { string number; number = LDT.GetNumber_Tel(port).ToString(); listBox1.Items.Add("端口"+port+": 来电号码 "+number); } } private void btnSetup_Click(object sender, EventArgs e) { //设置回调 LDTCallBack callback = new LDTCallBack(MyCallBack); LDT.Setup_Tel(callback, 1); listBox1.Items.Add("设置回调成功"); } private void button1_Click(object sender, EventArgs e) { //打开设备 for (int i = 1; i <= LDT.DevCount_Tel(); i++) { if (LDT.Begin_Tel(i, '1') == 1) { listBox1.Items.Add("开启设备" + i.ToString() + "成功"); } } } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { // return; try { for (int i = 1; i <= LDT.DevCount_Tel(); i++) { LDT.End_Tel(i); } } catch { } } private void button1_Click_1(object sender, EventArgs e) { frmEnum frm = new frmEnum(); frm.ShowDialog(); frm.Close(); } private void Form1_Load(object sender, EventArgs e) { } }