title: Find the name of the Imported DLLs using PE Headers
body: <p>A Few days back I have started with Windows System Programming using c++. Hence, thought of building a utility to grab the PE Headers of an exe file.
  And now I am stuck with the <em>Image_Import_descriptor</em> structure.</p>
  <p>What I want is to get the names of the DLL files(modules) imported by the exe. And below is the code I am using to get those names:</p>
  <pre><code>        DWORD Image_Import_Descriptor_addr = (DWORD)ntHeader + (DWORD)sizeof(ntHeader-&gt;FileHeader) + (DWORD)ntHeader-&gt;FileHeader.SizeOfOptionalHeader + (DWORD)ntHeader-&gt;OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size;
          importImageDescriptor = (PIMAGE_IMPORT_DESCRIPTOR)Image_Import_Descriptor_addr;
  </code></pre>
  <p>To get the RVA of the <em>name</em>:</p>
  <pre><code>        DWORD name = importImageDescriptor-&gt;Name;
          printf(&quot;\n\n\n\t\t (((Module Name)): %X&quot;, name);
  </code></pre>
  <p>Gives an output:
  <strong>4778B00</strong></p>
  <p>Hope untill now everything was fine technically.</p>
  <p>However, my motive is to print the DLL names(like kernel32.dll).
  Can anyone help me out how to get the names of the DLL ?</p>
  <p>My workarounds:</p>
  <pre><code>            LPCSTR snames = (LPCSTR)name;          
              printf(&quot;\n\n\n\t\t (((Module Name)): %s&quot;, *snames);
  </code></pre>
  <p>But this is giving me an error: <em>Access Violation</em></p>
  <p>I am getting confused with the pointers and Datatype conversions. A help is much appreciated.</p>