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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. dynamically loading an unmanaged dll

dynamically loading an unmanaged dll

Scheduled Pinned Locked Moved Managed C++/CLI
questioncsharpc++helpannouncement
3 Posts 3 Posters 2 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.
  • S Offline
    S Offline
    shezh
    wrote on last edited by
    #1

    Hi, I'm trying to dynamically load an unmanaged dll and call a function within it from a managed C++ app. I've managed to do this in an unmanaged C++ app, using calls to LoadLibrary and GetProcAdddress, but don't know what to do in the .NET version. I know there's P/Invoke, but with that the library has to be declared at compile-time, and I won't know the (unmanaged) library until run-time. So i guess the question is how can I use the LoadLibrary and GetProcAddress functions in managed C++ (again not using P/Invoke, as the library won't be known until run-time)? Thanks for your help Cheeze

    J N 2 Replies Last reply
    0
    • S shezh

      Hi, I'm trying to dynamically load an unmanaged dll and call a function within it from a managed C++ app. I've managed to do this in an unmanaged C++ app, using calls to LoadLibrary and GetProcAdddress, but don't know what to do in the .NET version. I know there's P/Invoke, but with that the library has to be declared at compile-time, and I won't know the (unmanaged) library until run-time. So i guess the question is how can I use the LoadLibrary and GetProcAddress functions in managed C++ (again not using P/Invoke, as the library won't be known until run-time)? Thanks for your help Cheeze

      J Offline
      J Offline
      Jun Du
      wrote on last edited by
      #2

      Actually, P/Invoking unmanaged DLL via DllImport() is dynamic loading. Until the program runs to that point, it won't check if the DLL exists or if the function call has right signature.

      Best, Jun

      1 Reply Last reply
      0
      • S shezh

        Hi, I'm trying to dynamically load an unmanaged dll and call a function within it from a managed C++ app. I've managed to do this in an unmanaged C++ app, using calls to LoadLibrary and GetProcAdddress, but don't know what to do in the .NET version. I know there's P/Invoke, but with that the library has to be declared at compile-time, and I won't know the (unmanaged) library until run-time. So i guess the question is how can I use the LoadLibrary and GetProcAddress functions in managed C++ (again not using P/Invoke, as the library won't be known until run-time)? Thanks for your help Cheeze

        N Offline
        N Offline
        Nish Nishant
        wrote on last edited by
        #3

        cheeze103 wrote:

        I've managed to do this in an unmanaged C++ app, using calls to LoadLibrary and GetProcAdddress, but don't know what to do in the .NET version.

        You can use the exact same code in your managed app too. Just #include the required header files, and link with the required import libs.

        Regards, Nish


        Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
        Currently working on C++/CLI in Action for Manning Publications. Also visit the Ultimate Toolbox blog (New)

        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