ddraw/tests: Add a test for drawing to a flippable surface.
[wine.git] / dlls / newdev / main.c
blobdcf7e391d4da3361612d1484fb29b2d252923d93
1 /*
2 * New Device installation API
4 * Copyright 2003 Ulrich Czekalla
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winerror.h"
25 #include "winbase.h"
26 #include "winnls.h"
27 #include "winuser.h"
28 #include "winreg.h"
29 #include "cfgmgr32.h"
30 #include "newdev.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
36 /***********************************************************************
37 * InstallNewDevice (NEWDEV.@)
39 BOOL WINAPI InstallNewDevice(HWND hwndParent, LPGUID ClassGuid, PDWORD pReboot)
41 FIXME("Stub!\n");
42 return TRUE;
45 /***********************************************************************
46 * InstallSelectedDriver (NEWDEV.@)
48 BOOL WINAPI InstallSelectedDriver(HWND parent, HDEVINFO info, const WCHAR *reserved, BOOL backup, DWORD *reboot)
50 FIXME("Stub! %p %p %s %u %p\n", parent, info, debugstr_w(reserved), backup, reboot);
51 return TRUE;
54 /***********************************************************************
55 * UpdateDriverForPlugAndPlayDevicesA (NEWDEV.@)
57 BOOL WINAPI UpdateDriverForPlugAndPlayDevicesA(HWND parent, const char *hardware_id,
58 const char *inf_path, DWORD flags, BOOL *reboot)
60 WCHAR hardware_idW[MAX_DEVICE_ID_LEN];
61 WCHAR inf_pathW[MAX_PATH];
63 MultiByteToWideChar(CP_ACP, 0, hardware_id, -1, hardware_idW, ARRAY_SIZE(hardware_idW));
64 MultiByteToWideChar(CP_ACP, 0, inf_path, -1, inf_pathW, ARRAY_SIZE(inf_pathW));
66 return UpdateDriverForPlugAndPlayDevicesW(parent, hardware_idW, inf_pathW, flags, reboot);
69 static BOOL hardware_id_matches(const WCHAR *id, const WCHAR *device_ids)
71 while (*device_ids)
73 if (!wcscmp(id, device_ids))
74 return TRUE;
75 device_ids += lstrlenW(device_ids) + 1;
77 return FALSE;
80 /***********************************************************************
81 * UpdateDriverForPlugAndPlayDevicesW (NEWDEV.@)
83 BOOL WINAPI UpdateDriverForPlugAndPlayDevicesW(HWND parent, const WCHAR *hardware_id,
84 const WCHAR *inf_path, DWORD flags, BOOL *reboot)
86 SP_DEVINSTALL_PARAMS_W params = {sizeof(params)};
87 SP_DEVINFO_DATA device = {sizeof(device)};
88 WCHAR *device_ids = NULL;
89 DWORD size = 0, i, j;
90 HDEVINFO set;
92 static const DWORD dif_list[] =
94 DIF_SELECTBESTCOMPATDRV,
95 DIF_ALLOW_INSTALL,
96 DIF_INSTALLDEVICEFILES,
97 DIF_REGISTER_COINSTALLERS,
98 DIF_INSTALLINTERFACES,
99 DIF_INSTALLDEVICE,
100 DIF_NEWDEVICEWIZARD_FINISHINSTALL,
103 TRACE("parent %p, hardware_id %s, inf_path %s, flags %#lx, reboot %p.\n",
104 parent, debugstr_w(hardware_id), debugstr_w(inf_path), flags, reboot);
106 if (flags)
107 FIXME("Unhandled flags %#lx.\n", flags);
109 if (reboot) *reboot = FALSE;
111 if ((set = SetupDiGetClassDevsW(NULL, NULL, 0, DIGCF_ALLCLASSES)) == INVALID_HANDLE_VALUE)
112 return FALSE;
114 for (i = 0; SetupDiEnumDeviceInfo(set, i, &device); ++i)
116 if (!SetupDiGetDeviceRegistryPropertyW(set, &device, SPDRP_HARDWAREID, NULL, (BYTE *)device_ids, size, &size))
118 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
119 continue;
120 device_ids = realloc(device_ids, size);
121 SetupDiGetDeviceRegistryPropertyW(set, &device, SPDRP_HARDWAREID, NULL, (BYTE *)device_ids, size, NULL);
124 if (!hardware_id_matches(hardware_id, device_ids))
125 continue;
127 if (!SetupDiGetDeviceInstallParamsW(set, &device, &params))
128 continue;
130 lstrcpyW(params.DriverPath, inf_path);
131 params.Flags |= DI_ENUMSINGLEINF;
132 if (!SetupDiSetDeviceInstallParamsW(set, &device, &params))
133 continue;
135 if (!SetupDiBuildDriverInfoList(set, &device, SPDIT_COMPATDRIVER))
136 continue;
138 for (j = 0; j < ARRAY_SIZE(dif_list); ++j)
140 if (!SetupDiCallClassInstaller(dif_list[j], set, &device) && GetLastError() != ERROR_DI_DO_DEFAULT)
141 break;
145 SetupDiDestroyDeviceInfoList(set);
146 free(device_ids);
147 return TRUE;
151 /***********************************************************************
152 * DiInstallDriverA (NEWDEV.@)
154 BOOL WINAPI DiInstallDriverA(HWND parent, const char *inf_path, DWORD flags, BOOL *reboot)
156 FIXME("parent %p, inf_path %s, flags %#lx, reboot %p, stub!\n", parent, debugstr_a(inf_path), flags, reboot);
157 return TRUE;
160 /***********************************************************************
161 * DiInstallDriverW (NEWDEV.@)
163 BOOL WINAPI DiInstallDriverW(HWND parent, const WCHAR *inf_path, DWORD flags, BOOL *reboot)
165 FIXME("parent %p, inf_path %s, flags %#lx, reboot %p, stub!\n", parent, debugstr_w(inf_path), flags, reboot);
166 return TRUE;