Dynamic .dll reference

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian Mitchell

    Dynamic .dll reference

    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!!




  • Tom Shelton

    #2
    Re: Dynamic .dll reference

    On 2004-02-19, Brian Mitchell <MagellanTX@hot mail.com> wrote:[color=blue]
    > 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!![/color]

    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("E xcel.Applicatio n")

    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 TypeLibaryConve rter 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.GetTypeFro mProgId("Excel. Application");
    public object excelObject = Activator.Creat eInstance(excel Type);

    excelType.Invok eMember(
    "Visible",
    BindingFlags.Se tProperty,
    null,
    excelObject,
    new object[] {true});

    Yikes!
    --
    Tom Shelton [MVP]
    Powered By Gentoo Linux 1.4
    Once the toothpaste is out of the tube, it's hard to get it back in.
    -- H.R. Haldeman

    Comment

    Working...