Click here to Skip to main content
15,886,689 members
Articles / Desktop Programming / ATL

Native & Managed Interop Made Simple

Rate me:
Please Sign up or sign in to vote.
4.43/5 (3 votes)
14 Nov 2007CPOL14 min read 37.3K   350   26  
This article presents a simple calculator component example by using COM Interoperability basics.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SimpleCalcTesterNET
{
	public partial class SimpleCalcTesterForm : Form
	{
		public SimpleCalcTesterForm()
		{
			InitializeComponent();
		}

		private void btAddEB_Click(object sender, EventArgs e)
		{
			double oper1 = double.Parse(txOper1.Text);
			double oper2 = double.Parse(txOper2.Text);

			SimpleCalcInterop.ISimpleCalc calculator = new SimpleCalcInterop.SimpleCalc();

			txResult.Text = calculator.Add(oper1, oper2).ToString();
		}

		private void btSubtractEB_Click(object sender, EventArgs e)
		{
			double oper1 = double.Parse(txOper1.Text);
			double oper2 = double.Parse(txOper2.Text);

			SimpleCalcInterop.ISimpleCalc calculator = new SimpleCalcInterop.SimpleCalc();

			txResult.Text = calculator.Subtract(oper1, oper2).ToString();
		}

		private void btMultiplyEB_Click(object sender, EventArgs e)
		{
			double oper1 = double.Parse(txOper1.Text);
			double oper2 = double.Parse(txOper2.Text);

			SimpleCalcInterop.ISimpleCalc calculator = new SimpleCalcInterop.SimpleCalc();

			txResult.Text = calculator.Multiply(oper1, oper2).ToString();
		}

		private void btDivideEB_Click(object sender, EventArgs e)
		{
			double oper1 = double.Parse(txOper1.Text);
			double oper2 = double.Parse(txOper2.Text);

			SimpleCalcInterop.ISimpleCalc calculator = new SimpleCalcInterop.SimpleCalc();

			txResult.Text = calculator.Divide(oper1, oper2).ToString();
		}

		private void btAddLB_Click(object sender, EventArgs e)
		{
			double oper1 = double.Parse(txOper1.Text);
			double oper2 = double.Parse(txOper2.Text);

			SimpleCalcInteropLateBinding.ISimpleCalc calculator = new SimpleCalcInteropLateBinding.SimpleCalc();

			txResult.Text = calculator.Add(oper1, oper2).ToString();
		}

		private void btSubtractLB_Click(object sender, EventArgs e)
		{
			double oper1 = double.Parse(txOper1.Text);
			double oper2 = double.Parse(txOper2.Text);

			SimpleCalcInteropLateBinding.ISimpleCalc calculator = new SimpleCalcInteropLateBinding.SimpleCalc();

			txResult.Text = calculator.Subtract(oper1, oper2).ToString();
		}

		private void btMultiplyLB_Click(object sender, EventArgs e)
		{
			double oper1 = double.Parse(txOper1.Text);
			double oper2 = double.Parse(txOper2.Text);

			SimpleCalcInteropLateBinding.ISimpleCalc calculator = new SimpleCalcInteropLateBinding.SimpleCalc();

			txResult.Text = calculator.Multiply(oper1, oper2).ToString();
		}

		private void btDivideLB_Click(object sender, EventArgs e)
		{
			double oper1 = double.Parse(txOper1.Text);
			double oper2 = double.Parse(txOper2.Text);

			SimpleCalcInteropLateBinding.ISimpleCalc calculator = new SimpleCalcInteropLateBinding.SimpleCalc();

			txResult.Text = calculator.Divide(oper1, oper2).ToString();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Safira
Portugal Portugal
Graduated the course Lincenciatura em Engenharia Informatica e Computadores at Instituto Superior Tecnico de Lisboa.
Worked as IT Technician and Manager of a small team while giving support to very small business offices.
Worked sa a Senior Developer at Markdata, a software house in Portugal.
Currently as Senior Software Engineer at Safira Consultoria S.A. in Portugal.

Comments and Discussions