Using C++ with Visual Studio, I was wondering if there's an API that will print the callstack for me. Preferably, I'd like to print a callstack 5 levels deep. Does windows provide a simple API to allow me to do this?
Asked
Active
Viewed 1.8k times
4 Answers
10
It looks like Microsoft's DbgHelp library can do what you want. Consult the StackWalk64 function's documentation on MSDN for more information. Also, this CodeProject article may be useful.

bcat
- 8,833
- 3
- 35
- 41
5
There is a number of ways to do this.
See How to Log Stack Frames with Windows x64
In my opinion, the simplest and as well the most reliable way is the Win32 API function:
USHORT WINAPI CaptureStackBackTrace(
__in ULONG FramesToSkip,
__in ULONG FramesToCapture,
__out PVOID *BackTrace,
__out_opt PULONG BackTraceHash
);
This FramesToCapture parameter, determines the maximum call stack depth returned.

Community
- 1
- 1

RED SOFT ADAIR
- 12,032
- 10
- 54
- 92
-
This does not generate any symbolic information. What use is a bunch of pointer values? – Tim Cooper Feb 20 '15 at 04:10
-
C/C++ Programs never contain symbolic information by default. See here for ways to add symbols to a stack dump: http://www.drdobbs.com/architecture-and-design/post-mortem-debugging-revisited/227900186 – RED SOFT ADAIR Feb 22 '15 at 20:41