Click here to Skip to main content
11,576,667 members (61,172 online)
   

COM

 
GeneralRe: .NET COM component to replace existing Pin
manoranjan20-Nov-12 17:03
membermanoranjan20-Nov-12 17:03 
QuestionEnumeration of implemented interfaces Pin
_Kel_22-Oct-12 6:30
member_Kel_22-Oct-12 6:30 
GeneralRe: Enumeration of implemented interfaces Pin
_Kel_10-Dec-12 23:32
member_Kel_10-Dec-12 23:32 
GeneralUsing Open MPI and CUDA in Windows 7 Pin
Sijo Mathew17-Sep-12 23:40
memberSijo Mathew17-Sep-12 23:40 
QuestionCOM+ Talking To DCOM Object Pin
Member 81371057-Sep-12 3:43
memberMember 81371057-Sep-12 3:43 
AnswerRe: COM+ Talking To DCOM Object Pin
Member 81371057-Sep-12 4:43
memberMember 81371057-Sep-12 4:43 
AnswerRe: COM+ Talking To DCOM Object Pin
skydger19-Sep-12 10:25
memberskydger19-Sep-12 10:25 
QuestionCOM and its availability via IIS Pin
gsvolt27-Aug-12 11:02
membergsvolt27-Aug-12 11:02 
AnswerRe: COM and its availability via IIS Pin
Wes Aday27-Aug-12 11:12
memberWes Aday27-Aug-12 11:12 
AnswerRe: COM and its availability via IIS Pin
Eddy Vluggen12-Oct-12 14:01
memberEddy Vluggen12-Oct-12 14:01 
Questionusing a dll to read an smart card Pin
javadadabi17-Jun-12 8:44
memberjavadadabi17-Jun-12 8:44 
AnswerRe: using a dll to read an smart card Pin
javadadabi20-Jun-12 1:53
memberjavadadabi20-Jun-12 1:53 
AnswerRe: using a dll to read an smart card Pin
Brandon T. H.1-Oct-12 3:49
memberBrandon T. H.1-Oct-12 3:49 
QuestionOffice Outlook COM Interop best practice. Pin
The Fist30-Mar-12 12:00
memberThe 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:
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
memberkrumia21-Feb-12 18:05 
AnswerRe: Is COM an 'outdated' technology? Pin
Richard MacCutchan21-Feb-12 21:26
mvpRichard MacCutchan21-Feb-12 21:26 
GeneralRe: Is COM an 'outdated' technology? Pin
krumia21-Feb-12 21:33
memberkrumia21-Feb-12 21:33 
GeneralRe: Is COM an 'outdated' technology? Pin
Richard MacCutchan21-Feb-12 21:58
mvpRichard MacCutchan21-Feb-12 21:58 
JokeRe: Is COM an 'outdated' technology? Pin
bob1697220-Apr-12 19:22
memberbob1697220-Apr-12 19:22 
GeneralRe: Is COM an 'outdated' technology? Pin
Richard MacCutchan20-Apr-12 22:11
mvpRichard MacCutchan20-Apr-12 22:11 
GeneralRe: Is COM an 'outdated' technology? Pin
bob1697221-Apr-12 5:52
memberbob1697221-Apr-12 5:52 
GeneralRe: Is COM an 'outdated' technology? Pin
Richard MacCutchan21-Apr-12 7:44
mvpRichard MacCutchan21-Apr-12 7:44 
AnswerRe: Is COM an 'outdated' technology? Pin
Eddy Vluggen12-Oct-12 14:05
memberEddy Vluggen12-Oct-12 14:05 
QuestionIssues with identity of COM+ application Pin
Member 39605603-Feb-12 5:52
memberMember 39605603-Feb-12 5:52 
AnswerRe: Issues with identity of COM+ application Pin
Member 39605606-Feb-12 2:49
memberMember 39605606-Feb-12 2:49 
QuestionHow to convert COM proxy-stub dll to type library ? Pin
benjava28-Dec-11 17:35
memberbenjava28-Dec-11 17:35 
AnswerRe: How to convert COM proxy-stub dll to type library ? Pin
Jonathan Davies30-Dec-11 9:08
memberJonathan Davies30-Dec-11 9:08 
AnswerRe: How to convert COM proxy-stub dll to type library ? Pin
«_Superman_»6-Jan-12 16:23
mvp«_Superman_»6-Jan-12 16:23 
QuestionOPENING THE VBA EDITOR ON CLICK ON OLEOBJECTS BUTTON Pin
archana jain15-Dec-11 0:20
memberarchana 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
memberarchana jain14-Dec-11 22:18 
QuestionAdding Workbook In Excel Pin
cooldhaniya6-Dec-11 20:02
membercooldhaniya6-Dec-11 20:02 
QuestionNeed Com Help - I'm a beginner Pin
jkirkerx6-Nov-11 8:48
memberjkirkerx6-Nov-11 8:48 
AnswerRe: Need Com Help - I'm a beginner Pin
«_Superman_»6-Nov-11 15:36
mvp«_Superman_»6-Nov-11 15:36 
GeneralRe: Need Com Help - I'm a beginner Pin
jkirkerx6-Nov-11 19:34
memberjkirkerx6-Nov-11 19:34 
GeneralRe: Need Com Help - I'm a beginner Pin
jkirkerx9-Nov-11 7:36
memberjkirkerx9-Nov-11 7:36 
QuestionHow to use unregistered tlb file Pin
cooldhaniya30-Oct-11 23:54
membercooldhaniya30-Oct-11 23:54 
AnswerRe: How to use unregistered tlb file Pin
DriveByCoder24-Mar-15 7:48
memberDriveByCoder24-Mar-15 7:48 
QuestionCOM Component Late binding trouble Pin
nilarya25-Aug-11 6:28
membernilarya25-Aug-11 6:28 
AnswerRe: COM Component Late binding trouble Pin
tom-englert21-Sep-11 1:20
membertom-englert21-Sep-11 1:20 
GeneralRe: COM Component Late binding trouble Pin
nilarya6-Oct-11 23:27
membernilarya6-Oct-11 23:27 
GeneralRe: COM Component Late binding trouble Pin
tom-englert7-Oct-11 3:59
membertom-englert7-Oct-11 3:59 
GeneralRe: COM Component Late binding trouble Pin
nilarya7-Oct-11 22:46
membernilarya7-Oct-11 22:46 
GeneralRe: COM Component Late binding trouble Pin
nilarya7-Oct-11 22:57
membernilarya7-Oct-11 22:57 
GeneralRe: COM Component Late binding trouble Pin
nilarya23-Oct-11 23:27
membernilarya23-Oct-11 23:27 
GeneralRe: COM Component Late binding trouble Pin
tom-englert7-Nov-11 6:23
membertom-englert7-Nov-11 6:23 
AnswerRe: COM Component Late binding trouble Pin
Vi25-Oct-11 0:39
memberVi25-Oct-11 0:39 
QuestionUnable to register 64 bit COM Server Pin
sandeepkavade17-Aug-11 2:07
membersandeepkavade17-Aug-11 2:07 
AnswerRe: Unable to register 64 bit COM Server Pin
Shameel17-Aug-11 2:32
memberShameel17-Aug-11 2:32 
AnswerRe: Unable to register 64 bit COM Server Pin
«_Superman_»19-Aug-11 4:18
mvp«_Superman_»19-Aug-11 4:18 
QuestionRegarding SheetCalculate event in Excel API Pin
gtag20-Jun-11 10:02
membergtag20-Jun-11 10:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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
Web03 | 2.8.150603.1 | Last Updated 24 Jun 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid