NotifyRouteChange function (iphlpapi.h)

The NotifyRouteChange function causes a notification to be sent to the caller whenever a change occurs in the IPv4 routing table.


  [out] PHANDLE      Handle,
  [in]  LPOVERLAPPED overlapped


[out] Handle

A pointer to a HANDLE variable that receives a handle to use in asynchronous notification.

[in] overlapped

A pointer to an OVERLAPPED structure that notifies the caller of any changes in the routing table.

Return value

If the function succeeds, the return value is NO_ERROR if the caller specifies NULL for the Handle and overlapped parameters. If the caller specifies non-NULL parameters, the return value for success is ERROR_IO_PENDING. If the function fails, use FormatMessage to obtain the message string for the returned error.

Return code Description
The context is being deregistered, so the call was canceled immediately.
An invalid parameter was passed. This error is returned if the both the Handle and overlapped parameters are not NULL, but the memory specified by the input parameters cannot be written by the calling process. This error is also returned if the client already has made a change notification request, so this duplicate request will fail.
There was insufficient memory available to complete the operation.
This error is returned on versions of Windows where this function is not supported such as Windows 98/95 and Windows NT 4.0.


NotifyRouteChange function may be called in two ways:

  • Synchronous method
  • Asynchronous method

If the caller specifies NULL for the Handle and overlapped parameters, the call to NotifyRouteChange is synchronous and will block until an IPv4 routing table change occurs. In this case if a change occurs, the NotifyRouteChange function completes to indicate that a change has occurred.

If the NotifyRouteChange function is called synchronously, a notification will be sent on the next IPv4 routing change until the application terminates.

If the caller specifies a handle variable and an OVERLAPPED structure, the caller can use the returned handle with the OVERLAPPED structure to receive asynchronous notification of IPv4 routing table changes. See the following topics for information about using the handle and OVERLAPPED structure to receive notifications:

If the application receives a notification and requires notification for the next change, then the NotifyRouteChange function must be called again.

The CancelIPChangeNotify function cancels notification of IP address and route changes previously requested with successful calls to the NotifyAddrChange or NotifyRouteChange functions.

Once an application has been notified of a change, the application can then call the GetIpForwardTable or GetIpForwardTable2 function to retrieve the IPv4 routing table to determine what has changed. If the application is notified and requires notification for the next change, then the NotifyRouteChange function must be called again.

If the NotifyRouteChange function is called asynchronously, a notification will be sent on the next IPv4 route change until either the application cancels the notification by calling the CancelIPChangeNotify function or the application terminates. If the application terminates, the system will automatically cancel the registration for the notification. It is still recommended that an application explicitly cancel any notification before it terminates.

Any registration for a notification does not persist across a system shut down or reboot.

On Windows Vista and later, the NotifyRouteChange2 function can be used to register to be notified for changes to the IPv6 routing table on the local computer.


The following example waits for a change to occur in the IP routing table.

#include <winsock2.h>
#include <iphlpapi.h>
#include <stdio.h>
#include <windows.h>

#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "ws2_32.lib")

void main()
  OVERLAPPED overlap;
  DWORD ret;
  HANDLE hand = NULL;
  overlap.hEvent = WSACreateEvent();

  ret = NotifyRouteChange(&hand, &overlap);

  if (ret != NO_ERROR)
    if (WSAGetLastError() != WSA_IO_PENDING)
      printf("NotifyRouteChange error...%d\n", WSAGetLastError());            

  if ( WaitForSingleObject(overlap.hEvent, INFINITE) == WAIT_OBJECT_0 )
    printf("Routing table changed..\n");


Requirement Value
Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header iphlpapi.h
Library Iphlpapi.lib
DLL Iphlpapi.dll

See also





IP Helper Function Reference