reverting : revison 22930 to 22932, 22938 to 22940, 22943, 22945, 22950, 22953 to...
[reactos.git] / reactos / dll / cpl / hdwwiz / hdwwiz.c
1 /*
2 * ReactOS New devices installation
3 * Copyright (C) 2005 ReactOS Team
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 /*
20 * PROJECT: ReactOS Add hardware control panel
21 * FILE: lib/cpl/hdwwiz/hdwwiz.c
22 * PURPOSE: ReactOS Add hardware control panel
23 * PROGRAMMER: Hervé Poussineau (hpoussin@reactos.org)
24 */
25
26 #include <windows.h>
27 #include <commctrl.h>
28 #include <setupapi.h>
29 #include <cpl.h>
30 #include <tchar.h>
31 #include <stdio.h>
32
33 #include "resource.h"
34 #include "hdwwiz.h"
35
36 LONG APIENTRY Applet(HWND hwnd, UINT uMsg, LONG wParam, LONG lParam);
37 HINSTANCE hApplet = 0;
38
39 /* Applets */
40 APPLET Applets[] =
41 {
42 {IDI_CPLICON, IDS_CPLNAME, IDS_CPLDESCRIPTION, Applet}
43 };
44
45 typedef BOOL (*PINSTALL_NEW_DEVICE)(HWND, LPGUID, PDWORD);
46
47 LONG APIENTRY
48 Applet(HWND hwnd, UINT uMsg, LONG wParam, LONG lParam)
49 {
50 HMODULE hNewDev = NULL;
51 PINSTALL_NEW_DEVICE InstallNewDevice;
52 DWORD Reboot;
53 BOOL ret;
54 LONG rc;
55
56 UNREFERENCED_PARAMETER(lParam)
57 UNREFERENCED_PARAMETER(wParam)
58 UNREFERENCED_PARAMETER(uMsg)
59
60 hNewDev = LoadLibrary(_T("newdev.dll"));
61 if (!hNewDev)
62 {
63 rc = 1;
64 goto cleanup;
65 }
66
67 InstallNewDevice = (PINSTALL_NEW_DEVICE)GetProcAddress(hNewDev, (LPCSTR)"InstallNewDevice");
68 if (!InstallNewDevice)
69 {
70 rc = 2;
71 goto cleanup;
72 }
73
74 ret = InstallNewDevice(hwnd, NULL, &Reboot);
75 if (!ret)
76 {
77 rc = 3;
78 goto cleanup;
79 }
80
81 if (Reboot != DI_NEEDRESTART && Reboot != DI_NEEDREBOOT)
82 {
83 /* We're done with installation */
84 rc = 0;
85 goto cleanup;
86 }
87
88 /* We need to reboot */
89 if (SetupPromptReboot(NULL, hwnd, FALSE) == -1)
90 {
91 /* User doesn't want to reboot, or an error occurred */
92 rc = 5;
93 goto cleanup;
94 }
95
96 rc = 0;
97
98 cleanup:
99 if (hNewDev != NULL)
100 FreeLibrary(hNewDev);
101 return rc;
102 }
103
104 /* Control Panel Callback */
105 LONG CALLBACK
106 CPlApplet(HWND hwndCpl,
107 UINT uMsg,
108 LPARAM lParam1,
109 LPARAM lParam2)
110 {
111 int i = (int)lParam1;
112
113 switch (uMsg)
114 {
115 case CPL_INIT:
116 return TRUE;
117
118 case CPL_GETCOUNT:
119 return sizeof(Applets)/sizeof(Applets[0]);
120
121 case CPL_INQUIRE:
122 {
123 CPLINFO *CPlInfo = (CPLINFO*)lParam2;
124 CPlInfo->lData = 0;
125 CPlInfo->idIcon = Applets[i].idIcon;
126 CPlInfo->idName = Applets[i].idName;
127 CPlInfo->idInfo = Applets[i].idDescription;
128 break;
129 }
130
131 case CPL_DBLCLK:
132 {
133 Applets[i].AppletProc(hwndCpl, uMsg, lParam1, lParam2);
134 break;
135 }
136 }
137 return FALSE;
138 }
139
140 BOOL WINAPI
141 DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
142 {
143 UNREFERENCED_PARAMETER(lpvReserved)
144 switch(dwReason)
145 {
146 case DLL_PROCESS_ATTACH:
147 hApplet = hinstDLL;
148 break;
149 }
150 return TRUE;
151 }