2519d9bad95103053c42c1eeb4aa2e58935b5b9d
[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
48 BOOL CALLBACK
49 InstallNewDevice(HWND hwndParent,
50 LPGUID ClassGuid,
51 PDWORD pReboot)
52 {
53 return TRUE;
54 }
55
56 static LONG APIENTRY
57 Applet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
58 {
59 HMODULE hNewDev = NULL;
60 PINSTALL_NEW_DEVICE InstallNewDevice;
61 DWORD Reboot;
62 BOOL ret;
63 LONG rc;
64
65 UNREFERENCED_PARAMETER(lParam);
66 UNREFERENCED_PARAMETER(wParam);
67 UNREFERENCED_PARAMETER(uMsg);
68
69 hNewDev = LoadLibrary(_T("newdev.dll"));
70 if (!hNewDev)
71 {
72 rc = 1;
73 goto cleanup;
74 }
75
76 InstallNewDevice = (PINSTALL_NEW_DEVICE)GetProcAddress(hNewDev, (LPCSTR)"InstallNewDevice");
77 if (!InstallNewDevice)
78 {
79 rc = 2;
80 goto cleanup;
81 }
82
83 ret = InstallNewDevice(hwnd, NULL, &Reboot);
84 if (!ret)
85 {
86 rc = 3;
87 goto cleanup;
88 }
89
90 if (Reboot != DI_NEEDRESTART && Reboot != DI_NEEDREBOOT)
91 {
92 /* We're done with installation */
93 rc = 0;
94 goto cleanup;
95 }
96
97 /* We need to reboot */
98 if (SetupPromptReboot(NULL, hwnd, FALSE) == -1)
99 {
100 /* User doesn't want to reboot, or an error occurred */
101 rc = 5;
102 goto cleanup;
103 }
104
105 rc = 0;
106
107 cleanup:
108 if (hNewDev != NULL)
109 FreeLibrary(hNewDev);
110 return rc;
111 }
112
113
114 /* Control Panel Callback */
115 LONG CALLBACK
116 CPlApplet(HWND hwndCpl,
117 UINT uMsg,
118 LPARAM lParam1,
119 LPARAM lParam2)
120 {
121 INT i = (INT)lParam1;
122
123 switch (uMsg)
124 {
125 case CPL_INIT:
126 return TRUE;
127
128 case CPL_GETCOUNT:
129 return sizeof(Applets)/sizeof(Applets[0]);
130
131 case CPL_INQUIRE:
132 {
133 CPLINFO *CPlInfo = (CPLINFO*)lParam2;
134 CPlInfo->lData = 0;
135 CPlInfo->idIcon = Applets[i].idIcon;
136 CPlInfo->idName = Applets[i].idName;
137 CPlInfo->idInfo = Applets[i].idDescription;
138 }
139 break;
140
141 case CPL_DBLCLK:
142 Applets[i].AppletProc(hwndCpl, uMsg, lParam1, lParam2);
143 break;
144 }
145
146 return FALSE;
147 }
148
149
150 BOOL WINAPI
151 DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
152 {
153 UNREFERENCED_PARAMETER(lpvReserved);
154
155 switch (dwReason)
156 {
157 case DLL_PROCESS_ATTACH:
158 hApplet = hinstDLL;
159 break;
160 }
161
162 return TRUE;
163 }