Hi,
I want to Load .dll library on my program. I was using LoadLibrary and GetProcAddress which is tedious work. I saw somewhere Idea of using .lib files but have no clue. I have used google but I got lost. Please help me :(

Codeblocks 8.02
MINGW 3.4.5
Windows Vista

Your program is already using several .lib files from the standard C and C++ libraries. If its a dll that you write and compiled, then most likely your compiler generated a lib file. If its a dll that someone else write/compiled then you might be able to get the *.lib file from whoever wrote it. AFAIK its not possible to generate a lib file from just the DLL.

I have the .lib file, but I'm very ignorant on how to use it!
Can you explain me with little grain of salt how to use it instead of using the tedious GetProcAddress?
Thanks for reply

you use it the same way that you use any other standard library. Take time.h for example. That header file contains function prototypes for functions such as time(). Then all you do is call time(), passing the appropriate parameter. When you compile the program the compiler will link with the standard library that contains the source code for the time function.

You do that too. If you have a header file for that dll then include it in your program. If not, then just add the function prototypes to the top of your program, after all other include statements. Then all you have to do is call the function just like you would have called time() in the above example.

You have to tell your compiler the name of the *.lib file. I don't have Code::Blocks installed so I can't tell you how to do that, but I'm sure it should be fairly easy to find out by browsing around the program's project options.

Thanks for good explanation. I have one more question on this, will the output exe just link to DLL or it will be Huge exe File? I mean using tedious GetProcAddress (Believe me I don't like even to say it) It will Link to DLL and maintain small exe file. Is it so with .lib option?

Do I need to distribute .lib with program?

Thanks

There are two ways to link: 1) static link, which normally does not require the DLL so the code is inside your .exe file, and 2) dynamic link, where the *.lib file only contains enough information for the linker to resolve references, and your program will need access to the DLL at runtime. There advantages and disadvantages to both link types. I normally do the dynamic link to keep the size of the *.exe as small as possible.

BTY: for your compiler you should have a library with *.a extension, not *.lib.

BTY: for your compiler you should have a library with *.a extension, not *.lib.

Not sure, but I thought Windows have .lib .dll and linux .so .a, am I right?

you have a *nix port of g++ compiler. So it uses *.a. Look in your <compiler's install directory>\lib

Thanks alot!
Hope someone using codeblocks will say something, before I close the thread. I'm happy that very soon I will say bye to boring Looong LoadLibrary/GetProcAddress method :)

Instead of waiting for someone to answer you why don't you try browsing around your compiler's IDE options. Look for something like Linker options, and Additional Library Dependencies. It won't be those words but something similar.

In Code::Blocks IDE, select menu item Settings --> Compiler and Debugger. Click the Linker Settings tab. Then click the Add button and enter the name of the library.

Oh I will do a try. I'm now at work (Electronics & Telecommunications Engineer interested in IT). I'm exhausted as far as my head is concerned. That's why I will do it later.

In Code::Blocks IDE, select menu item Settings --> Compiler and Debugger. Click the Linker Settings tab. Then click the Add button and enter the name of the library.

Thanks Sir

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.