This code works, after being build as an exe-file:
output
Microsoft.Office.Interop.Outlook.ApplicationClass
It doesn't work in debug-mode in Visual Studio 2010 Professional :
output
System.Runtime.InteropServices.COMException (0x800401E3): Handlingen er ikke tilgængelig (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE)) at System.Runtime.InteropServices.Marshal.GetActiveObject(Guid& rclsid, IntPtr reserved, Object& ppunk) at System.Runtime.InteropServices.Marshal.GetActiveObject(String progID) at MailAgent.Form1.button1_Click(Object sender, EventArgs e) in S:\Back-office\Optimering\Udvikling\Projects\MailAgent\MailAgent\Form1.cs:line 25
Can someone explain why? Do I need to disable a sandbox-setting in VS?
the code
private void button1_Click(object sender, EventArgs e)
{
try
{
Object obj;
obj = Marshal.GetActiveObject("Outlook.Application");
//Outputting both as MsgBox and to Clipboard
System.Windows.Forms.Clipboard.SetText(obj.ToString());
MessageBox.Show(obj.ToString());
}
catch (Exception ex)
{
//Outputting both as MsgBox and to Clipboard
System.Windows.Forms.Clipboard.SetText(ex.ToString());
MessageBox.Show(ex.ToString());
}
}
Of course, I am happy that it works in the build. But if it works, without me understanding why, I won't be able to solve the problem, if it one day strikes in the build too.
User contributions licensed under CC BY-SA 3.0