Microsoft Docs

DeleteIpForwardEntry function

Namespace: IP Helper API (iphlpapi)

Header: IpHlpApi.h

Library: Iphlpapi.lib

Syntax

DWORD DeleteIpForwardEntry(
    PMIB_IPFORWARDROW pRouteInfo
);

Parameters

ParameterTypeDescription
pRouteInfo PMIB_IPFORWARDROW Pointer to a MIB_IPFORWARDROW structure that specifies the route to delete.

Return Value

If the function succeeds, the return value is NO_ERROR. If it fails, the return value is a Windows error code. Common errors include:

Remarks

Example (C++)

#include <windows.h>
#include <iphlpapi.h>
#include <iostream>

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

int main() {
    MIB_IPFORWARDROW row = {0};
    row.dwForwardDest = inet_addr("192.168.1.0");
    row.dwForwardMask = inet_addr("255.255.255.0");
    row.dwForwardNextHop = inet_addr("192.168.1.1");
    row.dwForwardIfIndex = 2; // interface index
    row.dwForwardType = MIB_IPROUTE_TYPE_INDIRECT;
    row.dwForwardProto = MIB_IPPROTO_NETMGMT;

    DWORD result = DeleteIpForwardEntry(&row);
    if (result == NO_ERROR) {
        std::cout << "Route deleted successfully." << std::endl;
    } else {
        std::cerr << "Failed to delete route. Error: " << result << std::endl;
    }
    return 0;
}

See Also