-
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
-
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
-
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
>
>
-
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
> >
> >
>
-
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
>> >
>> >
>>
>
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
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
|
Bookmarks