title: How to fix ERROR_INVALID_ADDRESS (error 487) returned by SymFromAddr
body: <p>I'm tryng to get function name by address.</p>
  
  <p>I'm using VS Community 2019 and my first step is to copy microsoft examples that you can find at:<br/>
  <a href="https://docs.microsoft.com/en-us/windows/desktop/debug/initializing-the-symbol-handler" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/windows/desktop/debug/initializing-the-symbol-handler</a><br/>
  <a href="https://docs.microsoft.com/en-us/windows/desktop/debug/retrieving-symbol-information-by-address" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/windows/desktop/debug/retrieving-symbol-information-by-address</a><br/></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;windows.h&gt;
  #include &lt;dbghelp.h&gt;
  
  #pragma comment(lib, "dbghelp")
  
  int main() {
  
       DWORD64  SOME_ADDRESS = (DWORD64) (main);
  
      // https://docs.microsoft.com/en-us/windows/desktop/debug/initializing-the-symbol-handler
  
      DWORD  error;
      HANDLE hProcess;
  
      SymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS);
  
      hProcess = GetCurrentProcess();
  
      if (!SymInitialize(hProcess, NULL, TRUE))
      {
          // SymInitialize failed
          error = GetLastError();
          printf("SymInitialize returned error : %d\n", error);
          return FALSE;
      }
  
      // https://docs.microsoft.com/en-us/windows/desktop/debug/retrieving-symbol-information-by-address
  
      DWORD64  dwDisplacement = 0;
      DWORD64  dwAddress = SOME_ADDRESS;
  
      char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)];
      PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;
  
      pSymbol-&gt;SizeOfStruct = sizeof(SYMBOL_INFO);
      pSymbol-&gt;MaxNameLen = MAX_SYM_NAME;
  
      if (SymFromAddr(hProcess, dwAddress, &amp;dwDisplacement, pSymbol))
      {
          // SymFromAddr returned success
      }
      else
      {
          // SymFromAddr failed
          DWORD error = GetLastError();
          printf("SymFromAddr returned error : %d\n", error);
      }
  
  }
  </code></pre>
  
  <p>But this code print always "SymFromAddr returned error : 487"...<br/>
  I think I'm doing something wrong.<br/>
  Can you help?<br/></p>
  
  <p>Thanks,<br/>
  Alberto<br/></p>