title: How does the Import Library work? Details?
body: <p>I know this may seem quite basic to geeks. But I want to make it crystal clear.</p>
  
  <p>When I want to use a Win32 DLL, usually I just call the APIs like LoadLibrary() and GetProcAdderss(). But recently, I am developing with DirectX9, and I need to add <em>d3d9.lib</em>, <em>d3dx9.lib</em>, etc files.</p>
  
  <p>I have heard enough that LIB is for static linking and DLL is for dynamic linking.</p>
  
  <p>So my current understanding is that LIB contains the implementation of the methods and is statically linked at link time as part of the final EXE file. While DLL is dynamic loaded at runtime and is not part of the final EXE file.</p>
  
  <p>But sometimes, there're some LIB files <strong>coming with</strong> the DLL files, so:</p>
  
  <ul>
  <li>What are these LIB files for?</li>
  <li>How do they achieve what they are meant for?</li>
  <li>Is there any tools that can let me inspect the internals of these LIB files?</li>
  </ul>
  
  <h2>Update 1</h2>
  
  <p>After checking wikipedia, I remember that these LIB files are called <a href="http://en.wikipedia.org/wiki/Dynamic-link_library#Import_libraries" rel="noreferrer">import library</a>.
  But I am wondering how it works with my main application and the DLLs to be dynamically loaded.</p>
  
  <h2>Update 2</h2>
  
  <p>Just as RBerteig said, there're some stub code in the LIB files born with the DLLs. So the calling sequence should be like this:</p>
  
  <p>My main application  --> stub in the LIB  --> real target DLL</p>
  
  <p>So what information should be contained in these LIBs? I could think of the following:</p>
  
  <ul>
  <li>The LIB file should contain the fullpath of the corresponding DLL; So the DLL could be loaded by the runtime.</li>
  <li>The relative address (or file offset?) of each DLL export method's entry point should be encoded in the stub; So correct jumps/method calls could be made.</li>
  </ul>
  
  <p>Am I right on this? Is there something more?</p>
  
  <p><strong>BTW: Is there any tool that can inspect an import library? If I can see it, there'll be no more doubts.</strong></p>