MSDN Library
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.


Windows Mobile 6.5
A version of this page is also available for

This function is an interlocked function that performs a conditional setting of a variable.

LONG WINAPI InterlockedTestExchange(
  LPLONG Target,
  LONG OldValue,
  LONG NewValue


[in] Pointer to the LONG variable to check and set.


[in] Value to check against.


[in] Value to set to conditionally.

The original value pointed to by Target at the time of the call indicates success.

The InterlockedTestExchange function is an interlocked function. In other words, it can be considered atomic. It checks to see if the value pointed to by Target is equal to OldValue. If so, it sets Target to NewValue. Because InterlockedTestExchange returns the old value pointed to by Target, if the return value is OldValue, then InterlockedTestExchange succeeded and set the value pointed to by Target to NewValue. Otherwise, it failed.

Windows Embedded CEWindows CE 1.0 and later
Windows MobileWindows Mobile Version 5.0 and later

Community Additions

© 2015 Microsoft