Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How do we call methods in DLL's using a string for the method name?

How do we call methods in DLL's using a string for the method name?

Scheduled Pinned Locked Moved C#
csharpc++helptutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rudy net
    wrote on last edited by
    #1

    In C or C++ we used to be able to call functions from DLL's by loading the dll library (Ex: LoadLibrary("library.dll");) then using the method GetProcAddress("functionName") to find a function by name in the library.dll. Now in C# the Dll's contain classes rather than isolated functions. Is is possible to call functions from Dll's in c#? I am mainly interested in being able to pass a function name as parameter then use something like the GetProcAddress method that uses that function name to find it in the dll so we can call it. Example in C++: //this method will call a function from the library (no error checks to simplify) void CallFunction(char* libraryName, char* functionName) { //declare the function that will be called: typedef void * (FUNC)(int); //function that returns void and takes an int FUNC pFunction; //load dll library: HINSTANCE hLibrary = LoadLibrary("Library.dll"); //find function in library: pFunction = (FUNC) GetProcAddress(hLibrary, functionName); //call function pFunction(35); }

    S 1 Reply Last reply
    0
    • R rudy net

      In C or C++ we used to be able to call functions from DLL's by loading the dll library (Ex: LoadLibrary("library.dll");) then using the method GetProcAddress("functionName") to find a function by name in the library.dll. Now in C# the Dll's contain classes rather than isolated functions. Is is possible to call functions from Dll's in c#? I am mainly interested in being able to pass a function name as parameter then use something like the GetProcAddress method that uses that function name to find it in the dll so we can call it. Example in C++: //this method will call a function from the library (no error checks to simplify) void CallFunction(char* libraryName, char* functionName) { //declare the function that will be called: typedef void * (FUNC)(int); //function that returns void and takes an int FUNC pFunction; //load dll library: HINSTANCE hLibrary = LoadLibrary("Library.dll"); //find function in library: pFunction = (FUNC) GetProcAddress(hLibrary, functionName); //call function pFunction(35); }

      S Offline
      S Offline
      Stefan Troschuetz
      wrote on last edited by
      #2

      Take a look at the Reflection namespace.


      www.troschuetz.de

      R 1 Reply Last reply
      0
      • S Stefan Troschuetz

        Take a look at the Reflection namespace.


        www.troschuetz.de

        R Offline
        R Offline
        rudy net
        wrote on last edited by
        #3

        Got it! Thanks :-D Here is a link where I found a good example in msdn web site in case someone else needs it: [http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet02262002.asp](Mirror, Mirror (a vb reflection example))

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups