Click here to Skip to main content
15,861,172 members
Home / Discussions / COM
   

COM

 
AnswerRe: COM+ Talking To DCOM Object Pin
skydger19-Sep-12 10:25
skydger19-Sep-12 10:25 
QuestionCOM and its availability via IIS Pin
gsvolt27-Aug-12 11:02
gsvolt27-Aug-12 11:02 
AnswerRe: COM and its availability via IIS Pin
Wes Aday27-Aug-12 11:12
professionalWes Aday27-Aug-12 11:12 
AnswerRe: COM and its availability via IIS Pin
Eddy Vluggen12-Oct-12 14:01
professionalEddy Vluggen12-Oct-12 14:01 
Questionusing a dll to read an smart card Pin
javadadabi17-Jun-12 8:44
javadadabi17-Jun-12 8:44 
AnswerRe: using a dll to read an smart card Pin
javadadabi20-Jun-12 1:53
javadadabi20-Jun-12 1:53 
AnswerRe: using a dll to read an smart card Pin
Brandon-X120001-Oct-12 3:49
Brandon-X120001-Oct-12 3:49 
QuestionOffice Outlook COM Interop best practice. Pin
The Fist30-Mar-12 12:00
The Fist30-Mar-12 12:00 
Hello

With the help of coffee and guesswork I've managed to use COM and Interop to open an Outlook .msg file and extract content from it. I have Outlook 2007 installed and I'm using Microsoft.Office.Interop.Outlook PIA runtime version 2.0.50727 (Version 14.0.0.0)
I'm using .NET 4 in a WPF application.

My problem is that my code starts an Outlook process but does not close it down afterwards. If I am already running Outlook, my code seems to attach to that process rather than start another one and if outlook is already running, my app.Quit() message closes the existing Outlook application (not the process.)
My question is am I going about this in the wrong way? I've read lots of posts about using Outlook but nothing that describes with authority how I should cleanly open, interrogate and close an outlook message.
Here's the code:
C#
public override void ViewContent(string strFilePath)
{
  base.ViewContent(strFilePath);

  Microsoft.Office.Interop.Outlook.Application app = null;
  Microsoft.Office.Interop.Outlook.NameSpace session = null;
  Microsoft.Office.Interop.Outlook.MailItem item = null;

  try
  {
    // Start Outlook.
    app = new Microsoft.Office.Interop.Outlook.Application();
    // Do some voodoo.
    session = app.Session;
    // Get the MailItem we're interested in.
    item = session.OpenSharedItem(strFilePath) as Microsoft.Office.Interop.Outlook.MailItem;

    if(item != null)
    {
      // Set the Dependency properties that the UI has bound to.
      Subject = item.Subject;
      From = item.SenderName;
      if(string.IsNullOrEmpty(item.SenderEmailAddress) == false)
        From += "{" + item.SenderEmailAddress + "}";

      MessageText = item.Body;

      item.Unload += new ItemEvents_10_UnloadEventHandler(item_Unload);

      item.Close(OlInspectorClose.olDiscard);
    }
    // This does not quit the Outlook process we started earlier.
    // If the full Outlook application is running, this line terminates that instead.
    // How can I quit the process I started earlier instead?
    app.Quit();
  }
  catch(Exception)
  {
    // Blah ...
  }
  finally
  {
    if(item != null)
      System.Runtime.InteropServices.Marshal.ReleaseComObject(item);

    if(session != null)
      System.Runtime.InteropServices.Marshal.ReleaseComObject(session);

    if(app != null)
      System.Runtime.InteropServices.Marshal.ReleaseComObject(app);

    item = null;
    session = null;
    app = null;
  }
}


Is this the right way to use COM and Interop? Does anyone have any pointers for me or a guide showing best practices? I'm new to COM so if anyone thinks my code is going to leak or use up handles or some other horror please let me know.

Thanks all,
Keith
QuestionIs COM an 'outdated' technology? Pin
krumia21-Feb-12 18:05
krumia21-Feb-12 18:05 
AnswerRe: Is COM an 'outdated' technology? Pin
Richard MacCutchan21-Feb-12 21:26
mveRichard MacCutchan21-Feb-12 21:26 
GeneralRe: Is COM an 'outdated' technology? Pin
krumia21-Feb-12 21:33
krumia21-Feb-12 21:33 
GeneralRe: Is COM an 'outdated' technology? PinPopular
Richard MacCutchan21-Feb-12 21:58
mveRichard MacCutchan21-Feb-12 21:58 
JokeRe: Is COM an 'outdated' technology? Pin
bob1697220-Apr-12 19:22
bob1697220-Apr-12 19:22 
GeneralRe: Is COM an 'outdated' technology? Pin
Richard MacCutchan20-Apr-12 22:11
mveRichard MacCutchan20-Apr-12 22:11 
GeneralRe: Is COM an 'outdated' technology? Pin
bob1697221-Apr-12 5:52
bob1697221-Apr-12 5:52 
GeneralRe: Is COM an 'outdated' technology? PinPopular
Richard MacCutchan21-Apr-12 7:44
mveRichard MacCutchan21-Apr-12 7:44 
AnswerRe: Is COM an 'outdated' technology? Pin
Eddy Vluggen12-Oct-12 14:05
professionalEddy Vluggen12-Oct-12 14:05 
QuestionIssues with identity of COM+ application Pin
Member 39605603-Feb-12 5:52
Member 39605603-Feb-12 5:52 
AnswerRe: Issues with identity of COM+ application Pin
Member 39605606-Feb-12 2:49
Member 39605606-Feb-12 2:49 
QuestionHow to convert COM proxy-stub dll to type library ? Pin
benjava28-Dec-11 17:35
benjava28-Dec-11 17:35 
AnswerRe: How to convert COM proxy-stub dll to type library ? Pin
Jonathan Davies30-Dec-11 9:08
Jonathan Davies30-Dec-11 9:08 
AnswerRe: How to convert COM proxy-stub dll to type library ? Pin
«_Superman_»6-Jan-12 16:23
professional«_Superman_»6-Jan-12 16:23 
QuestionOPENING THE VBA EDITOR ON CLICK ON OLEOBJECTS BUTTON Pin
archana jain15-Dec-11 0:20
archana jain15-Dec-11 0:20 
QuestionHow to select the predefined area as WIDTH in PIXEL by HEIGHT IN PIXELS in MSEXCEL for desiging your templates Pin
archana jain14-Dec-11 22:18
archana jain14-Dec-11 22:18 
QuestionAdding Workbook In Excel Pin
SB_CodeForFun6-Dec-11 20:02
SB_CodeForFun6-Dec-11 20:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.