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. Calling exported functions from a static DLL

Calling exported functions from a static DLL

Scheduled Pinned Locked Moved C / C++ / MFC
json
10 Posts 5 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.
  • Y Offline
    Y Offline
    Yashusid
    wrote on last edited by
    #1

    I have a x.lib and x.dll. its a static dll. Now i am using functions exported in this dll by loading this dll and calling functions thro GetProcAddress API. Now i don't want to load dll instead i want to use x.lib, Please let me know how i can call those functions by using x.lib

    M C T 3 Replies Last reply
    0
    • Y Yashusid

      I have a x.lib and x.dll. its a static dll. Now i am using functions exported in this dll by loading this dll and calling functions thro GetProcAddress API. Now i don't want to load dll instead i want to use x.lib, Please let me know how i can call those functions by using x.lib

      M Offline
      M Offline
      Matthew Faithfull
      wrote on last edited by
      #2

      I think you may have your terms a little confused so I'm not exactly sure what you want. There are basically three scenarios: 1. x.dll is a Dll and is used by calling LoadLibrary and GetProcAddress 2. x.dll is a Dll, x.lib is its import library. x.lib is linked into application y which is then implicitly linked to x.dll. x.dll get loaded by y.exe during the bootstrap phase and functions in x.dll can be called directly from y.exe code, No LoadLibrary, no GetProcAddress 3. x.lib is a static library which is linked as part of y.exe. The two are merged at compile time to produce y.exe. That's it, the functions all act as if they are in the same module because they are, no LoadLibrary, no GetProcAddress Generally you'd use: 1 if the code in x.dll is shared and only used occassionaly by y.exe 2 if the code in x.dll is shared and used all the time by y.exe 3 if x.lib is really just a subdivision of y.exe and is not used by other applications. I hope this helps. :)

      "The secret of happiness is freedom, and the secret of freedom, courage." Thucydides (B.C. 460-400)

      Y 1 Reply Last reply
      0
      • Y Yashusid

        I have a x.lib and x.dll. its a static dll. Now i am using functions exported in this dll by loading this dll and calling functions thro GetProcAddress API. Now i don't want to load dll instead i want to use x.lib, Please let me know how i can call those functions by using x.lib

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

        To complete what Matthew just said, if you are in scenario 2 (x.lib is the import libary of the dll), then you can't statically link to it to access the functions. The lib doesn't contain the code for the functions but only information about how to load the dll.

        Cédric Moonen Software developer
        Charting control [v1.4] OpenGL game tutorial in C++

        1 Reply Last reply
        0
        • Y Yashusid

          I have a x.lib and x.dll. its a static dll. Now i am using functions exported in this dll by loading this dll and calling functions thro GetProcAddress API. Now i don't want to load dll instead i want to use x.lib, Please let me know how i can call those functions by using x.lib

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #4

          Yashusid wrote:

          its a static dll

          impossible. DLL means **D**YNAMIC **L**ink **L**ibrary

          [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

          1 Reply Last reply
          0
          • M Matthew Faithfull

            I think you may have your terms a little confused so I'm not exactly sure what you want. There are basically three scenarios: 1. x.dll is a Dll and is used by calling LoadLibrary and GetProcAddress 2. x.dll is a Dll, x.lib is its import library. x.lib is linked into application y which is then implicitly linked to x.dll. x.dll get loaded by y.exe during the bootstrap phase and functions in x.dll can be called directly from y.exe code, No LoadLibrary, no GetProcAddress 3. x.lib is a static library which is linked as part of y.exe. The two are merged at compile time to produce y.exe. That's it, the functions all act as if they are in the same module because they are, no LoadLibrary, no GetProcAddress Generally you'd use: 1 if the code in x.dll is shared and only used occassionaly by y.exe 2 if the code in x.dll is shared and used all the time by y.exe 3 if x.lib is really just a subdivision of y.exe and is not used by other applications. I hope this helps. :)

            "The secret of happiness is freedom, and the secret of freedom, courage." Thucydides (B.C. 460-400)

            Y Offline
            Y Offline
            Yashusid
            wrote on last edited by
            #5

            I think the 2) option does work for me. i will clarify my doubt again, please confirm whether 2) option works or not. I have some code x when built it gives x.dll and creates x.lib. Currently i m loading x.dll by LoadLibray and calling function thro' GetProcAddress. Now i want to call those same functions but want to avoid using LoadLibray and GetProcAddress. How it could be done ?? Thanks a lot !!!!

            L M 2 Replies Last reply
            0
            • Y Yashusid

              I think the 2) option does work for me. i will clarify my doubt again, please confirm whether 2) option works or not. I have some code x when built it gives x.dll and creates x.lib. Currently i m loading x.dll by LoadLibray and calling function thro' GetProcAddress. Now i want to call those same functions but want to avoid using LoadLibray and GetProcAddress. How it could be done ?? Thanks a lot !!!!

              L Offline
              L Offline
              led mike
              wrote on last edited by
              #6

              Yashusid wrote:

              How it could be done ??

              You link to the .lib file.

              led mike

              1 Reply Last reply
              0
              • Y Yashusid

                I think the 2) option does work for me. i will clarify my doubt again, please confirm whether 2) option works or not. I have some code x when built it gives x.dll and creates x.lib. Currently i m loading x.dll by LoadLibray and calling function thro' GetProcAddress. Now i want to call those same functions but want to avoid using LoadLibray and GetProcAddress. How it could be done ?? Thanks a lot !!!!

                M Offline
                M Offline
                Matthew Faithfull
                wrote on last edited by
                #7

                OK, you need to add x.lib to the Input files list for the Linker. I'd need to know what development environment you're using to be much more specific. Your exe source files which call functions in the dll will need to include the relevant header file from the dll source e.g. //exe_main.cpp #include "mydll.h" int iResult = MyDllFunction( "SomeString" );

                "The secret of happiness is freedom, and the secret of freedom, courage." Thucydides (B.C. 460-400)

                Y 1 Reply Last reply
                0
                • M Matthew Faithfull

                  OK, you need to add x.lib to the Input files list for the Linker. I'd need to know what development environment you're using to be much more specific. Your exe source files which call functions in the dll will need to include the relevant header file from the dll source e.g. //exe_main.cpp #include "mydll.h" int iResult = MyDllFunction( "SomeString" );

                  "The secret of happiness is freedom, and the secret of freedom, courage." Thucydides (B.C. 460-400)

                  Y Offline
                  Y Offline
                  Yashusid
                  wrote on last edited by
                  #8

                  I am using VS2005. Thanks a lot Matthew

                  M 1 Reply Last reply
                  0
                  • Y Yashusid

                    I am using VS2005. Thanks a lot Matthew

                    M Offline
                    M Offline
                    Matthew Faithfull
                    wrote on last edited by
                    #9

                    In which case, as you probably know, you'll find the Linker Input files by right clicking on your project (not the solution), selecting Properties and then choosing Configuration Properties\Linker\Input in the properties dialog. You can add the name of your x.lib file to the 'Additional Dependencies'

                    "The secret of happiness is freedom, and the secret of freedom, courage." Thucydides (B.C. 460-400)

                    Y 1 Reply Last reply
                    0
                    • M Matthew Faithfull

                      In which case, as you probably know, you'll find the Linker Input files by right clicking on your project (not the solution), selecting Properties and then choosing Configuration Properties\Linker\Input in the properties dialog. You can add the name of your x.lib file to the 'Additional Dependencies'

                      "The secret of happiness is freedom, and the secret of freedom, courage." Thucydides (B.C. 460-400)

                      Y Offline
                      Y Offline
                      Yashusid
                      wrote on last edited by
                      #10

                      Thanks ... I have included this x.lib Is it possible to call those function from the x.lib in y.exe application directly?? like if a function add(int,int) is implemented in x.lib ...can i call in y.exe as int n=add(2,3) ??

                      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