views:

280

answers:

2

I'm new to Windows concepts. I'm trying to develop a DLL that also dynamically links against other DLL's. I'm using Visual Studio 2010. At linking time Visual studio tells me it's trying to link against a bunch of .lib files. I don't think Visual Studio should attempt to read any .LIB files if I want my code to perform dynamic linking is that correct? Or do I not understand the use of .LIB files enough?

thank you

A: 

As I recall, Visual Studio's compiler resolves .DLL files by linking against stub .LIB files.

Check, one of them should be kernel32.lib.

Joshua
Yes, it checks against kernel32.lib and various others. however I have external dependency libraries that I am compiling/linking against. It wants the .lib files for those too. I DO have the .lib files for those but I don't want it to perform static linking with me thinking it's performing dynamic linking... I'm sure there's a flag/setting that I can check to make sure that my project is __ONLY__ performing dynamic linking... do you know what that setting/flag is?
alessandro ferrucci
The kind of linking is defined by the kind of .lib file you link against. Is that the static .lib or the dynamic lib? It's easy to tell, the static .lib is very small compared to the .dll.
Joshua
+1  A: 

How I understand, you are a little confused, because you want to use DLLs instead of LIBs.

The trick is that Kernel32.Lib, User32.Lib, AdvAPI32.Lib and so on has no implementation of the function which you use. Moreover if you use functions like CreateFileW or MessageBoxW in your program the references to the function will be unresolved after the compilation. So without having LIBs the unresolved references will stay also in the EXE. That will be bad of cause. To be executable the EXE must have resolved all external references and moreover know exactly which functions should be found in which DLLs. So named import library help to solve the problem. The import library Kernel32.Lib for example has information about CreateFileW function and User32.Lib has information about MessageBoxW. If you use a list of import libraries like Kernel32.Lib, User32.Lib, AdvAPI32.Lib your EXE resolves all referenced and includes the exact list of DLLs which it need and the list of functions used in the corresponding DLL in a special Import table (see http://en.wikipedia.org/wiki/Portable_Executable#Import_Table, http://msdn.microsoft.com/en-us/library/ms809762.aspx and http://www.microsoft.com/whdc/system/platform/firmware/pecoff.mspx). So If one starts your EXE the operation system loads the DLL in the address space of the process and resolves till the end all references up to the addresses of all functions used.

Typically import libraries will be created by linker (link.exe) when one compile a DLL. It is also possible to create an import library which corresponds to the DLL with respect of lib.exe utility. (see http://msdn.microsoft.com/en-us/library/0b9xe492.aspx)

Oleg