title: How to properly implement CaptureStackBackTrace on windows
body: <p>There is this way of retrieving a stack trace on MS windows: <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb204633%28v=vs.85%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/windows/desktop/bb204633%28v=vs.85%29.aspx</a></p>
  
  <p>I tried to implement this in my application (which doesn't run on Windows only) using this:</p>
  
  <pre><code>#elif defined HUGGLE_WIN
      result = "";
      unsigned int   i;
      void          *stack[HUGGLE_STACK];
      unsigned short frames;
      SYMBOL_INFO   *symbol;
      HANDLE         process;
      process = GetCurrentProcess();
      SymInitialize( process, NULL, TRUE );
      frames               = CaptureStackBackTrace( 0, HUGGLE_STACK, stack, NULL );
      symbol               = ( SYMBOL_INFO * )calloc( sizeof( SYMBOL_INFO ) + 256 * sizeof( char ), 1 );
      symbol-&gt;MaxNameLen   = 255;
      symbol-&gt;SizeOfStruct = sizeof( SYMBOL_INFO );
      for( i = 0; i &lt; frames; i++ )
      {
          SymFromAddr( process, ( DWORD64 )( stack[ i ] ), 0, symbol );
          QString symbol_name = "unknown symbol";
          if (!QString(symbol-&gt;Name).isEmpty())
          symbol_name = QString(symbol-&gt;Name);
          result += QString(QString::number(frames - i - 1) + QString(" ") + symbol_name + QString(" 0x") +
                            QString::number(symbol-&gt;Address, 16) + QString("\n"));
      }
      free( symbol );
  #else
  </code></pre>
  
  <p>however, despite this "works" I get symbol names for 3rd libraries only, and not for my own functions that are in my application, despite I see frames for them. These have empty symbols and addr 0x0, see example output:</p>
  
  <pre><code>34 unknown symbol 0x0
  33 unknown symbol 0x0
  32 unknown symbol 0x0
  31 unknown symbol 0x0
  30 unknown symbol 0x0
  29 ZN11QMetaObject8activateEP7QObjectiiPPv 0x6b954a50
  28 ZN11QMetaObject8activateEP7QObjectPKS_iPPv 0x6b95495e
  27 ZN6QTimer7timeoutENS_14QPrivateSignalE 0x6b9ad018
  26 ZN6QTimer10timerEventEP11QTimerEvent 0x6b9588ea
  25 ZN7QObject5eventEP6QEvent 0x6b94f3fc
  24 ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent 0x2259ddfe
  23 ZN12QApplication6notifyEP7QObjectP6QEvent 0x2259b4a4
  22 ZN12QApplication6notifyEP7QObjectP6QEvent 0x2259b4a4
  21 ZN16QCoreApplication14notifyInternalEP7QObjectP6QEvent 0x6b929e6c
  20 ZN16QCoreApplication9sendEventEP7QObjectP6QEvent 0x6b9cf5ac
  19 ZN28QEventDispatcherWin32Private14sendTimerEventEi 0x6b97904c
  18 ZN28QEventDispatcherWin32Private21activateEventNotifierEP17QWinEventNotifier 0x6b978260
  17 gapfnScSendMessage 0x76305fc8
  16 GetThreadDesktop 0x76306c63
  15 CharPrevW 0x7630768c
  14 DispatchMessageW 0x7630787b
  13 ZN21QEventDispatcherWin3213processEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE 0x6b979682
  12 ZN21QEventDispatcherWin3213processEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE 0x6b979682
  11 ZN10QEventLoop13processEventsE6QFlagsINS_17ProcessEventsFlagEE 0x6b927f3c
  10 ZN10QEventLoop4execE6QFlagsINS_17ProcessEventsFlagEE 0x6b9280ec
  9 ZN16QCoreApplication4execEv 0x6b92a3dc
  8 ZN15QGuiApplication4execEv 0x4606506
  7 ZN12QApplication4execEv 0x2259b34a
  6 ZN12QApplication4execEv 0x2259b34a
  5 ZN12QApplication4execEv 0x2259b34a
  4 ZN12QApplication4execEv 0x2259b34a
  3 ZN12QApplication4execEv 0x2259b34a
  2 BaseThreadInitThunk 0x76633378
  1 RtlInitializeExceptionChain 0x778dbecf
  0 RtlInitializeExceptionChain 0x778dbecf
  </code></pre>
  
  <p>these 5 unknowns are my function from my program. Why I don't see them?</p>