public static printCallBackFun PrintCallBack;//接收返回值,防止被GC回收 public AppPrinterWindow() { InitializeComponent(); //托盘图标加载 //Init_NotifyIcon(); //托盘图标加载单例 //var cc = ViewModelLocator.notify; //监听打印机 PrintCallBack = CsharpCall; start(PrintCallBack, ""); Label.Content = "正在添加打印机"; LoadWindow(true);//窗体动画开始 }
void AddPrinter() { string name = "印兔打印"; string driverName = "Into_1"; //+ Guid.NewGuid().ToString(); int code = addVPrinter(name, driverName); if (code == 0) { PrintCallBack = new printCallBackFun(CsharpCall); start(PrintCallBack, name); this.Dispatcher.Invoke(new Action(delegate { this.Label.Content = "添加打印机成功"; StartCloseTimer(true, 3); //PrinterVM.Lab = "添加打印机成功"; })); //成功 } else if (code == 1) { this.Dispatcher.Invoke(new Action(delegate { this.Label.Content = "添加打印机成功"; StartCloseTimer(true, 3); //PrinterVM.Lab = "添加打印机成功"; })); } else { //MMessageBox.ShouBox("打印机未正确添加,请联系维护人员。", "提示", MMessageBox.ButtonType.Yes, MMessageBox.IconType.Info); //MessageBox.Show("打印机未正确添加,请联系维护人员。", "提示", MessageBoxButton.OK, MessageBoxImage.Information); //PrinterVM.Lab = "打印机未正确添加,请联系维护人员"; this.Label.Content = "打印机未正确添加,请联系维护人员"; StartCloseTimer(true, 3); } }
extern static int start(printCallBackFun callback, [MarshalAs(UnmanagedType.LPStr)] string printerName);