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. Calling unmanaged code

Calling unmanaged code

Scheduled Pinned Locked Moved C#
csharpalgorithmsquestion
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.
  • F Offline
    F Offline
    Frank Olorin Rizzi
    wrote on last edited by
    #1

    Hi all. I haven't found an answer to this through quite some googling and searching, so I hope someone can provide some tips. Here's the deal: How can you call unmanaged code from a C# app? Yeah, I know about a few ways to do it, but they all seem to rely on the DllImport attribute initialized with the name of the DLL to be called at compile-time. For instance: [DllImport("msvcrt.dll")] in my case, I will not know the name of the unmanaged dll to be called until run-time. The name of the dll will come from a config file. So, imagine string unmanagedDll = this.GetUnmanagedDllNameFromConfigFile(); and now, is there any way to *programmatically* do the equivalent of [DllImport(unmanagedDll)] ? Thanks in advance for any suggestion, F.O.R.

    D 1 Reply Last reply
    0
    • F Frank Olorin Rizzi

      Hi all. I haven't found an answer to this through quite some googling and searching, so I hope someone can provide some tips. Here's the deal: How can you call unmanaged code from a C# app? Yeah, I know about a few ways to do it, but they all seem to rely on the DllImport attribute initialized with the name of the DLL to be called at compile-time. For instance: [DllImport("msvcrt.dll")] in my case, I will not know the name of the unmanaged dll to be called until run-time. The name of the dll will come from a config file. So, imagine string unmanagedDll = this.GetUnmanagedDllNameFromConfigFile(); and now, is there any way to *programmatically* do the equivalent of [DllImport(unmanagedDll)] ? Thanks in advance for any suggestion, F.O.R.

      D Offline
      D Offline
      Dan_P
      wrote on last edited by
      #2

      You might want to have a look at this article: [http://www.codeproject.com/csharp/dyninvok.asp](http://
      http://www.codeproject.com/csharp/dyninvok.asp)[[^](http://
      http://www.codeproject.com/csharp/dyninvok.asp)]

      F 1 Reply Last reply
      0
      • D Dan_P

        You might want to have a look at this article: [http://www.codeproject.com/csharp/dyninvok.asp](http://
        http://www.codeproject.com/csharp/dyninvok.asp)[[^](http://
        http://www.codeproject.com/csharp/dyninvok.asp)]

        F Offline
        F Offline
        Frank Olorin Rizzi
        wrote on last edited by
        #3

        Thanks, that might be just what I was looking for. F.O.R.

        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