tags:

views:

1046

answers:

3

In Visual C++ , when I build a dll , the output files are .dll and .lib.

Is the name of the dll built into the .lib file .

The reasson I ask this question is : When I built my exe by importing this dll and run the exe , the exe tries to locate the dll to load it in the process address space .

As we just specify the library name (.lib file) in the project properties , how does the exe get to know the name of the dll .

Note : I dumpbin libary file (.lib) and saw that it does not contain the name of the dll .

+7  A: 

The LIB file is turned into an import table in the EXE. This does contain the name of the DLL.

You can see this if you run dumpbin /all MyDLL.lib. Note that dumpbin MyDll.lib by itself doesn't show anything useful: you should use /all.

This shows all of the sections defined in the .LIB file. You can ignore any .debug sections, because they wouldn't be present in a Release build. In the .LIB file, there are a collection of .idata sections. In the DLL project that I just built, the LIB file contains a .idata$4 section which defines the symbols to be put in the EXE's import table, including the DLL name:

Archive member name at 83E: MyDll.dll/      
497C3B9F time/date Sun Jan 25 10:14:55 2009
         uid
         gid
       0 mode
      2E size
correct header end

  Version      : 0
  Machine      : 14C (x86)
  TimeDateStamp: 497C3B9F Sun Jan 25 10:14:55 2009
  SizeOfData   : 0000001A
  DLL name     : MyDll.dll
  Symbol name  : ?fnMyDll@@YAHXZ (int __cdecl fnMyDll(void))
  Type         : code
  Name type    : name
  Hint         : 2
  Name         : ?fnMyDll@@YAHXZ
Roger Lipscombe
yeah the exe's import section contains the name of the dll . But it get to know the name from the library as you say . So , do you mean the library contains the name . If yes , why dont I see that when I dumpbin the library .
...because you're not running DUMPBIN correctly? Pass the /ALL switch, and then you should see output similar to what I included.
Roger Lipscombe
Thanks . I get the concept now .
A: 

Yes, the lib contains the name of the DLL.

Functionally, the import library implements the LoadLibrary and GetProcAdress calls, and makes the exported functions available as if they were linked statically.

The search path is the same as documented for LoadLibrary, the name is fixed, though.

peterchen
A: 

Can the header of the stub library be modified? For example can : DLL name : MyDll.dll be changed to : DLL name : MyNewDll.dll

AceAmit
Don't use the "answer" form to ask questions.
Philipp