[NETCFGX]
[reactos.git] / reactos / dll / win32 / netcfgx / netcfgx.c
index 85f6165..ba89dff 100644 (file)
  * PROGRAMMERS:     HervĂ© Poussineau (hpoussin@reactos.org)
  */
 
-#define INITGUID
-#include "netcfgx.h"
 
+#include "precomp.h"
+#include <initguid.h>
+#include <devguid.h>
 #define NDEBUG
 #include <debug.h>
 
+HINSTANCE netcfgx_hInstance;
+const GUID CLSID_TcpipConfigNotifyObject      = {0xA907657F, 0x6FDF, 0x11D0, {0x8E, 0xFB, 0x00, 0xC0, 0x4F, 0xD9, 0x12, 0xB2}};
+
+
+
+
+static INTERFACE_TABLE InterfaceTable[] =
+{
+    {
+        &CLSID_CNetCfg,
+        INetCfg_Constructor
+    },
+    {
+        &CLSID_TcpipConfigNotifyObject,
+        TcpipConfigNotify_Constructor
+    },
+    {
+        NULL,
+        NULL
+    }
+};
+
+BOOL
+WINAPI
+DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
+{
+    switch (fdwReason)
+    {
+        case DLL_PROCESS_ATTACH:
+            netcfgx_hInstance = hinstDLL;
+            DisableThreadLibraryCalls(netcfgx_hInstance);
+            break;
+    default:
+        break;
+    }
+
+    return TRUE;
+}
+
+HRESULT
+WINAPI
+DllCanUnloadNow(void)
+{
+    return S_FALSE;
+}
+
+STDAPI
+DllRegisterServer(void)
+{
+    HKEY hKey, hSubKey;
+    LPOLESTR pStr;
+    WCHAR szName[MAX_PATH] = L"CLSID\\";
+
+    if (FAILED(StringFromCLSID(&CLSID_CNetCfg, &pStr)))
+        return SELFREG_E_CLASS;
+
+    wcscpy(&szName[6], pStr);
+    CoTaskMemFree(pStr);
+
+    if (RegCreateKeyExW(HKEY_CLASSES_ROOT, szName, 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) != ERROR_SUCCESS)
+        return SELFREG_E_CLASS;
+
+    if (RegCreateKeyExW(hKey, L"InProcServer32", 0, NULL, 0, KEY_WRITE, NULL, &hSubKey, NULL) == ERROR_SUCCESS)
+    {
+        if (!GetModuleFileNameW(netcfgx_hInstance, szName, sizeof(szName)/sizeof(WCHAR)))
+        {
+            RegCloseKey(hSubKey);
+            RegCloseKey(hKey);
+            return SELFREG_E_CLASS;
+        }
+        szName[(sizeof(szName)/sizeof(WCHAR))-1] = L'\0';
+        RegSetValueW(hSubKey, NULL, REG_SZ, szName, (wcslen(szName)+1) * sizeof(WCHAR));
+        RegSetValueExW(hSubKey, L"ThreadingModel", 0, REG_SZ, (LPBYTE)L"Both", 10);
+        RegCloseKey(hSubKey);
+    }
+
+    RegCloseKey(hKey);
+    return S_OK;
+}
+
+STDAPI
+DllUnregisterServer(void)
+{
+    //FIXME
+    // implement unregistering services
+    //
+    return S_OK;
+}
+
+STDAPI
+DllGetClassObject(
+  REFCLSID rclsid,
+  REFIID riid,
+  LPVOID* ppv 
+)
+{
+    UINT i;
+    HRESULT    hres = E_OUTOFMEMORY;
+    IClassFactory * pcf = NULL;        
+
+    if (!ppv)
+        return E_INVALIDARG;
+
+    *ppv = NULL;
+
+    for (i = 0; InterfaceTable[i].riid; i++) 
+    {
+        if (IsEqualIID(InterfaceTable[i].riid, rclsid)) 
+        {
+            pcf = IClassFactory_fnConstructor(InterfaceTable[i].lpfnCI, NULL, NULL);
+            break;
+        }
+    }
+
+    if (!pcf) 
+    {
+        return CLASS_E_CLASSNOTAVAILABLE;
+    }
+
+    hres = IClassFactory_QueryInterface(pcf, riid, ppv);
+    IClassFactory_Release(pcf);
+
+    return hres;
+}
+
+
 /* Append a REG_SZ to an existing REG_MULTI_SZ string in the registry.
  * If the value doesn't exist, create it.
  * Returns ERROR_SUCCESS if success. Othewise, returns an error code
@@ -198,7 +325,6 @@ InstallNetDevice(
        HKEY hLinkageKey = NULL;
        HKEY hConnectionKey = NULL;
        DWORD dwShowIcon, dwLength;
-       SP_DEVINSTALL_PARAMS_W installParams;
 
        /* Get Instance ID */
        if (SetupDiGetDeviceInstanceIdW(DeviceInfoSet, DeviceInfoData, NULL, 0, &dwLength))
@@ -423,31 +549,6 @@ InstallNetDevice(
                goto cleanup;
        }
 
-       /* HACK: hpoussin, Dec 2005. TCP/IP driver is not able to manage devices
-        * which are installed after its startup. So, we have to reboot to take
-        * this new netcard into account.
-        */
-       /* Should we reboot? */
-       installParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS_W);
-       if (!SetupDiGetDeviceInstallParamsW(
-               DeviceInfoSet,
-               DeviceInfoData,
-               &installParams))
-       {
-               rc = GetLastError();
-               DPRINT("SetupDiGetDeviceInstallParams() failed with error 0x%lx\n", rc);
-               goto cleanup;
-       }
-       installParams.Flags |= DI_NEEDRESTART;
-       if (!SetupDiSetDeviceInstallParamsW(
-               DeviceInfoSet,
-               DeviceInfoData,
-               &installParams))
-       {
-               rc = GetLastError();
-               DPRINT("SetupDiSetDeviceInstallParams() failed with error 0x%lx\n", rc);
-               goto cleanup;
-       }
        rc = ERROR_SUCCESS;
 
 cleanup: