DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    John Jensen Guest

    Late DLL binding


    Hi

    How do I make a late binding to a .NET DLL ?
    Instead of adding a reference when compiling the .exe assembly I want to
    be able to invoke a dll-file when my program is running?
    Could anyone please help..


    John

  2. #2
    Per Thygesen Guest

    Re: Late DLL binding

    In C# you can use reflection.
    --
    Per Thygesen


    "John Jensen" <john@birkkoff.dk> wrote in message
    news:3aa79c6d$1@news.devx.com...
    >
    > Hi
    >
    > How do I make a late binding to a .NET DLL ?
    > Instead of adding a reference when compiling the .exe assembly I want to
    > be able to invoke a dll-file when my program is running?
    > Could anyone please help..
    >
    >
    > John




  3. #3
    John Jensen Guest

    Re: Late DLL binding


    Could you give an example please..?

    "Per Thygesen" <perthygesen@hotmail.com> wrote:
    >In C# you can use reflection.
    >--
    >Per Thygesen
    >
    >
    >"John Jensen" <john@birkkoff.dk> wrote in message
    >news:3aa79c6d$1@news.devx.com...
    >>
    >> Hi
    >>
    >> How do I make a late binding to a .NET DLL ?
    >> Instead of adding a reference when compiling the .exe assembly I want

    to
    >> be able to invoke a dll-file when my program is running?
    >> Could anyone please help..
    >>
    >>
    >> John

    >
    >



  4. #4
    Per Thygesen Guest

    Re: Late DLL binding

    Sure.

    Invoke.cs
    -------------------------
    using System;
    using System.Reflection;

    public class Invoke
    {
    public static void Main ()
    {
    Assembly asm = Assembly.LoadFrom(".\\Test.exe");

    // Call a static method
    Type t = asm.GetType("TestClass");
    t.InvokeMember ("SayHello",
    BindingFlags.Default | BindingFlags.InvokeMethod |
    BindingFlags.Static,
    null, null, new object [] {});

    // Call instance method
    object obj = Activator.CreateInstance(t);
    t.InvokeMember ("SayHello2",
    BindingFlags.Default | BindingFlags.InvokeMethod,
    null, obj, new object [] {});
    }
    }

    Test.cs
    -------------------------
    using System;

    public class TestClass
    {
    public static void SayHello ()
    {
    Console.WriteLine ("Hello");
    }

    public void SayHello2 ()
    {
    Console.WriteLine ("Hello2");
    }

    public static void Main() {}
    }

    --
    Per Thygesen

    "John Jensen" <john@birkof.dk> wrote in message
    news:3aa8b0f4@news.devx.com...
    >
    > Could you give an example please..?
    >
    > "Per Thygesen" <perthygesen@hotmail.com> wrote:
    > >In C# you can use reflection.
    > >--
    > >Per Thygesen
    > >
    > >
    > >"John Jensen" <john@birkkoff.dk> wrote in message
    > >news:3aa79c6d$1@news.devx.com...
    > >>
    > >> Hi
    > >>
    > >> How do I make a late binding to a .NET DLL ?
    > >> Instead of adding a reference when compiling the .exe assembly I want

    > to
    > >> be able to invoke a dll-file when my program is running?
    > >> Could anyone please help..
    > >>
    > >>
    > >> John

    > >
    > >

    >




  5. #5
    John Jensen Guest

    Re: Late DLL binding


    Thanks!!


    "Per Thygesen" <perthygesen@hotmail.com> wrote:
    >Sure.
    >
    >Invoke.cs
    >-------------------------
    >using System;
    >using System.Reflection;
    >
    >public class Invoke
    >{
    > public static void Main ()
    > {
    > Assembly asm = Assembly.LoadFrom(".\\Test.exe");
    >
    > // Call a static method
    > Type t = asm.GetType("TestClass");
    > t.InvokeMember ("SayHello",
    > BindingFlags.Default | BindingFlags.InvokeMethod |
    >BindingFlags.Static,
    > null, null, new object [] {});
    >
    > // Call instance method
    > object obj = Activator.CreateInstance(t);
    > t.InvokeMember ("SayHello2",
    > BindingFlags.Default | BindingFlags.InvokeMethod,
    > null, obj, new object [] {});
    > }
    >}
    >
    >Test.cs
    >-------------------------
    >using System;
    >
    >public class TestClass
    >{
    > public static void SayHello ()
    > {
    > Console.WriteLine ("Hello");
    > }
    >
    > public void SayHello2 ()
    > {
    > Console.WriteLine ("Hello2");
    > }
    >
    > public static void Main() {}
    >}
    >
    >--
    >Per Thygesen
    >
    >"John Jensen" <john@birkof.dk> wrote in message
    >news:3aa8b0f4@news.devx.com...
    >>
    >> Could you give an example please..?
    >>
    >> "Per Thygesen" <perthygesen@hotmail.com> wrote:
    >> >In C# you can use reflection.
    >> >--
    >> >Per Thygesen
    >> >
    >> >
    >> >"John Jensen" <john@birkkoff.dk> wrote in message
    >> >news:3aa79c6d$1@news.devx.com...
    >> >>
    >> >> Hi
    >> >>
    >> >> How do I make a late binding to a .NET DLL ?
    >> >> Instead of adding a reference when compiling the .exe assembly I want

    >> to
    >> >> be able to invoke a dll-file when my program is running?
    >> >> Could anyone please help..
    >> >>
    >> >>
    >> >> John
    >> >
    >> >

    >>

    >
    >



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links