Sync with trunk (r48545)
[reactos.git] / dll / win32 / netshell / netshell.c
1 #include "precomp.h"
2 #include <initguid.h>
3 #include <devguid.h>
4
5 HINSTANCE netshell_hInstance;
6 const GUID CLSID_LANConnectUI = {0x7007ACC5, 0x3202, 0x11D1, {0xAA, 0xD2, 0x00, 0x80, 0x5F, 0xC1, 0x27, 0x0E}};
7 const GUID CLSID_NetworkConnections = {0x7007ACC7, 0x3202, 0x11D1, {0xAA, 0xD2, 0x00, 0x80, 0x5F, 0xC1, 0x27, 0x0E}};
8 const GUID CLSID_LanConnectStatusUI = {0x7007ACCF, 0x3202, 0x11D1, {0xAA, 0xD2, 0x00, 0x80, 0x5F, 0xC1, 0x27, 0x0E}};
9
10 static const WCHAR szNetConnectClass[] = L"CLSID\\{7007ACC7-3202-11D1-AAD2-00805FC1270E}";
11 static const WCHAR szLanConnectUI[] = L"CLSID\\{7007ACC5-3202-11D1-AAD2-00805FC1270E}";
12 static const WCHAR szLanConnectStatusUI[] = L"CLSID\\{7007ACCF-3202-11D1-AAD2-00805FC1270E}";
13 static const WCHAR szNamespaceKey[] = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ControlPanel\\NameSpace\\{7007ACC7-3202-11D1-AAD2-00805FC1270E}";
14
15 static INTERFACE_TABLE InterfaceTable[] =
16 {
17 {
18 &CLSID_NetworkConnections,
19 ISF_NetConnect_Constructor
20 },
21 {
22 &CLSID_ConnectionManager,
23 INetConnectionManager_Constructor
24 },
25 {
26 &CLSID_LANConnectUI,
27 LanConnectUI_Constructor
28 },
29 {
30 &CLSID_LanConnectStatusUI,
31 LanConnectStatusUI_Constructor
32 },
33 {
34 NULL,
35 NULL
36 }
37 };
38
39
40 BOOL
41 WINAPI
42 DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
43 {
44 switch (fdwReason)
45 {
46 case DLL_PROCESS_ATTACH:
47 netshell_hInstance = hinstDLL;
48 DisableThreadLibraryCalls(netshell_hInstance);
49 break;
50 default:
51 break;
52 }
53
54 return TRUE;
55 }
56
57 HRESULT
58 WINAPI
59 DllCanUnloadNow(void)
60 {
61 return S_FALSE;
62 }
63
64 STDAPI
65 DllRegisterServer(void)
66 {
67 HKEY hKey, hSubKey;
68 WCHAR szName[MAX_PATH+20] = {0};
69 WCHAR szNet[20];
70 UINT Length, Offset;
71
72
73 if (RegCreateKeyExW(HKEY_CLASSES_ROOT, szNetConnectClass, 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) != ERROR_SUCCESS)
74 return SELFREG_E_CLASS;
75
76 if (LoadStringW(netshell_hInstance, IDS_NETWORKCONNECTION, szName, MAX_PATH))
77 {
78 szName[MAX_PATH-1] = L'\0';
79 RegSetValueW(hKey, NULL, REG_SZ, szName, (wcslen(szName)+1) * sizeof(WCHAR));
80 }
81
82 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, szNamespaceKey, 0, NULL, 0, KEY_WRITE, NULL, &hSubKey, NULL) == ERROR_SUCCESS)
83 {
84 RegSetValueW(hSubKey, NULL, REG_SZ, szName, (wcslen(szName)+1) * sizeof(WCHAR));
85 RegCloseKey(hSubKey);
86 }
87
88 Length = swprintf(szNet, L",-%u", IDS_NETWORKCONNECTION);
89 Offset = GetModuleFileNameW(netshell_hInstance, &szName[1], (sizeof(szName)/sizeof(WCHAR))-1);
90 if (Offset + Length + 2 < MAX_PATH)
91 {
92 /* set localized name */
93 szName[0] = L'@';
94 wcscpy(&szName[Offset+1], szNet);
95 RegSetValueExW(hKey, L"LocalizedString", 0, REG_SZ, (const LPBYTE)szName, (wcslen(szName)+1) * sizeof(WCHAR));
96 }
97
98 szName[Offset+1] = L'\0';
99
100 /* store default icon */
101 if (RegCreateKeyExW(hKey, L"DefaultIcon", 0, NULL, 0, KEY_WRITE, NULL, &hSubKey, NULL) == ERROR_SUCCESS)
102 {
103 RegSetValueW(hSubKey, NULL, REG_SZ, &szName[1], (Offset+1) * sizeof(WCHAR));
104 RegCloseKey(hSubKey);
105 }
106 if (RegCreateKeyExW(hKey, L"InProcServer32", 0, NULL, 0, KEY_WRITE, NULL, &hSubKey, NULL) == ERROR_SUCCESS)
107 {
108 RegSetValueW(hSubKey, NULL, REG_SZ, &szName[1], (Offset+1) * sizeof(WCHAR));
109 RegSetValueExW(hSubKey, L"ThreadingModel", 0, REG_SZ, (LPBYTE)L"Both", 10);
110 RegCloseKey(hSubKey);
111 }
112
113 if (RegCreateKeyExW(hKey, L"ShellFolder", 0, NULL, 0, KEY_WRITE, NULL, &hSubKey, NULL) == ERROR_SUCCESS)
114 {
115 DWORD dwAttributes = SFGAO_FOLDER;
116 RegSetValueExW(hSubKey, L"Attributes",0, REG_BINARY, (const LPBYTE)&dwAttributes, sizeof(DWORD));
117 }
118
119 RegCloseKey(hKey);
120
121 if (RegCreateKeyExW(HKEY_CLASSES_ROOT, szLanConnectUI, 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) != ERROR_SUCCESS)
122 return SELFREG_E_CLASS;
123
124 if (RegCreateKeyExW(hKey, L"InProcServer32", 0, NULL, 0, KEY_WRITE, NULL, &hSubKey, NULL) == ERROR_SUCCESS)
125 {
126 RegSetValueW(hSubKey, NULL, REG_SZ, &szName[1], (Offset+1) * sizeof(WCHAR));
127 RegSetValueExW(hSubKey, L"ThreadingModel", 0, REG_SZ, (LPBYTE)L"Both", 10);
128 RegCloseKey(hSubKey);
129 }
130
131 RegCloseKey(hKey);
132
133 if (RegCreateKeyExW(HKEY_CLASSES_ROOT, szLanConnectStatusUI, 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) != ERROR_SUCCESS)
134 return SELFREG_E_CLASS;
135
136 if (RegCreateKeyExW(hKey, L"InProcServer32", 0, NULL, 0, KEY_WRITE, NULL, &hSubKey, NULL) == ERROR_SUCCESS)
137 {
138 RegSetValueW(hSubKey, NULL, REG_SZ, &szName[1], (Offset+1) * sizeof(WCHAR));
139 RegSetValueExW(hSubKey, L"ThreadingModel", 0, REG_SZ, (LPBYTE)L"Both", 10);
140 RegCloseKey(hSubKey);
141 }
142
143 RegCloseKey(hKey);
144
145
146 return S_OK;
147 }
148
149 STDAPI
150 DllUnregisterServer(void)
151 {
152 SHDeleteKeyW(HKEY_CLASSES_ROOT, szNetConnectClass);
153 SHDeleteKeyW(HKEY_LOCAL_MACHINE, szNamespaceKey);
154 return S_OK;
155 }
156
157 STDAPI
158 DllGetClassObject(
159 REFCLSID rclsid,
160 REFIID riid,
161 LPVOID* ppv
162 )
163 {
164 UINT i;
165 HRESULT hres = E_OUTOFMEMORY;
166 IClassFactory * pcf = NULL;
167
168 if (!ppv)
169 return E_INVALIDARG;
170
171 *ppv = NULL;
172
173 for (i = 0; InterfaceTable[i].riid; i++)
174 {
175 if (IsEqualIID(InterfaceTable[i].riid, rclsid))
176 {
177 pcf = IClassFactory_fnConstructor(InterfaceTable[i].lpfnCI, NULL, NULL);
178 break;
179 }
180 }
181
182 if (!pcf)
183 {
184 return CLASS_E_CLASSNOTAVAILABLE;
185 }
186
187 hres = IClassFactory_QueryInterface(pcf, riid, ppv);
188 IClassFactory_Release(pcf);
189
190 return hres;
191 }
192
193 VOID
194 WINAPI
195 NcFreeNetconProperties (NETCON_PROPERTIES* pProps)
196 {
197 CoTaskMemFree(pProps->pszwName);
198 CoTaskMemFree(pProps->pszwDeviceName);
199 CoTaskMemFree(pProps);
200 }