怎么通过编程修改本机ip地址和子网掩码及网关地址

如何通过编程修改本机ip地址和子网掩码及网关地址
如题,如何通过编程修改本机ip地址和子网掩码及网关地址,比如开一个对话框,
输入ip地址,子网掩码,网关地址,相应的系统地址随之改变??
万分着急,请各位前辈指教!!

------解决方案--------------------
/******************************************************************************* This is a part of the Microsoft Source Code Samples.
* Copyright 1996 - 1998 Microsoft Corporation.
* All rights reserved.
* This source code is only intended as a supplement to
* Microsoft Development Tools and/or WinHelp documentation.
* See these sources for detailed information regarding the
* Microsoft samples programs.
\******************************************************************************/

/*
Module Name:

ipchange.cpp

Abstract:

This module illustrates how to programmatically change an IP address for
a specific network adapter on your machine. This program also demonstrates how
to retrieve existing network adapter IP configuration information.

IP configurations can be changed for a specific network adapter by using the
AddIpAddress() and DeleteIpAddress() Ip Helper APIs. These APIs require you to
understand adapter index numbers and IP context numbers. In Windows, every network
adapter has a unique index ID and every IP address has a unique context ID.
Adapter index IDs and IP context numbers can be retrieved using the GetAdaptersInfo()
IP Helper API. This program features a list option that displays current network
adapter configuration information by showing all adapters index numbers and IP
address context numbers associated with their corresponding network adaptors.

To execute this application, simply build the application using the Visual C++
Nmake.exe program generation facility. A ipchange.exe program should result.
Execute the ipchange.exe with the following parameters:

Ipchange.exe [ -l ] [ -a -n <index id> -i <ip address> -m <subnet mask> ]
[ -d -c <context id> ]

-l List adapter index IDs and IP Address context ID information
-a Add IP Address option
-d Delete IP Address option
-i IP Address to specify with -a option
-m Subnet Mask to specify with -a option
-c IP context ID for an existing IP address
-n Index ID of an existing network adapter

Author:

Jim Ohlund 21-Apr-98

Revision History:

*/

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

void Usage(void) {
printf( "Usage: Ipchange [ -l ] [ -a -n <index id> -i <ip address> -m <subnet mask> ] "