GetThreadCallStack (Windows CE 5.0)

Send Feedback

This function retrieves the call stack of an arbitrary thread in the system.

ULONGGetThreadCallStack( HANDLE hThrd,ULONG dwMaxFrames,LPVOID lpFrames[],DWORD dwFlags,DWORD dwSkip);

Parameters

  • hThrd
    [in] Handle to the thread whose call stack is to be retrieved.

  • dwMaxFrames
    [in] Maximum number of frames to be retrieved.

  • lpFrames
    [in] Array of CallSnapshot or CallSnapshotEx structures to receive the stack frames.

  • dwFlags
    [in] Bit flag to indicate what operation is to be performed.

    The following table shows the values for this parameter. These values can be used together in any combination.

    Value Description
    STACKSNAP_FAIL_IF_INCOMPLETE Indicates that the function will fail if dwMaxFrames is less than the number of actual frames.
    STACKSNAP_EXTENDED_INFO Allow the function to return additional stack information such as the frame pointer, current process, and function parameters.

    See the Remarks section for more information about this flag.

    STACKSNAP_INPROC_ONLY Causes the function to return only the stack frames that are within the thread's owner process. It does not include stack frames that are outside the thread's owner process.
    STACKSNAP_RETURN_FRAMES_ON_ERROR Returns the number of frames found even if an error occurs. The SetLastError function will be set.

    If this flag is on, the last error will always be set even when there is no error. Normally, the function does not set the last error when no error occurs.

  • dwSkip
    [in] Number of frames to be skipped.

Return Values

If successful, this returns the number of frames actually copied into lpFrames array. Otherwise, zero is returned.

To get extended error information, call GetLastError.

Remarks

Keep the following points in mind when using GetThreadCallStack:

  • Untrusted applications can only get the call stack of threads within its own process.

  • The priority of the caller thread of this function might be temporarily boosted to a higher priority than the priority of hThrd. This prevents hThrd from running while looking into its context. Calling this function can have an impact on the real-time behavior for hThrd.

  • The number of frames is dynamic. However, by using dwSkip, you can use the following loop to retrieve the full call stacks of a thread:

    CallSnapshot lpFrames[MAX_FRAMES];
    DWORD dwCnt, dwSkip = 0;
    do {
          dwCnt = GetThreadCallStack (hThread, MAX_FRAMES, lpFrames, 0, dwSkip);
          if (dwCnt) {
             // Process the frames retrieved so far
             MyProcessFrames (dwCnt, lpFrames);
             dwSkip += dwCnt;
          }
       } while (MAX_FRAMES == dwCnt);
    

Keep the following points in mind when passing the STACKSNAP_EXTENDED_INFO flag:

  • If you pass this flag, Windows CE treats the lpFrames passed in as a CallSnapshotEx structure and passes back extended information for each frame, including the frame pointer, current process, four parameters, and return address.
  • If the flag is not passed, Windows CE treats lpFrames as a CallSnapshot structure and passes back only the return addresses.

Requirements

OS Versions: Windows CE 5.0 and later.
Header: Pkfuncs.h.
Link Library: Coredll.lib.

See Also

CallSnapshot | CallSnapshotEx | SetLastError

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.