Delete all Trailing spaces in code.
[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: dll/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 static LONG APIENTRY Applet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM 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 (WINAPI *PINSTALL_NEW_DEVICE)(HWND, LPGUID, PDWORD);
46
47 static LONG APIENTRY
48 Applet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM 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
105 /* Control Panel Callback */
106 LONG CALLBACK
107 CPlApplet(HWND hwndCpl,
108 UINT uMsg,
109 LPARAM lParam1,
110 LPARAM lParam2)
111 {
112 INT i = (INT)lParam1;
113
114 switch (uMsg)
115 {
116 case CPL_INIT:
117 return TRUE;
118
119 case CPL_GETCOUNT:
120 return sizeof(Applets)/sizeof(Applets[0]);
121
122 case CPL_INQUIRE:
123 {
124 CPLINFO *CPlInfo = (CPLINFO*)lParam2;
125 CPlInfo->lData = 0;
126 CPlInfo->idIcon = Applets[i].idIcon;
127 CPlInfo->idName = Applets[i].idName;
128 CPlInfo->idInfo = Applets[i].idDescription;
129 }
130 break;
131
132 case CPL_DBLCLK:
133 Applets[i].AppletProc(hwndCpl, uMsg, lParam1, lParam2);
134 break;
135 }
136
137 return FALSE;
138 }
139
140
141 BOOL WINAPI
142 DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
143 {
144 UNREFERENCED_PARAMETER(lpvReserved);
145
146 switch (dwReason)
147 {
148 case DLL_PROCESS_ATTACH:
149 hApplet = hinstDLL;
150 break;
151 }
152
153 return TRUE;
154 }