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. C / C++ / MFC
  4. Explicitly link DLL [modified]

Explicitly link DLL [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialc++
10 Posts 5 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
    shakumar_22
    wrote on last edited by
    #1

    Hi I want to imort dll through dynamic link in vc++ 6.0. I know static link dll, giving the lib file in projects->setting->link->lib path and Store the dll file in system directory. And by using “using namespace “ we can access all the function in the dll automatically. Now I want to know how to link dll dynamically. There are some example in google search, even I could not understand that. If you give any suggestion (step by step)or any simple example ,its very useful for me. Regards shakumar

    shakumar

    modified on Thursday, May 22, 2008 5:21 AM

    R C F 3 Replies Last reply
    0
    • S shakumar_22

      Hi I want to imort dll through dynamic link in vc++ 6.0. I know static link dll, giving the lib file in projects->setting->link->lib path and Store the dll file in system directory. And by using “using namespace “ we can access all the function in the dll automatically. Now I want to know how to link dll dynamically. There are some example in google search, even I could not understand that. If you give any suggestion (step by step)or any simple example ,its very useful for me. Regards shakumar

      shakumar

      modified on Thursday, May 22, 2008 5:21 AM

      R Offline
      R Offline
      Rajesh R Subramanian
      wrote on last edited by
      #2

      DLLs are simple - Part 1 to 4[^] See the DLLs and Assemblies section in this page by Hans Dietrich[^] Also, see DLLs and Assemblies[^] under general programming. Additionally, read in MSDN about LoadLibrary(), GetProcAddress().

      Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

      1 Reply Last reply
      0
      • S shakumar_22

        Hi I want to imort dll through dynamic link in vc++ 6.0. I know static link dll, giving the lib file in projects->setting->link->lib path and Store the dll file in system directory. And by using “using namespace “ we can access all the function in the dll automatically. Now I want to know how to link dll dynamically. There are some example in google search, even I could not understand that. If you give any suggestion (step by step)or any simple example ,its very useful for me. Regards shakumar

        shakumar

        modified on Thursday, May 22, 2008 5:21 AM

        C Offline
        C Offline
        Cedric Moonen
        wrote on last edited by
        #3

        Dll's are always dynamically linked (dll stands for dynamic link library). So what's your question exactly ? Why don't you want to use the static lib provided with the dll ? (BTW this doesn't contain the code of the dll but only information about how to load the dll, basically). You can also use LoadLibrary to load the dll and then use GetProcAddress to retrieve the address of a specific exported function of your dll. But this is a bit more complex. The main advantage is that you can handle the error when the dll is missing the way you want (and not simply have an error message saying that the dll is missing and then exit the program).

        Cédric Moonen Software developer
        Charting control [v1.4]

        S 1 Reply Last reply
        0
        • S shakumar_22

          Hi I want to imort dll through dynamic link in vc++ 6.0. I know static link dll, giving the lib file in projects->setting->link->lib path and Store the dll file in system directory. And by using “using namespace “ we can access all the function in the dll automatically. Now I want to know how to link dll dynamically. There are some example in google search, even I could not understand that. If you give any suggestion (step by step)or any simple example ,its very useful for me. Regards shakumar

          shakumar

          modified on Thursday, May 22, 2008 5:21 AM

          F Offline
          F Offline
          Force Code
          wrote on last edited by
          #4

          typedef DWORD (*GETNGLYPHS)(HDC hdc,LPCTSTR lpstr,int c,LPWORD pgi,DWORD fl); GETNGLYPHS GetGlyphIndices = (GETNGLYPHS)GetProcAddress(LoadLibrary("gdi32.dll"), "GetGlyphIndicesA"); . . . GetGlyphIndices(hdc,save_chrs,sg_cnt,save_glyphs,1);

          R 1 Reply Last reply
          0
          • C Cedric Moonen

            Dll's are always dynamically linked (dll stands for dynamic link library). So what's your question exactly ? Why don't you want to use the static lib provided with the dll ? (BTW this doesn't contain the code of the dll but only information about how to load the dll, basically). You can also use LoadLibrary to load the dll and then use GetProcAddress to retrieve the address of a specific exported function of your dll. But this is a bit more complex. The main advantage is that you can handle the error when the dll is missing the way you want (and not simply have an error message saying that the dll is missing and then exit the program).

            Cédric Moonen Software developer
            Charting control [v1.4]

            S Offline
            S Offline
            shakumar_22
            wrote on last edited by
            #5

            Thanks for your reply As i said above ,in my programme I used shell32.dll, I import the dll through project->setting->link->giving lib path ”shell.lib”. it automatically(ctl+tab) it give the function “SHFILEOPSTRUCT.” I want to load dll at runtime ,ie: giving the path of the dll through the code. My doubt was when I loading dll at run time , how can I access the function from dll because at run time only dll will import, so we cannot know what are the function is available in dll. Will all the dll can import(dynamic) like this. It may be simple for u, for me it is not understand, so give u’r suggestion. Regards shakumar

            shakumar

            C 1 Reply Last reply
            0
            • S shakumar_22

              Thanks for your reply As i said above ,in my programme I used shell32.dll, I import the dll through project->setting->link->giving lib path ”shell.lib”. it automatically(ctl+tab) it give the function “SHFILEOPSTRUCT.” I want to load dll at runtime ,ie: giving the path of the dll through the code. My doubt was when I loading dll at run time , how can I access the function from dll because at run time only dll will import, so we cannot know what are the function is available in dll. Will all the dll can import(dynamic) like this. It may be simple for u, for me it is not understand, so give u’r suggestion. Regards shakumar

              shakumar

              C Offline
              C Offline
              Cedric Moonen
              wrote on last edited by
              #6

              shakumar_22 wrote:

              I want to load dll at runtime

              It WILL be loaded at runtime. That's the purpose of the dll. As I said in my previous post, it's not because you link against shell32.lib that you are statically linking. The lib file only contains information about the way to load your dll but your dll will still be loaded at runtime. The only thing you have to make sure is that in your project settings, you choose the runtime library as a dll: (for VC2005) open your project properties -> C/C++ entry -> "Code generation" -> "Runtime Library" and there select "Multi-threaded Debug Dll" (or "Multi-threaded Dll" if you are in release mode).

              Cédric Moonen Software developer
              Charting control [v1.4]

              R 1 Reply Last reply
              0
              • C Cedric Moonen

                shakumar_22 wrote:

                I want to load dll at runtime

                It WILL be loaded at runtime. That's the purpose of the dll. As I said in my previous post, it's not because you link against shell32.lib that you are statically linking. The lib file only contains information about the way to load your dll but your dll will still be loaded at runtime. The only thing you have to make sure is that in your project settings, you choose the runtime library as a dll: (for VC2005) open your project properties -> C/C++ entry -> "Code generation" -> "Runtime Library" and there select "Multi-threaded Debug Dll" (or "Multi-threaded Dll" if you are in release mode).

                Cédric Moonen Software developer
                Charting control [v1.4]

                R Offline
                R Offline
                Rajesh R Subramanian
                wrote on last edited by
                #7

                I think he is looking for ways to load the DLL from his program, without the help of a .lib file. That's what I understand. CPMRU is charged, you see. [add] May I know why is this post down-voted. I'll appreciate any feedback. :) [/add]

                Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

                modified on Thursday, May 22, 2008 4:49 AM

                C 1 Reply Last reply
                0
                • R Rajesh R Subramanian

                  I think he is looking for ways to load the DLL from his program, without the help of a .lib file. That's what I understand. CPMRU is charged, you see. [add] May I know why is this post down-voted. I'll appreciate any feedback. :) [/add]

                  Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

                  modified on Thursday, May 22, 2008 4:49 AM

                  C Offline
                  C Offline
                  Cedric Moonen
                  wrote on last edited by
                  #8

                  Yes I got that but for what reason exactly ? I honnestly it will only make things much more complex with no added value in this case. He is talking about a windows dll for which I don't see any reason why you would load it explicitely. (and I also already gave him an answer if he really wants to do load it explicitely in my first post :) ).

                  Cédric Moonen Software developer
                  Charting control [v1.4]

                  R 1 Reply Last reply
                  0
                  • C Cedric Moonen

                    Yes I got that but for what reason exactly ? I honnestly it will only make things much more complex with no added value in this case. He is talking about a windows dll for which I don't see any reason why you would load it explicitely. (and I also already gave him an answer if he really wants to do load it explicitely in my first post :) ).

                    Cédric Moonen Software developer
                    Charting control [v1.4]

                    R Offline
                    R Offline
                    Rajesh R Subramanian
                    wrote on last edited by
                    #9

                    Cedric Moonen wrote:

                    Yes I got that but for what reason exactly ?

                    May be just to explore and learn the other ways of loading a DLL?! I had to always load DLLs the LoadLibrary() way when I was working for my first employer. They had a bunch of third party DLLs to use in the project, and no corresponding .lib files. There might be a similar situation. Could be anything. But just keep the CPMRU handy, just in case. :-D

                    Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

                    1 Reply Last reply
                    0
                    • F Force Code

                      typedef DWORD (*GETNGLYPHS)(HDC hdc,LPCTSTR lpstr,int c,LPWORD pgi,DWORD fl); GETNGLYPHS GetGlyphIndices = (GETNGLYPHS)GetProcAddress(LoadLibrary("gdi32.dll"), "GetGlyphIndicesA"); . . . GetGlyphIndices(hdc,save_chrs,sg_cnt,save_glyphs,1);

                      R Offline
                      R Offline
                      Rajkumar R
                      wrote on last edited by
                      #10

                      Force Code wrote:

                      typedef DWORD (*GETNGLYPHS)(HDC hdc,LPCTSTR lpstr,int c,LPWORD pgi,DWORD fl);

                      generic Text data type and linking to ANSI version API.

                      Force Code wrote:

                      (GETNGLYPHS)GetProcAddress(LoadLibrary("gdi32.dll"), "GetGlyphIndicesA");

                      can cause problem if unicode build.

                      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