Click here to Skip to main content
12,241,814 members (53,427 online)
   

COM

 
AnswerRe: COM+ Talking To DCOM Object Pin
skydger19-Sep-12 11:25
memberskydger19-Sep-12 11:25 
QuestionCOM and its availability via IIS Pin
gsvolt27-Aug-12 12:02
membergsvolt27-Aug-12 12:02 
AnswerRe: COM and its availability via IIS Pin
Wes Aday27-Aug-12 12:12
memberWes Aday27-Aug-12 12:12 
AnswerRe: COM and its availability via IIS Pin
Eddy Vluggen12-Oct-12 15:01
memberEddy Vluggen12-Oct-12 15:01 
Questionusing a dll to read an smart card Pin
javadadabi17-Jun-12 9:44
memberjavadadabi17-Jun-12 9:44 
AnswerRe: using a dll to read an smart card Pin
javadadabi20-Jun-12 2:53
memberjavadadabi20-Jun-12 2:53 
AnswerRe: using a dll to read an smart card Pin
Brandon T. H.1-Oct-12 4:49
memberBrandon T. H.1-Oct-12 4:49 
QuestionOffice Outlook COM Interop best practice. Pin
The Fist30-Mar-12 13:00
memberThe Fist30-Mar-12 13: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:
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 19:05
memberkrumia21-Feb-12 19:05 
AnswerRe: Is COM an 'outdated' technology? Pin
Richard MacCutchan21-Feb-12 22:26
mvpRichard MacCutchan21-Feb-12 22:26 
GeneralRe: Is COM an 'outdated' technology? Pin
krumia21-Feb-12 22:33
memberkrumia21-Feb-12 22:33 
GeneralRe: Is COM an 'outdated' technology? Pin
Richard MacCutchan21-Feb-12 22:58
mvpRichard MacCutchan21-Feb-12 22:58 
JokeRe: Is COM an 'outdated' technology? Pin
bob1697220-Apr-12 20:22
memberbob1697220-Apr-12 20:22 
GeneralRe: Is COM an 'outdated' technology? Pin
Richard MacCutchan20-Apr-12 23:11
mvpRichard MacCutchan20-Apr-12 23:11 
GeneralRe: Is COM an 'outdated' technology? Pin
bob1697221-Apr-12 6:52
memberbob1697221-Apr-12 6:52 
GeneralRe: Is COM an 'outdated' technology? Pin
Richard MacCutchan21-Apr-12 8:44
mvpRichard MacCutchan21-Apr-12 8:44 
AnswerRe: Is COM an 'outdated' technology? Pin
Eddy Vluggen12-Oct-12 15:05
memberEddy Vluggen12-Oct-12 15:05 
QuestionIssues with identity of COM+ application Pin
Member 39605603-Feb-12 6:52
memberMember 39605603-Feb-12 6:52 
AnswerRe: Issues with identity of COM+ application Pin
Member 39605606-Feb-12 3:49
memberMember 39605606-Feb-12 3:49 
QuestionHow to convert COM proxy-stub dll to type library ? Pin
benjava28-Dec-11 18:35
memberbenjava28-Dec-11 18:35 
AnswerRe: How to convert COM proxy-stub dll to type library ? Pin
Jonathan Davies30-Dec-11 10:08
memberJonathan Davies30-Dec-11 10:08 
AnswerRe: How to convert COM proxy-stub dll to type library ? Pin
«_Superman_»6-Jan-12 17:23
mvp«_Superman_»6-Jan-12 17:23 
QuestionOPENING THE VBA EDITOR ON CLICK ON OLEOBJECTS BUTTON Pin
archana jain15-Dec-11 1:20
memberarchana jain15-Dec-11 1: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 23:18
memberarchana jain14-Dec-11 23:18 
QuestionAdding Workbook In Excel Pin
cooldhaniya6-Dec-11 21:02
membercooldhaniya6-Dec-11 21: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.


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 30 Mar 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid