Detect Outlook installed and load dynamically INterop.Outlook - c#

I have a Windows Forms application in VS2010. It has a reference to Interop.Outlook (2003). Then, I have reinstalled Windows XP and VS2010, but not install Outlook.
Now, the project not compiles.
I think this, my application will not work if Outlook not installed in machine that my program executes on.
I need to know if I detect Outlook installed, and load dynamically Interop.Outlook.dll (for using the Outlook PIA or Embedded Interop types in .NET 4).
If the machine has Outlook (2003, 2007, 2010, perhaps need code to detect version and do compatibility of Outlook versions) installed, the application works fine with functionally Outlook.
If the machine hasn't Outlook installed, the application works fine without functionally Outlook.
Any sample source code or goog patterns and practices about it??

To detect if Outlook is installed, look for the "Outlook.Application" ProgID.
From an installer, look in the registry for HKEY_CLASSES_ROOT\Outlook.Application
At runtime, you can do this:
using System;
using Microsoft.Office.Interop.Outlook;
class Program
{
static void Main(string[] args)
{
var outlookType = Type.GetTypeFromProgID("Outlook.Application");
if (outlookType == null)
{
Console.WriteLine("Not installed.");
}
else
{
var app = Activator.CreateInstance(outlookType) as Application;
Console.WriteLine(app.Name);
}
}
}
To avoid the problem of dynamically loading the interop, you should set Embed Interop Types to true for Microsoft.Office.Interop.Outlook.Interop.dll

check the Installer APIs to detect the install state of Outlook or use one of the method described here.

Related

Is It Possible To Load Add-in On Outlook Of MacOS

I have one native shim add-in project including C# class libraries.
Add-in works fine in windows OS (By using WIX).
Is it possible to load this add-in on outlook of MacOS?
If so, How can i do that ?
Is it possible to load this add-in on outlook of MacOS?
No, it is not possible. There is no COM technology available on other platforms. COM add-ins can be run on Windows only.
If so, How can i do that ?
There is no way to port an existing solution. You may consider developing a web-based Office add-in to support multiple platforms and devices. See Build your first Outlook add-in to get started quickly.

Avoid errors using Interop if the COMponent aren't installed

"If you want to use Interop, then the component should be installed in
the system. Otherwise, it won't work."
I have a WinForm application, that is used by many users in several SO (WinXP, Win7, Win8.1, WinServer 2008, WinServer 2012)
In development, I use a COM component (Outlook, SpeechLib,...).
Two keys:
Some users cannot installed the component. Or they haven't installed it.
Another users can be installed the component.
Any programatically way to:
avoid the application fails for the users that hasn't installed the component
the application works for the users that has installed the component
?
Notes:
Programmatically way to determine whether a particular COM library DLL has been installed or is installed. Anyways, if a particular COM library not installed, the target is that my source code not fails in runtime in that machine without that COM installed.
For example, for Excel, Word, Outlook COM (ActiveX), SpeechLib (Microsoft Speech Object Library), etc
I could have source code like this:
SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
SpeechLib.ISpeechVoice speech = new SpeechLib.SpVoiceClass();
// ....
Or anyways using Outlool application class, or Excel.Application, etc.
Type officeType = Type.GetTypeFromProgID("Excel.Application");
if (officeType == null)
{
// Excel is not installed.
// Show message or alert that Excel is not installed.
}
else
{
// Excel is installed.
// Continue your work.
}
My old issue, but not solution:
Detect Outlook installed and load dynamically INterop.Outlook
Detect Outlook installed and load dynamically INterop.Outlook
I have a Windows Forms application in VS2010. It has a reference to
Interop.Outlook (2003). Then, I have reinstalled Windows XP and
VS2010, but not install Outlook.
Now, the project not compiles.
I think this, my application will not work if Outlook not installed in
machine that my program executes on.
I need to know if I detect Outlook installed, and load dynamically
Interop.Outlook.dll (for using the Outlook PIA or Embedded Interop
types in .NET 4).
If the machine has Outlook (2003, 2007, 2010, perhaps need code to
detect version and do compatibility of Outlook versions) installed,
the application works fine with functionally Outlook.
If the machine hasn’t Outlook installed, (in runtime) the application
works fine without functionally Outlook. I think, If the machine
hasn’t Outlook installed, (in runtime) the application fails because
references (in source code) to Outlook.Application class?.
In development machine, the application works because Outlook (and
COM) is installed in the machine.
Any sample source code or goog patterns and practices about it??
References
Does this code fails if Office not installed in machine ?
How to detect installed version of MS-Office?
http://www.codeproject.com/Tips/679027/How-to-Check-Whether-Excel-is-Installed-in-the-Sys?msg=5027820#xx5027820xx
How to check, programatically, if MS Excel exists on a pc?
http://codeblog.jonskeet.uk/2009/07/07/faking-com-to-fool-the-c-compiler
I posted this elsewhere, but here's the code to detect if Outlook is installed. Basically, it tries to get the Outlook automation object.
using System;
using Microsoft.Office.Interop.Outlook;
class Program
{
static void Main(string[] args)
{
var outlookType = Type.GetTypeFromProgID("Outlook.Application");
if (outlookType == null)
{
Console.WriteLine("Not installed.");
}
else
{
var app = Activator.CreateInstance(outlookType) as Application;
Console.WriteLine(app.Name);
}
}
}
For SpeechLib, I think the right way to detect it is to just try and create a "new SpVoice()" instance wrapped with a try/catch. If it fails, then assume speech is not installed. Again, embedding the interop will allow you to avoid runtime type load issues.
Hope that helps.

C# Winforms Exception from HRESULT: 0x80040154

I have a winforms application which works perfectly in my x64 Win 7 dev environment but I cannot get the Outlook feature to work at all on the x86 XP machine, I keep getting this error when I try to open up a new Outlook mail with the address/subject line pre-filled in from the application side.
This only started happening since adding the reference to: Microsoft.Office.Interop.Outlook
This is the code used to create a new mail:
private void CreateOutlookEmail(string addresses)
{
Outlook.Application outlookApp = new Outlook.Application();
Outlook.MailItem mailItem = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.Subject = "";
mailItem.To = addresses;
mailItem.Body = "";
mailItem.Display(false);
}
I have been searching the forums for an answer but no luck thus far. Here is what I have tried without success:
Set the platform target to x86 in project properties in VS2010
Install the OWC11 binaries.
Install all windows updates on the win XP machine.
Must I install other packs on the XP machine?
You need to install the Primary Interop Assemblies on the system. This happens automatically on your development system since they are installed with VisualStudio. Other systems will not necessarily have them installed.
Better yet, you should probably be deploying with an installer - this would take care of the dependencies for you.
How to: Install Office Primary Interop Assemblies (MSDN)
Microsoft Office 2010: Primary Interop Assemblies Redistributable (download)
2007 Microsoft Office System Update: Redistributable Primary Interop Assemblies (download)
Office 2003 Update: Redistributable Primary Interop Assemblies (download)
See Also : How to: Install the Visual Studio Tools for Office Runtime Redistributable (MSDN)

VSTO application add-in won't load - says "The Managed Add-in Loader failed to initialize"

I have a PowerPoint 2010 application-level add-in developed using VS2012 and VSTO. It works with PowerPoint 2007 too. I built an installer for it using the (terrible) InstallShield LE crippleware provided with VS2012. I've been able to install it on various test machines, but now that I'm trying to deploy it to a client, they can't install it on some machines.
One user at the client's site can install it, but that user works in IT and has admin rights on his machine. However, when the IT admins try to install it on a "normal" user's machine, the install seems to go OK but the add-in is not loaded by PowerPoint.
The "COM add-ins" dialog shows the message:
Load behavior: Not loaded. The Managed Add-in Loader failed to initialize.
[In case it's relevant, this client uses Office 2007. Note however that it works OK on Office 2007 both on my test hardware and for that one user at the client.]
Is there anything I can do to figure out why? Is there anything obvious that I should be doing as part of the installation? Clearly the registry entries are being set, because the add-in is listed in the COM Add-ins dialog. And I assume that all the required files are installed, because the installer works fine on other machines.
I guess it may be a security-related issue. I should note that I'm not doing anything security-wise, and I don't think the InstallShield thing is doing anything helpful in this regard. I don't know whether it's necessary to digitally sign my code (I haven't), or somehow set some security policy stuff (I wouldn't know how). I've seen some stuff on-line about using CasPol (?) to apply security settings to add-ins, but that applied to older versions of VS and/or ClickOnce, and I wasn't sure whether I needed any of that.
It turns out that the VSTO runtime is not installed with Office 2007 (it is installed with Office 2010). The IT user who could load the add-in already had it because he'd installed something else that included it (I guess). The other users did not have it.
So, I updated my installer to include it, and it now works.

FileLoadException on windows 2003 for managed c++ dll

My company has login integration with GroupWise, and Exchange 5.5/2000+. The Exchange 5.5/GroupWise logic is done using wldap32.dll (win32), and so the login code is in a managed c++ class. When the configuration tool (or the backend service) tries to load the dll built off this managed c++ project on my XP development box, it works fine. On QA/Customer Windows 2003 boxes, a FileLoadException is thrown.
First off, this used to work fine. Secondly, I've validated the same working code on my box fails on the qa box.
How can I track down the cause of this exception?
Have you changed your development environment recently? In particular have you installed a service pack or new release of Visual Studio?
It appears you are linking against a C++ runtime that is not available on the client's server. You can use the Windows Event Viewer to identify the DLL failing to load, or if this shows nothing, use depends.exe to see what runtime DLLs are dependencies for your managed code.
Microsoft has moved to using side-by-side installation to handle "DLL hell", basically this allows multiple versions of a DLL to be installed (side-by-side) concurrently on a Windows installations and have applications load the correct version of the DLL at run-time. Recent releases of Visual Studio make use of this technology so I suspect this is the cause of your 'sudden' incompatibility.
Not to answer my own question, but support just updated the bug with the text following this paragraph. I'm still interested in thoughts on tracking down situations like this.
Resolved by downloading and installing the Visual C++ 2008 Redistributable
Package for Windows on the IMS:
http://www.microsoft.com/downloads/details.aspx?FamilyID=a5c84275-3b97-4ab7-a40d-3802b2af5fc2&DisplayLang=en

Categories

Resources