//创建COM 接口对象 public static ICustomedOperation CreateOperation(String _guid, String conStr) { ICustomedOperation iOperation = null; try { Guid guid = new Guid(_guid); Type operationType = Type.GetTypeFromCLSID(guid); object operation = Activator.CreateInstance(operationType); iOperation = operation as ICustomedOperation; iOperation.Connect(conStr); } catch (Exception ex) { Console.Write(ex.ToString()); } return(iOperation); }
private void MulBtn_Click(object sender, RoutedEventArgs e) { if (mul1.Text == null || mul1.Text == "" || mul2.Text == "" || mul2.Text == null) { MessageBox.Show("请输入需要相加的两个源操作数"); return; } ICustomedOperation iOperation = CreateOperation("0695719A-8D21-4428-AB41-4068431F1C54", ""); int d1, d2; bool b1 = Int32.TryParse(mul1.Text, out d1); bool b2 = Int32.TryParse(mul2.Text, out d2); if (b1 && b2) { mulResultBox.Text = iOperation.Multiply(d1, d2).ToString(); } else { MessageBox.Show("输入的操作数不符合规范!!!"); } }