Click here to Skip to main content
15,896,118 members
Home / Discussions / COM
   

COM

 
AnswerRe: office 2003 interop Pin
Bernhard Hiller19-Nov-12 22:40
Bernhard Hiller19-Nov-12 22:40 
GeneralRe: office 2003 interop Pin
AnkitGoel.com10-Dec-12 17:47
AnkitGoel.com10-Dec-12 17:47 
QuestionHow to get INTERFACEDATA from ITypeInfo? Pin
masterhe11-Nov-12 3:50
masterhe11-Nov-12 3:50 
QuestionHow to add a bar in the bottom of Windows Explorer(not IE)? Pin
ohsorry9-Nov-12 16:07
ohsorry9-Nov-12 16:07 
AnswerRe: How to add a bar in the bottom of Windows Explorer(not IE)? Pin
Richard MacCutchan9-Nov-12 23:29
mveRichard MacCutchan9-Nov-12 23:29 
Question.NET COM component to replace existing Pin
cjb1108-Nov-12 6:59
cjb1108-Nov-12 6:59 
AnswerRe: .NET COM component to replace existing Pin
manoranjan20-Nov-12 5:56
manoranjan20-Nov-12 5:56 
GeneralRe: .NET COM component to replace existing Pin
cjb11020-Nov-12 9:17
cjb11020-Nov-12 9:17 
GeneralRe: .NET COM component to replace existing Pin
manoranjan20-Nov-12 17:03
manoranjan20-Nov-12 17:03 
QuestionEnumeration of implemented interfaces Pin
_Kel_22-Oct-12 6:30
_Kel_22-Oct-12 6:30 
GeneralRe: Enumeration of implemented interfaces Pin
_Kel_10-Dec-12 23:32
_Kel_10-Dec-12 23:32 
GeneralUsing Open MPI and CUDA in Windows 7 Pin
Sijo Mathew17-Sep-12 23:40
professionalSijo Mathew17-Sep-12 23:40 
QuestionCOM+ Talking To DCOM Object Pin
Member 81371057-Sep-12 3:43
Member 81371057-Sep-12 3:43 
AnswerRe: COM+ Talking To DCOM Object Pin
Member 81371057-Sep-12 4:43
Member 81371057-Sep-12 4:43 
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 

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.