Dynamic .dll reference

B

Brian Mitchell

Hello, I have an application that uses word automation and everything is
working perfectly. However, I have one potential issue



1) I am using Office XP on my machine to design the app, however I
realize that not everyone will have that version of Office and thus won't
have the version 10 interop .dll. Is there any way to iterate through the
available assemblies on the system and dynamically reference them (instead
of explicitly adding a reference in the designer)?



I want to make sure that if someone is using Office 2000 it will reference
version 9 and office 2003 will be 11.



Thanks for the help!!
 
T

Tom Shelton

Hello, I have an application that uses word automation and everything is
working perfectly. However, I have one potential issue



1) I am using Office XP on my machine to design the app, however I
realize that not everyone will have that version of Office and thus won't
have the version 10 interop .dll. Is there any way to iterate through the
available assemblies on the system and dynamically reference them (instead
of explicitly adding a reference in the designer)?



I want to make sure that if someone is using Office 2000 it will reference
version 9 and office 2003 will be 11.



Thanks for the help!!

I'm going through that myself right now... The best, I have found so
far is to use late binding (that means Option Strict Off for the modules
where you're doing the interop)..

Option Strict Off
Option Explicit On

....

Public oExcel As Object = CreateObject("Excel.Application")

oExcel.Visible = True


The disadvantage of doing this is that you loose intellisense, and of
course late binding is slower - but the advantage is that you're not
tied to a specific version of office :)

I admit to not being an expert at Office development, but what I have
done in the past for the couple of apps I worked on in VB6 is to just go
ahead and reference the library on my system and develope the code.
When I'm done, I then remove the reference and convert all the types
object references to Object. Of course, you need to make sure you don't
use any version specific features, so you may want to do this against
the earliest version of Office you expect to support.

Other then that... Well, I have been trying to see if there is a way to
get a reference to the current office type library and generate a
interop assembly using the TypeLibaryConverter class... But, so far I
haven't come up with anything useful.

Well there's my two cents... Hopefully someone will have some better
ideas, so that we can both benifit here :) By the way, be glad your
doing the late binding code in VB.NET and not C#... It is a whole lot
harder...

// off the top of my head - so it may not be 100% accurate :)
public Type excelType = Type.GetTypeFromProgId("Excel.Application");
public object excelObject = Activator.CreateInstance(excelType);

excelType.InvokeMember(
"Visible",
BindingFlags.SetProperty,
null,
excelObject,
new object[] {true});

Yikes!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top