COM DLL Import at design time

ADO DOT NET

Well-known member
Joined
Dec 20, 2006
Messages
156
Hi everyone,
My application needs outlook 2007 installed property to run.
I mean I have used some COM components from outlook 2007 in my app.
So if outlook is installed on the target system, my application wont have problem.
Otherwise my app wont even start and will close with an error.
I can check if outlook is installed on the system via registry.
But the question is that my only way would be importing those COM dlls at runtime to my app.
Is such thing possible in VB.NET 2005?
Exactly like you add some COM component reference at design time to the application?
In this way I can check first if outlook is installed then import those COM dlls to my app?
Thanks.
 
Does your application crash even before the Outlook COM Classes are referenced or is it just failing to create the objects?

If the object isnt registered then it should throw a trappable exception when it fails to create a valid instance - could you not simply catch this and notify the user?
 
Is it crashing before you are using them in code though? Will the application run ok until it actually attempts to use the Outlook COM objects?
 
That looks like it is at least running your application till it hits a line of code where you are trying to use the Outlook component (it is crashing in your Form_Load rather than earlier in the application).

Try putting a Try ... Catch block around the code you are using to instantiate the outlook component - if an exception is raised then outlook probably isnt installed.
 
Is it possible to use DLLImport some thing like this:?
<DllImport("*.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
 
DLLImport is used to reference a normal (i.e. non COM) DLL and would be no help in this case.

You should only be experiencing this problem when you attempt to use[/use] the component - simply running a program that references it will not be enough to cause a crash. Like I have said before simply wrap the call(s) to the component in a try catch block to catch the errors.
 
Back
Top