SwitchStackTo

Version 3.0

Syntax

void SwitchStackTo(wStackSegment,wStackPointer,wStackTop)

This function changes the stack of the current task to the segment identified by the wStackSegment parameter.

Dynamic-link libraries (DLLs) do not have a stack; instead, a DLL uses the stack of the task which calls the library. As a result, DLL functions that assume that the contents of the code-segment (CS) and stack-segment (SS) registers are the same will fail. The SwitchStackTo function redirects the stack of the task to the data segment of a DLL, permitting the DLL to call these functions. SwitchStackTo copies the arguments on the stack of the task to the new stack location.

Parameter Type/Description  

wStackSegment WORD Specifies the data segment which is to contain the stack.  
wStackPointer WORD Specifies the offset of the beginning of the stack in the data segment.  
wStackTop WORD Specifies the offset of the top of the stack from the beginning of the stack.  

Return Value

None.

Comments

A task can call SwitchStackTo before calling a function in a DLL that assumes the CS and DS registeres are equal. When the DLL function returns, the task must then call SwitchStackBack to redirect its stack to its own data segment.

A DLL can also call SwitchStackTo before calling a routine that assumes CS and DS are 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, a program must call SwitchStackBack before calling SwitchStackTo again.