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. Implicit vs Explicit Linking of DLLs

Implicit vs Explicit Linking of DLLs

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestionvisual-studiohelpworkspace
5 Posts 3 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.
  • V Offline
    V Offline
    VanHlebar
    wrote on last edited by
    #1

    I finally figured out how to get my dlls setup properly and exported the functions and was able to import the functions into another project. When I did this I had to add the .lib file to my project and compile the project with the lib file to be able to access the exported functions. What I would really like to do is link to the dll Explicitly using LoadLibrary and GetProcAddress. To explain why I need to ask another question. I am going to have a series of dlls that will all export the same functions but will have different data returned depending on the dll that is called. For example each dll might have a function exported call GetNames(). If dll1 is called in might return John, Jill, Jack and Joe. If dll2 is called it might return Amber, Ally, Allen and Ashely. Now what I really wanted to be able to do is not have to recompile the the main application when I add each dll. I need a way to be able to have my main application check to see which dlls are available and then call those functions for each dll. If I have to include the .lib file for each dll won't I have to recompile the project each time I add a new dll? Or will I have to recompile the project each time no matter which style I use? Thanks for all the help from everyone with my relentless dll questions. :) -Eric

    C 1 Reply Last reply
    0
    • V VanHlebar

      I finally figured out how to get my dlls setup properly and exported the functions and was able to import the functions into another project. When I did this I had to add the .lib file to my project and compile the project with the lib file to be able to access the exported functions. What I would really like to do is link to the dll Explicitly using LoadLibrary and GetProcAddress. To explain why I need to ask another question. I am going to have a series of dlls that will all export the same functions but will have different data returned depending on the dll that is called. For example each dll might have a function exported call GetNames(). If dll1 is called in might return John, Jill, Jack and Joe. If dll2 is called it might return Amber, Ally, Allen and Ashely. Now what I really wanted to be able to do is not have to recompile the the main application when I add each dll. I need a way to be able to have my main application check to see which dlls are available and then call those functions for each dll. If I have to include the .lib file for each dll won't I have to recompile the project each time I add a new dll? Or will I have to recompile the project each time no matter which style I use? Thanks for all the help from everyone with my relentless dll questions. :) -Eric

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      VanHlebar wrote: If I have to include the .lib file for each dll won't I have to recompile the project each time I add a new dll? yes. since you're linking to the static lib, your app will have the DLL name encoded into it somewhere. it sounds like you're doing a plug-in system. (click here to learn more! :) ) if that's the case, what you need to do (IMO) is to write an interface layer between the DLLs and the code that calls the DLL. this layer will act as a proxy between your DLLs and the caller. in addition to allowing a way to call the DLL functions, it will handle DLL loading and unloading. your app can just scan a folder (or whatever) and get a list of DLLs that support your interface (just GetProcAddr for all your calls; if they're all there, the DLL is good, add it to the list). make that proxy layer a class and instantiate one per DLL. put them all in an array and you're all set :) -c


      I'm not the droid you're looking for.

      ThumbNailer

      V 1 Reply Last reply
      0
      • C Chris Losinger

        VanHlebar wrote: If I have to include the .lib file for each dll won't I have to recompile the project each time I add a new dll? yes. since you're linking to the static lib, your app will have the DLL name encoded into it somewhere. it sounds like you're doing a plug-in system. (click here to learn more! :) ) if that's the case, what you need to do (IMO) is to write an interface layer between the DLLs and the code that calls the DLL. this layer will act as a proxy between your DLLs and the caller. in addition to allowing a way to call the DLL functions, it will handle DLL loading and unloading. your app can just scan a folder (or whatever) and get a list of DLLs that support your interface (just GetProcAddr for all your calls; if they're all there, the DLL is good, add it to the list). make that proxy layer a class and instantiate one per DLL. put them all in an array and you're all set :) -c


        I'm not the droid you're looking for.

        ThumbNailer

        V Offline
        V Offline
        VanHlebar
        wrote on last edited by
        #3

        Chris Losinger wrote: it sounds like you're doing a plug-in system. (click here to learn more! ) Chris, I clicked but didn't go anywhere :) Yes it is sort of a plug-in system. The user will be able to get the extra dlls and choose which ones they want to use and which ones not to use. I like the idea of being able to instantiate one class per dll and having an array, but I guess I would need more information on how to do just that. Thanks for the help, -Eric

        C R 2 Replies Last reply
        0
        • V VanHlebar

          Chris Losinger wrote: it sounds like you're doing a plug-in system. (click here to learn more! ) Chris, I clicked but didn't go anywhere :) Yes it is sort of a plug-in system. The user will be able to get the extra dlls and choose which ones they want to use and which ones not to use. I like the idea of being able to instantiate one class per dll and having an array, but I guess I would need more information on how to do just that. Thanks for the help, -Eric

          C Offline
          C Offline
          Chris Losinger
          wrote on last edited by
          #4

          somethign like this:

          class CMyProxy
          {
          public:
          CMyProxy();

          // calls FreeLibrary
          ~CMyProxy();

          // calls LoadLibrary. then calls GetProcAddress for each function
          // and assigns each proc addr to a member function of the appropriate type
          bool Load(const char *pDLLName);

          RetType MyFunc1(...) {return (m_pFunc1)(...);}
          RetType MyFunc2(...) {return (m_pFunc2)(...);}

          protected:
          FuncType1 m_pFunc1;
          FuncType2 m_pFunc2;
          };

          CMyProxy proxy;
          if (proxy.Load(pDLLFileName))
          {
          RetType ret = proxy.MyFunc1(whatever, whatever);
          }

          so, the CMyProxy class loads the DLL, gets function pointers and lets you call DLL functions through its own function wrappers. -c


          I'm not the droid you're looking for.

          ThumbNailer

          1 Reply Last reply
          0
          • V VanHlebar

            Chris Losinger wrote: it sounds like you're doing a plug-in system. (click here to learn more! ) Chris, I clicked but didn't go anywhere :) Yes it is sort of a plug-in system. The user will be able to get the extra dlls and choose which ones they want to use and which ones not to use. I like the idea of being able to instantiate one class per dll and having an array, but I guess I would need more information on how to do just that. Thanks for the help, -Eric

            R Offline
            R Offline
            Roger Allen
            wrote on last edited by
            #5

            This article Plug-In Architecture.asp[^] of mine does what Chris is suggesting. Its probably overkill for your current situation, but you should be able to cut out the bits you needs and modify them to what you require. Roger Allen Sonork 100.10016 This is a multiple choice question, choose wisely Why did the hedgehog cross the road? A: To show he had guts? B: To see his flat mate?

            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