动态修改IP方法

来源:互联网 发布:jsp网上购物系统源码 编辑:程序博客网 时间:2024/06/06 03:29
//调用DhcpNotifyConfigChange函数动态修改IP
BOOL NotifyIPChange(LPCTSTR lpszAdapterName, int nIndex, LPCTSTR pIPAddress, LPCTSTR pNetMask)
{
 BOOL   bResult = FALSE;
 HINSTANCE  hDhcpDll;
 DHCPNOTIFYPROC pDhcpNotifyProc;
 WCHAR wcAdapterName[256];
 
 MultiByteToWideChar(CP_ACP, 0, lpszAdapterName, -1, wcAdapterName,256);
 if((hDhcpDll = LoadLibrary("dhcpcsvc")) == NULL)
  return FALSE;
 if((pDhcpNotifyProc = (DHCPNOTIFYPROC)GetProcAddress(hDhcpDll, "DhcpNotifyConfigChange")) != NULL)
  if((pDhcpNotifyProc)(NULL,
                                     wcAdapterName,
                                     TRUE,
                                     nIndex,
                                     inet_addr(pIPAddress),
                                     inet_addr(pNetMask), 0) == ERROR_SUCCESS)
   bResult = TRUE;
 FreeLibrary(hDhcpDll);
 return bResult;
}
原创粉丝点击