title: Why isn't SymGetSymFromAddr64 working? It returns error code 126
body: <p>I am trying to capture a stack trace on exceptions using the following code:</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;process.h&gt;
  #include &lt;iostream&gt;
  #include &lt;Windows.h&gt;
  #include "dbghelp.h"
  
  using namespace std;
  
  #define TRACE_MAX_FUNCTION_NAME_LENGTH 1024
  
  void function2()
  {
      int a = 0;
      int b = 0;
      throw new exception;
  }
  
  void function1()
  {
      int a = 0;
      function2();
  }
  
  void function0()
  {
      function1();
  }
  
  LONG WINAPI FatalExceptionFilter(EXCEPTION_POINTERS* exception, DWORD exceptionCode)
  {
      CONTEXT *context = exception-&gt;ContextRecord;
      HANDLE thread = GetCurrentThread();
      HANDLE process = GetCurrentProcess();
      STACKFRAME64 frame;
      DWORD image;
  #ifdef _M_IX86
      image = IMAGE_FILE_MACHINE_I386;
      frame.AddrPC.Offset = context-&gt;Eip;
      frame.AddrPC.Mode = AddrModeFlat;
      frame.AddrFrame.Offset = context-&gt;Ebp;
      frame.AddrFrame.Mode = AddrModeFlat;
      frame.AddrStack.Offset = context-&gt;Esp;
      frame.AddrStack.Mode = AddrModeFlat;
  #elif _M_X64
      image = IMAGE_FILE_MACHINE_AMD64;
      frame.AddrPC.Offset = context-&gt;Rip;
      frame.AddrPC.Mode = AddrModeFlat;
      frame.AddrFrame.Offset = context-&gt;Rsp;
      frame.AddrFrame.Mode = AddrModeFlat;
      frame.AddrStack.Offset = context-&gt;Rsp;
      frame.AddrStack.Mode = AddrModeFlat;
  #elif _M_IA64
      image = IMAGE_FILE_MACHINE_IA64;
      frame.AddrPC.Offset = context-&gt;StIIP;
      frame.AddrPC.Mode = AddrModeFlat;
      frame.AddrFrame.Offset = context-&gt;IntSp;
      frame.AddrFrame.Mode = AddrModeFlat;
      frame.AddrBStore.Offset = context-&gt;RsBSP;
      frame.AddrBStore.Mode = AddrModeFlat;
      frame.AddrStack.Offset = context-&gt;IntSp;
      frame.AddrStack.Mode = AddrModeFlat;
  #else
  #error "This platform is not supported."
  #endif
      IMAGEHLP_SYMBOL64 *symbol = (IMAGEHLP_SYMBOL64 *)malloc(sizeof(IMAGEHLP_SYMBOL64)+(TRACE_MAX_FUNCTION_NAME_LENGTH - 1) * sizeof(TCHAR));
      symbol-&gt;MaxNameLength = TRACE_MAX_FUNCTION_NAME_LENGTH;
      symbol-&gt;SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64); 
      IMAGEHLP_LINE64 *line = (IMAGEHLP_LINE64 *)malloc(sizeof(IMAGEHLP_LINE64));
      line-&gt;SizeOfStruct = sizeof(IMAGEHLP_LINE64);
      while (StackWalk64(image, process, thread, &amp;frame, context, NULL, NULL, NULL, NULL))
      {
          DWORD64 displacement64;
          if (SymGetSymFromAddr64(process, frame.AddrPC.Offset, &amp;displacement64, symbol))
          {
              DWORD displacement;
              if (SymGetLineFromAddr64(process, frame.AddrPC.Offset, &amp;displacement, line))
              {
                  printf("\tat %s in %s: line: %lu: address: 0x%0X\n", symbol-&gt;Name, line-&gt;FileName, line-&gt;LineNumber, symbol-&gt;Address);
              }
              else
              {
                  printf("Error from SymGetLineFromAddr64: %lu.\n", GetLastError());
              }
          }
          else
          {
              printf("Error from SymGetSymFromAddr64: %lu.\n", GetLastError());
          }
      }
      return EXCEPTION_EXECUTE_HANDLER;
  }
  
  static void threadFunction(void *param)
  {
      __try
      {
          function0();
      }
      __except (FatalExceptionFilter(GetExceptionInformation(), GetExceptionCode()))
      { }
  }
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      _beginthread(threadFunction, 0, NULL);
      printf("Press any key to exit.\n");
      cin.get();
      return 0;
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Press any key to exit.
  Error from SymGetSymFromAddr64: 126.
  Error from SymGetSymFromAddr64: 126.
  Error from SymGetSymFromAddr64: 126.
  Error from SymGetSymFromAddr64: 126.
  Error from SymGetSymFromAddr64: 126.
  Error from SymGetSymFromAddr64: 126.
  Error from SymGetSymFromAddr64: 126.
  Error from SymGetSymFromAddr64: 126.
  Error from SymGetSymFromAddr64: 126.
  Error from SymGetSymFromAddr64: 126.
  </code></pre>
  
  <p>I'm a little baffled as to why SymGetSymFromAddr64 is failing. Any ideas?</p>
  
  <p>126 should be a missing dependency, but I have the DLL in the appropriate folder...I am running this all in a MSVC++ console application on a Windows 8.1 x64 PC using a Win32 platform Debug build. So what could be causing the problem?</p>
  
  <p><strong>Update</strong>: Dependency walker is telling me it can't find API-MS-WIN-SERVICE-PRIVATE-L1-1-1.DLL</p>