Interfacing with COM

  • Thread starter Thread starter Marco Shaw
  • Start date Start date
M

Marco Shaw

**Programming newbie**

I'd like to write some C# that interacts with a COM object ("automation
library"?). I don't quite know what to look for though to find examples.

I'm guessing if I can find some demos of C# using COM objects like that from
MS Office, that might get me started?

Marco
 
Hi Marco,
If you reference a dll in your project .net creates an Interop wrapper that
lets you interact with it.
regarding Office you reference the Office PIAs (Primary Interop Assemblies)
these can be downloaded from Microsoft.

I have had a quick play but haven't done anything substantial.
Play code follows:
hth
Bob
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using Outlook = Microsoft.Office.Interop.Outlook;

namespace TestOutLookPIA

{

public partial class Form1 : Form

{

private Outlook.Application outlook;

public Form1()

{

InitializeComponent();

outlook = new Outlook.ApplicationClass();

outlook.GetNamespace("MAPI");

Outlook.MailItem myMail;

myMail=(Outlook.MailItem)outlook.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

myMail.Recipients.Add([email protected]);

myMail.Body = "Test Message";

myMail.Subject = "Test Mail";

myMail.Send();


}

}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top