SwitchStackTo

3.0

  void SwitchStackTo(uStackSegment, uStackPointer, uStackTop)    
  UINT uStackSegment; /* new stack data segment */
  UINT uStackPointer; /* offset of beginning of stack */
  UINT uStackTop; /* offset of top of stack */

The SwitchStackTo function changes the stack of the current task to the specified data segment.

Parameters

uStackSegment

Specifies the data segment to contain the stack.

uStackPointer

Specifies the offset to the beginning of the stack in the data segment.

uStackTop

Specifies the offset to the top of the stack from the beginning of the stack.

Return Value

This function does not return a value.

Comments

Dynamic-link libraries (DLLs) do not have private stacks; instead, a DLL uses the stack of the task that calls the library. As a result, a DLL function fails if it treats the contents of the data-segment (DS) and stack-segment (SS) registers as equal. A task can call SwitchStackTo before calling a function in a DLL that treats the SS and DS registers as equal. When the DLL function returns, the task must then call the SwitchStackBack function to redirect its stack to its own data segment.

A DLL can also call SwitchStackTo before calling a function that assumes SS and DS to be equal and then call SwitchStackBack before returning to the task that called the DLL function.

Calls to SwitchStackTo and SwitchStackBack cannot be nested. That is, after calling SwitchStackTo, an application must call SwitchStackBack before calling SwitchStackTo again.

See Also

SwitchStackBack