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 / C++ / MFC
  4. load dll

load dll

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
4 Posts 4 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.
  • B Offline
    B Offline
    Benjamin Bruno
    wrote on last edited by
    #1

    How to load dll in pure C++ class?

    C O E 3 Replies Last reply
    0
    • B Benjamin Bruno

      How to load dll in pure C++ class?

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      What do you really mean? You know there's a function, namely LoadLibrary[^] to (explicitely) load a dynamic library.

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      1 Reply Last reply
      0
      • B Benjamin Bruno

        How to load dll in pure C++ class?

        O Offline
        O Offline
        Orjan Westin
        wrote on last edited by
        #3

        The question isn't very clear, I'm afraid. If you use "pure C++" to mean only standards-compliant language elements/libraries, the answer is that you can't. To start with, DLL files are specific for the Windows platform, so any solution would not work on Unix/Linux/MacOS etc. If you are concerned that the Windows function to load a DLL (LoadLibrary, as already noted) is a C function, and therefore should not for some reason be used in "pure C++", don't worry - a large reason for making C++ backwards compatible with C was that many operating systems offer their native APIs as C functions, and calling them is a perfectly valid use of C++.

        1 Reply Last reply
        0
        • B Benjamin Bruno

          How to load dll in pure C++ class?

          E Offline
          E Offline
          Eugen Podsypalnikov
          wrote on last edited by
          #4

          Here is an exception-free way :) :

          class CSafeDllHolder {
          HMODULE m_hModule;

          public:
          CSafeDllHolder(LPCTSTR lpszLib) : m_hModule(::LoadLibrary(lpszLib)) {}
          ~CSafeDllHolder() { if (m_hModule) ::FreeLibrary(m_hModule); }

          HMODULE GetHandle() const { return m_hModule; }
          //..
          };

          They sought it with thimbles, they sought it with care; They pursued it with forks and hope; They threatened its life with a railway-share; They charmed it with smiles and soap. :)

          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