Share via


RegistryTestExchangeDWORD (Windows Embedded CE 6.0)

1/6/2010

This function atomically sets a value based on a condition.

Syntax

HRESULT WINAPI RegistryTestExchangeDWORD( 
  HKEY hKey,
  LPCTSTR pszSubKey,
  LPCTSTR pszValueName,
  DWORD dwOldValue,
  DWORD dwNewValue 
);

Parameters

  • hKey
    [in] Handle to the open key or a predefined root value.
  • pszSubKey
    [in] Key where the value is stored. If this value is NULL, then pszValueName is assumed to be under hkey.
  • pszValueName
    [in] Named value to set. If this value is NULL, the function sets the default value.
  • dwOldValue
    [in] Value to check against.
  • dwNewValue
    [in] Value to set conditionally.

Return Value

The following table shows the return values for this function.

Value Description

S_OK

Value is changed to dwNewValue.

ERROR_NO_MATCH

Value is not changed to dwNewValue because the current value in the registry is not equal to dwOldValue.

E_INVALIDARG

Invalid hkey or pszValueName.

E_DATATYPE_MISMATCH

Value is not type REG_DWORD.

An error value returned by RegOpenKey or RegQueryValueEx.

Error value wrapped as a FACILITY_WIN32 HRESULT.

Remarks

Success indicates that the old value is replaced by the new value. Failure does not cause any change.

RegistryTestExchangeDWORD is an interlocked function. It behaves similarly to the Microsoft Win32 InterlockedTestExchange funtion. It checks to see if the DWORD value associated with pszValueName is equal to dwOldValue. If the values are equal, the function sets the target to dwNewValue; otherwise, the function fails.

If the client might be calling RegistryTestExchangeDWORD multiple times, it should cache a handle to the key using RegOpenKeyEx and pass the handle instead of passing a string value. Every time RegistryTestExchangeDWORD is called with a string value for the key, the RegOpenKeyEx and RegCloseKey functions are called, so passing a handle instead of a string value can avert a potential performance problem over mutltiple calls.

Requirements

Header regext.h
Library aygshell.lib
Windows Embedded CE Windows Embedded CE 6.0 and later

See Also

Reference

State and Notifications Broker Functions
State and Notifications Broker Reference

Other Resources

State and Notifications Broker