[NETCFGX]
[reactos.git] / reactos / dll / win32 / netcfgx / tcpipconf_notify.c
index 0c6b75f..14b9a4a 100644 (file)
@@ -34,6 +34,7 @@ typedef struct tagIP_ADDR
         DWORD Subnetmask;
         USHORT Metric;
     }u;
+    ULONG NTEContext;
     struct tagIP_ADDR * Next;
 }IP_ADDR;
 
@@ -106,7 +107,7 @@ typedef struct
     UINT MaxNum;
 }TcpipPortSettings;
 
-static LPTcpipConfNotifyImpl __inline impl_from_INetCfgComponentControl(INetCfgComponentControl *iface)
+static __inline LPTcpipConfNotifyImpl impl_from_INetCfgComponentControl(INetCfgComponentControl *iface)
 {
     return (TcpipConfNotifyImpl*)((char *)iface - FIELD_OFFSET(TcpipConfNotifyImpl, lpVtblCompControl));
 }
@@ -115,6 +116,7 @@ INT GetSelectedItem(HWND hDlgCtrl);
 HRESULT InitializeTcpipBasicDlgCtrls(HWND hwndDlg, TcpipSettings * pCurSettings);
 VOID InsertColumnToListView(HWND hDlgCtrl, UINT ResId, UINT SubItem, UINT Size);
 INT_PTR StoreTcpipBasicSettings(HWND hwndDlg, TcpipConfNotifyImpl * This, BOOL bApply);
+HRESULT Initialize(TcpipConfNotifyImpl * This);
 
 VOID
 DisplayError(UINT ResTxt, UINT ResTitle, UINT Type)
@@ -1760,6 +1762,7 @@ StoreDNSSettings(
         pLast = pCur;
         pCur = pCur->Next;
     }
+    This->pCurrentConfig->AutoconfigActive = FALSE;
 }
 
 INT_PTR
@@ -2044,7 +2047,6 @@ TcpipAdvancedDnsDlg(
 
 VOID
 LaunchAdvancedTcpipSettings(
-    HWND hDlg,
     HWND hwndDlg,
     TcpipConfNotifyImpl * This)
 {
@@ -2067,14 +2069,14 @@ LaunchAdvancedTcpipSettings(
     pinfo.dwFlags = PSH_NOCONTEXTHELP | PSH_PROPTITLE | PSH_NOAPPLYNOW;
     pinfo.u3.phpage = hppages;
     pinfo.nPages = 3;
-    pinfo.hwndParent = hDlg;
+    pinfo.hwndParent = hwndDlg;
     pinfo.pszCaption = szBuffer;
 
     StoreTcpipBasicSettings(hwndDlg, This, FALSE);
     PropertySheetW(&pinfo);
 
     InitializeTcpipBasicDlgCtrls(hwndDlg, This->pCurrentConfig);
-    PropSheet_Changed(hDlg, hwndDlg); 
+    PropSheet_Changed(GetParent(hwndDlg), hwndDlg); 
 }
 
 INT_PTR
@@ -2172,6 +2174,15 @@ StoreTcpipBasicSettings(
             /* store default gateway */
             This->pCurrentConfig->Gw->IpAddress = dwIpAddr;
        }
+       else
+       {
+           if (This->pCurrentConfig->Gw)
+           {
+               IP_ADDR * pNextGw = This->pCurrentConfig->Gw->Next;
+               CoTaskMemFree(This->pCurrentConfig->Gw);
+               This->pCurrentConfig->Gw = pNextGw;
+           }
+       }
     }
     else
     {
@@ -2302,7 +2313,7 @@ InitializeTcpipBasicDlgCtrls(
             /* set current hostmask */
             SendDlgItemMessageA(hwndDlg, IDC_SUBNETMASK, IPM_SETADDRESS, 0, (LPARAM)pCurSettings->Ip->u.Subnetmask);
         }
-        if (pCurSettings->Gw->IpAddress)
+        if (pCurSettings->Gw && pCurSettings->Gw->IpAddress)
         {
             /* set current gateway */
             SendDlgItemMessageA(hwndDlg, IDC_DEFGATEWAY, IPM_SETADDRESS, 0, (LPARAM)pCurSettings->Gw->IpAddress);
@@ -2317,6 +2328,8 @@ InitializeTcpipBasicDlgCtrls(
     else
     {
         SendDlgItemMessageW(hwndDlg, IDC_FIXEDDNS, BM_SETCHECK, BST_CHECKED, 0);
+        EnableWindow(GetDlgItem(hwndDlg, IDC_DNS1), TRUE);
+        EnableWindow(GetDlgItem(hwndDlg, IDC_DNS2), TRUE);
         if (pCurSettings->Ns)
         {
             SendDlgItemMessageW(hwndDlg, IDC_DNS1, IPM_SETADDRESS, 0, (LPARAM)pCurSettings->Ns->IpAddress);
@@ -2364,10 +2377,16 @@ CopyIpAddrString(
         }
         ZeroMemory(pNew, sizeof(IP_ADDR));
         pNew->IpAddress = GetIpAddressFromStringA(pCurrent->IpAddress.String);
+        if (!pNew->IpAddress)
+        {
+            CoTaskMemFree(pNew);
+            return E_FAIL;
+        }
 
        if (Type == SUBMASK)
        {
            pNew->u.Subnetmask = GetIpAddressFromStringA(pCurrent->IpMask.String);
+           pNew->NTEContext = pCurrent->Context;
        }
        else if (Type == METRIC)
        {
@@ -2504,7 +2523,7 @@ TcpipBasicDlg(
                         }
                         break;
                     case IDC_ADVANCED:
-                        LaunchAdvancedTcpipSettings(GetParent(hwndDlg), hwndDlg, (TcpipConfNotifyImpl*)GetWindowLongPtr(hwndDlg, DWLP_USER));
+                        LaunchAdvancedTcpipSettings(hwndDlg, (TcpipConfNotifyImpl*)GetWindowLongPtr(hwndDlg, DWLP_USER));
                         break;
                 }
                 break;
@@ -2521,7 +2540,7 @@ TcpipBasicDlg(
  */
 
 HRESULT
-STDCALL
+WINAPI
 INetCfgComponentPropertyUi_fnQueryInterface(
     INetCfgComponentPropertyUi * iface,
     REFIID iid,
@@ -2556,7 +2575,7 @@ INetCfgComponentPropertyUi_fnQueryInterface(
 
 
 ULONG
-STDCALL
+WINAPI
 INetCfgComponentPropertyUi_fnAddRef(
     INetCfgComponentPropertyUi * iface)
 {
@@ -2567,7 +2586,7 @@ INetCfgComponentPropertyUi_fnAddRef(
 }
 
 ULONG
-STDCALL
+WINAPI
 INetCfgComponentPropertyUi_fnRelease(
     INetCfgComponentPropertyUi * iface)
 {
@@ -2582,7 +2601,7 @@ INetCfgComponentPropertyUi_fnRelease(
 }
 
 HRESULT
-STDCALL
+WINAPI
 INetCfgComponentPropertyUi_fnQueryPropertyUi(
     INetCfgComponentPropertyUi * iface,
     IUnknown *pUnkReserved)
@@ -2604,7 +2623,7 @@ INetCfgComponentPropertyUi_fnQueryPropertyUi(
 }
 
 HRESULT
-STDCALL
+WINAPI
 INetCfgComponentPropertyUi_fnSetContext(
     INetCfgComponentPropertyUi * iface,
     IUnknown *pUnkReserved)
@@ -2627,6 +2646,7 @@ LoadDNSSettings(
     HKEY hKey;
     DWORD dwSize;
 
+
     This->pCurrentConfig->pDNS = (TcpipAdvancedDNSDlgSettings*) CoTaskMemAlloc(sizeof(TcpipAdvancedDNSDlgSettings));
     if (!This->pCurrentConfig->pDNS)
         return E_FAIL;
@@ -2743,7 +2763,7 @@ LoadFilterSettings(
 
 
 HRESULT
-InitializeTcpipBasicDlg(TcpipConfNotifyImpl * This)
+Initialize(TcpipConfNotifyImpl * This)
 {
     DWORD dwSize;
     WCHAR szBuffer[50];
@@ -2794,7 +2814,7 @@ InitializeTcpipBasicDlg(TcpipConfNotifyImpl * This)
         {
             szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
         }
-        if (!wcsicmp(szBuffer, pStr))
+        if (!_wcsicmp(szBuffer, pStr))
         {
             bFound = TRUE;
             break;
@@ -2826,7 +2846,7 @@ InitializeTcpipBasicDlg(TcpipConfNotifyImpl * This)
         CopyIpAddrString(&pCurrentAdapter->IpAddressList, &pCurSettings->Ip, SUBMASK, NULL);
         CopyIpAddrString(&pCurrentAdapter->GatewayList, &pCurSettings->Gw, METRIC, NULL); //FIXME
     }
-
+    uLength = 0;
     if (GetPerAdapterInfo(pCurrentAdapter->Index, NULL, &uLength) == ERROR_BUFFER_OVERFLOW)
     {
         pPerInfo = (PIP_PER_ADAPTER_INFO)CoTaskMemAlloc(uLength);
@@ -2857,7 +2877,7 @@ InitializeTcpipBasicDlg(TcpipConfNotifyImpl * This)
 }
 
 HRESULT
-STDCALL
+WINAPI
 INetCfgComponentPropertyUi_fnMergePropPages( 
     INetCfgComponentPropertyUi * iface,
     DWORD *pdwDefPages,
@@ -2871,7 +2891,7 @@ INetCfgComponentPropertyUi_fnMergePropPages(
     HRESULT hr;
     TcpipConfNotifyImpl * This = (TcpipConfNotifyImpl*)iface;
 
-    hr = InitializeTcpipBasicDlg(This);
+    hr = Initialize(This);
     if (FAILED(hr))
         return hr;
 
@@ -2908,7 +2928,7 @@ INetCfgComponentPropertyUi_fnMergePropPages(
 }
 
 HRESULT
-STDCALL
+WINAPI
 INetCfgComponentPropertyUi_fnValidateProperties(
     INetCfgComponentPropertyUi * iface,
     HWND hwndDlg)
@@ -2918,7 +2938,7 @@ MessageBoxW(NULL, L"INetCfgComponentPropertyUi_fnValidateProperties", NULL, MB_O
 }
 
 HRESULT
-STDCALL
+WINAPI
 INetCfgComponentPropertyUi_fnApplyProperties(
     INetCfgComponentPropertyUi * iface)
 {
@@ -2928,7 +2948,7 @@ MessageBoxW(NULL, L"INetCfgComponentPropertyUi_fnApplyProperties", NULL, MB_OK);
 
 
 HRESULT
-STDCALL
+WINAPI
 INetCfgComponentPropertyUi_fnCancelProperties(
     INetCfgComponentPropertyUi * iface)
 {
@@ -2954,7 +2974,7 @@ static const INetCfgComponentPropertyUiVtbl vt_NetCfgComponentPropertyUi =
  */
 
 HRESULT
-STDCALL
+WINAPI
 INetCfgComponentControl_fnQueryInterface(
     INetCfgComponentControl * iface,
     REFIID iid,
@@ -2965,7 +2985,7 @@ INetCfgComponentControl_fnQueryInterface(
 }
 
 ULONG
-STDCALL
+WINAPI
 INetCfgComponentControl_fnAddRef(
     INetCfgComponentControl * iface)
 {
@@ -2974,7 +2994,7 @@ INetCfgComponentControl_fnAddRef(
 }
 
 ULONG
-STDCALL
+WINAPI
 INetCfgComponentControl_fnRelease(
     INetCfgComponentControl * iface)
 {
@@ -2983,7 +3003,7 @@ INetCfgComponentControl_fnRelease(
 }
 
 HRESULT
-STDCALL
+WINAPI
 INetCfgComponentControl_fnInitialize( 
     INetCfgComponentControl * iface,
     INetCfgComponent *pIComp,
@@ -3079,7 +3099,7 @@ CreateMultiSzString(IP_ADDR * pAddr, COPY_TYPE Type, LPDWORD Size, BOOL bComma)
 
 
 HRESULT
-STDCALL
+WINAPI
 INetCfgComponentControl_fnApplyRegistryChanges(
     INetCfgComponentControl * iface)
 {
@@ -3087,24 +3107,37 @@ INetCfgComponentControl_fnApplyRegistryChanges(
     LPOLESTR pStr;
     DWORD dwSize;
     WCHAR szBuffer[200];
+    TcpipSettings * pCurrentConfig, *pOldConfig;
+    ULONG NTEInstance;
 
     TcpipConfNotifyImpl * This = impl_from_INetCfgComponentControl(iface);
 
+    pCurrentConfig = This->pCurrentConfig;
+    This->pCurrentConfig = NULL;
+
+    if (FAILED(Initialize(This)))
+    {
+        This->pCurrentConfig = pCurrentConfig;
+        return E_FAIL;
+    }
+    pOldConfig = This->pCurrentConfig;
+    This->pCurrentConfig = pCurrentConfig;
+
     //MessageBoxW(NULL, L"INetCfgComponentControl_fnApplyRegistryChanges", NULL, MB_OK);
 
 
     if (RegCreateKeyExW(hKey, L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS)
     {
-        if (This->pCurrentConfig->pDNS)
+        if (pCurrentConfig->pDNS)
         {
-            RegSetValueExW(hKey, L"UseDomainNameDevolution", 0, REG_DWORD, (LPBYTE)&This->pCurrentConfig->pDNS->UseDomainNameDevolution, sizeof(DWORD));
-            RegSetValueExW(hKey, L"SearchList", 0, REG_SZ, (LPBYTE)This->pCurrentConfig->pDNS->szSearchList,
-                       (wcslen(This->pCurrentConfig->pDNS->szSearchList)+1) * sizeof(WCHAR));
+            RegSetValueExW(hKey, L"UseDomainNameDevolution", 0, REG_DWORD, (LPBYTE)&pCurrentConfig->pDNS->UseDomainNameDevolution, sizeof(DWORD));
+            RegSetValueExW(hKey, L"SearchList", 0, REG_SZ, (LPBYTE)pCurrentConfig->pDNS->szSearchList,
+                       (wcslen(pCurrentConfig->pDNS->szSearchList)+1) * sizeof(WCHAR));
         }
-        if (This->pCurrentConfig->pFilter)
+        if (pCurrentConfig->pFilter)
         {
             RegSetValueExW(hKey, L"EnableSecurityFilters", 0, REG_DWORD, 
-                      (LPBYTE)&This->pCurrentConfig->pFilter->EnableSecurityFilters, sizeof(DWORD));
+                      (LPBYTE)&pCurrentConfig->pFilter->EnableSecurityFilters, sizeof(DWORD));
         }
         RegCloseKey(hKey);
     }
@@ -3117,90 +3150,161 @@ INetCfgComponentControl_fnApplyRegistryChanges(
 
     if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, szBuffer, 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS)
     {
-        if (This->pCurrentConfig->pDNS)
+        if (pCurrentConfig->pDNS)
         {
             RegSetValueExW(hKey, L"RegisterAdapterName", 0, REG_DWORD, (LPBYTE)&This->pCurrentConfig->pDNS->RegisterAdapterName, sizeof(DWORD));
             RegSetValueExW(hKey, L"RegistrationEnabled", 0, REG_DWORD, (LPBYTE)&This->pCurrentConfig->pDNS->RegistrationEnabled, sizeof(DWORD));
             RegSetValueExW(hKey, L"Domain", 0, REG_SZ, (LPBYTE)This->pCurrentConfig->pDNS->szDomain,
                        (wcslen(This->pCurrentConfig->pDNS->szDomain)+1) * sizeof(WCHAR));
         }
-
-        if (This->pCurrentConfig->pFilter)
+#if 0
+        if (pCurrentConfig->pFilter)
         {
-            RegSetValueExW(hKey, L"TCPAllowedPorts", 0, REG_MULTI_SZ, 
-                       (LPBYTE)This->pCurrentConfig->pFilter->szTCPAllowedPorts,
-                        This->pCurrentConfig->pFilter->TCPSize);
-
-            RegSetValueExW(hKey, L"UDPAllowedPorts", 0, REG_MULTI_SZ, 
-                       (LPBYTE)This->pCurrentConfig->pFilter->szUDPAllowedPorts,
-                        This->pCurrentConfig->pFilter->UDPSize);
-
-            RegSetValueExW(hKey, L"RawIPAllowedProtocols", 0, REG_MULTI_SZ, 
-                       (LPBYTE)This->pCurrentConfig->pFilter->szRawIPAllowedProtocols,
-                        This->pCurrentConfig->pFilter->IPSize);
+            if (pCurrentConfig->pFilter->szTCPAllowedPorts)
+            {
+                RegSetValueExW(hKey, L"TCPAllowedPorts", 0, REG_MULTI_SZ, 
+                       (LPBYTE)pCurrentConfig->pFilter->szTCPAllowedPorts,
+                        pCurrentConfig->pFilter->TCPSize);
+            }
+            if (pCurrentConfig->pFilter->szUDPAllowedPorts)
+            {
+                RegSetValueExW(hKey, L"UDPAllowedPorts", 0, REG_MULTI_SZ, 
+                       (LPBYTE)pCurrentConfig->pFilter->szUDPAllowedPorts,
+                        pCurrentConfig->pFilter->UDPSize);
+            }
+            if (pCurrentConfig->pFilter->szRawIPAllowedProtocols)
+            {
+                RegSetValueExW(hKey, L"RawIPAllowedProtocols", 0, REG_MULTI_SZ, 
+                       (LPBYTE)pCurrentConfig->pFilter->szRawIPAllowedProtocols,
+                        pCurrentConfig->pFilter->IPSize);
+            }
         }
-
-        RegSetValueExW(hKey, L"EnableDHCP", 0, REG_DWORD, (LPBYTE)&This->pCurrentConfig->DhcpEnabled, sizeof(DWORD));
-        if (This->pCurrentConfig->DhcpEnabled)
+#endif
+        RegSetValueExW(hKey, L"EnableDHCP", 0, REG_DWORD, (LPBYTE)&pCurrentConfig->DhcpEnabled, sizeof(DWORD));
+        if (pCurrentConfig->DhcpEnabled)
         {
             RegSetValueExW(hKey, L"IPAddress", 0, REG_MULTI_SZ, (LPBYTE)L"0.0.0.0\0", 9 * sizeof(WCHAR));
             RegSetValueExW(hKey, L"SubnetMask", 0, REG_MULTI_SZ, (LPBYTE)L"0.0.0.0\0", 9 * sizeof(WCHAR));
             RegSetValueExW(hKey, L"DefaultGateway", 0, REG_MULTI_SZ, (LPBYTE)L"\0", 2 * sizeof(WCHAR));
             RegSetValueExW(hKey, L"DefaultGatewayMetric", 0, REG_MULTI_SZ, (LPBYTE)L"\0", 2 * sizeof(WCHAR));
+            if (!pOldConfig->DhcpEnabled)
+            {
+                DeleteIPAddress(pOldConfig->Ip->NTEContext);
+                //FIXME
+                // start dhcp client service for the adapter
+            }
         }
         else
         {
-            pStr = CreateMultiSzString(This->pCurrentConfig->Ip, IPADDR, &dwSize, FALSE);
-            if(pStr)
+            if (!pOldConfig->DhcpEnabled)
             {
-                RegSetValueExW(hKey, L"IPAddress", 0, REG_MULTI_SZ, (LPBYTE)pStr, dwSize);
-                CoTaskMemFree(pStr);
+                DeleteIPAddress(pOldConfig->Ip->NTEContext);
+                //TODO
+                //delete multiple ip addresses when required
             }
 
-            pStr = CreateMultiSzString(This->pCurrentConfig->Ip, SUBMASK, &dwSize, FALSE);
-            if(pStr)
+            //TODO
+            // add multiple ip addresses when required
+            if (AddIPAddress(htonl(pCurrentConfig->Ip->IpAddress), htonl(pCurrentConfig->Ip->u.Subnetmask), pCurrentConfig->Index, &pCurrentConfig->Ip->NTEContext, &NTEInstance) == NO_ERROR)
             {
-                RegSetValueExW(hKey, L"SubnetMask", 0, REG_MULTI_SZ, (LPBYTE)pStr, dwSize);
-                CoTaskMemFree(pStr);
+                pStr = CreateMultiSzString(pCurrentConfig->Ip, IPADDR, &dwSize, FALSE);
+                if(pStr)
+                {
+                    RegSetValueExW(hKey, L"IPAddress", 0, REG_MULTI_SZ, (LPBYTE)pStr, dwSize);
+                    CoTaskMemFree(pStr);
+                }
+
+                pStr = CreateMultiSzString(pCurrentConfig->Ip, SUBMASK, &dwSize, FALSE);
+                if(pStr)
+                {
+                    RegSetValueExW(hKey, L"SubnetMask", 0, REG_MULTI_SZ, (LPBYTE)pStr, dwSize);
+                    CoTaskMemFree(pStr);
+                }
             }
 
-            pStr = CreateMultiSzString(This->pCurrentConfig->Gw, IPADDR, &dwSize, FALSE);
-            if(pStr)
+            if (pOldConfig->Gw)
             {
-                RegSetValueExW(hKey, L"DefaultGateway", 0, REG_MULTI_SZ, (LPBYTE)pStr, dwSize);
-                CoTaskMemFree(pStr);
+                dwSize = 0;
+                if (GetIpForwardTable(NULL, &dwSize, FALSE) == ERROR_INSUFFICIENT_BUFFER)
+                {
+                    DWORD Index;
+                    PMIB_IPFORWARDTABLE pIpForwardTable = (PMIB_IPFORWARDTABLE)CoTaskMemAlloc(dwSize);
+                    if (pIpForwardTable)
+                    {
+                        if (GetIpForwardTable(pIpForwardTable, &dwSize, FALSE) == NO_ERROR)
+                        {
+                            for (Index = 0; Index < pIpForwardTable->dwNumEntries; Index++)
+                            {
+                                if (pIpForwardTable->table[Index].dwForwardIfIndex == pOldConfig->Index)
+                                {
+                                    DeleteIpForwardEntry(&pIpForwardTable->table[Index]);
+                                }
+                            }
+                        }
+                        CoTaskMemFree(pIpForwardTable);
+                    }
+                }
             }
 
-            pStr = CreateMultiSzString(This->pCurrentConfig->Gw, METRIC, &dwSize, FALSE);
-            if(pStr)
+            if (pCurrentConfig->Gw)
             {
-                RegSetValueExW(hKey, L"DefaultGatewayMetric", 0, REG_MULTI_SZ, (LPBYTE)pStr, dwSize);
-                CoTaskMemFree(pStr);
+                MIB_IPFORWARDROW RouterMib;
+                ZeroMemory(&RouterMib, sizeof(MIB_IPFORWARDROW));
+
+                RouterMib.dwForwardMetric1 = 1;
+                RouterMib.dwForwardIfIndex = pOldConfig->Index;
+                RouterMib.dwForwardNextHop = htonl(pCurrentConfig->Gw->IpAddress);
+
+                //TODO
+                // add multiple gw addresses when required
+
+                if (CreateIpForwardEntry(&RouterMib) == NO_ERROR)
+                {
+                    pStr = CreateMultiSzString(pCurrentConfig->Gw, IPADDR, &dwSize, FALSE);
+                    if(pStr)
+                    {
+                        RegSetValueExW(hKey, L"DefaultGateway", 0, REG_MULTI_SZ, (LPBYTE)pStr, dwSize);
+                        CoTaskMemFree(pStr);
+                    }
+
+                    pStr = CreateMultiSzString(pCurrentConfig->Gw, METRIC, &dwSize, FALSE);
+                    if(pStr)
+                    {
+                        RegSetValueExW(hKey, L"DefaultGatewayMetric", 0, REG_MULTI_SZ, (LPBYTE)pStr, dwSize);
+                        CoTaskMemFree(pStr);
+                    }
+                }
+            }
+            else
+            {
+                RegSetValueExW(hKey, L"DefaultGateway", 0, REG_MULTI_SZ, (LPBYTE)L"", 1 * sizeof(WCHAR));
+                RegSetValueExW(hKey, L"DefaultGatewayMetric", 0, REG_MULTI_SZ, (LPBYTE)L"\0", sizeof(WCHAR) * 2);
             }
         }
 
-        if (!This->pCurrentConfig->Ns || This->pCurrentConfig->AutoconfigActive)
+        if (!pCurrentConfig->Ns || pCurrentConfig->AutoconfigActive)
         {
             RegSetValueExW(hKey, L"NameServer", 0, REG_SZ, (LPBYTE)L"", 1 * sizeof(WCHAR));
         }
         else
         {
-            pStr = CreateMultiSzString(This->pCurrentConfig->Ns, IPADDR, &dwSize, TRUE);
+            pStr = CreateMultiSzString(pCurrentConfig->Ns, IPADDR, &dwSize, TRUE);
             if(pStr)
             {
+
                 RegSetValueExW(hKey, L"NameServer", 0, REG_SZ, (LPBYTE)pStr, dwSize);
+                RegDeleteValueW(hKey, L"DhcpNameServer");
                 CoTaskMemFree(pStr);
             }
         }
+
         RegCloseKey(hKey);
     }
-
-
     return S_OK;
 }
 
 HRESULT
-STDCALL
+WINAPI
 INetCfgComponentControl_fnApplyPnpChanges(
     INetCfgComponentControl * iface,
     INetCfgPnpReconfigCallback *pICallback)
@@ -3210,7 +3314,7 @@ INetCfgComponentControl_fnApplyPnpChanges(
 }
 
 HRESULT
-STDCALL
+WINAPI
 INetCfgComponentControl_fnCancelChanges(
     INetCfgComponentControl * iface)
 {
@@ -3230,7 +3334,7 @@ static const INetCfgComponentControlVtbl vt_NetCfgComponentControl =
 };
 
 HRESULT
-STDCALL
+WINAPI
 TcpipConfigNotify_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
 {
     TcpipConfNotifyImpl *This;