Loading a DLL file

This is a discussion on Loading a DLL file within the C# Programming forums, part of the General Programming Boards category; How can I load a DLL file when my program is running? (I'm using C# 2005 Express) BTW the DLL ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    98

    Loading a DLL file

    How can I load a DLL file when my program is running?
    (I'm using C# 2005 Express)

    BTW the DLL is also written in C# 2005.
    Last edited by Mavix; 08-21-2007 at 06:48 AM. Reason: Added some more information

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Not sure about C#, but in regular C/C++ it's:
    Code:
    	HMODULE h;
    	h = LoadLibrary("somename.dll");
    Then you can get the functions in that by for example:
    Code:
    	funcs.Init = (Init)GetProcAddress(h, "Init");
    --
    Mats

  3. #3
    Registered User
    Join Date
    Aug 2007
    Location
    Gloucester, England
    Posts
    11

    Cool Reflection is the answer

    I think the best way is using Reflection.

    Code:
    using System.Reflection;
    Assembly myAssembly = Assembly.LoadFrom(MyAssemblyName);
    Or

    Code:
    using System.Reflection;
    Assembly myAssembly = Assembly.LoadFile(MyAssemblyPath);
    Regards
    Pete

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  4. multiple file loading. so fruturated! help!
    By psychopath in forum Game Programming
    Replies: 5
    Last Post: 05-09-2005, 05:13 PM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21