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
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
)
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
);
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
)
73 if (!wcscmp(id
, device_ids
))
75 device_ids
+= lstrlenW(device_ids
) + 1;
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
;
92 static const DWORD dif_list
[] =
94 DIF_SELECTBESTCOMPATDRV
,
96 DIF_INSTALLDEVICEFILES
,
97 DIF_REGISTER_COINSTALLERS
,
98 DIF_INSTALLINTERFACES
,
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
);
107 FIXME("Unhandled flags %#lx.\n", flags
);
109 if (reboot
) *reboot
= FALSE
;
111 if ((set
= SetupDiGetClassDevsW(NULL
, NULL
, 0, DIGCF_ALLCLASSES
)) == INVALID_HANDLE_VALUE
)
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
)
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
))
127 if (!SetupDiGetDeviceInstallParamsW(set
, &device
, ¶ms
))
130 lstrcpyW(params
.DriverPath
, inf_path
);
131 params
.Flags
|= DI_ENUMSINGLEINF
;
132 if (!SetupDiSetDeviceInstallParamsW(set
, &device
, ¶ms
))
135 if (!SetupDiBuildDriverInfoList(set
, &device
, SPDIT_COMPATDRIVER
))
138 for (j
= 0; j
< ARRAY_SIZE(dif_list
); ++j
)
140 if (!SetupDiCallClassInstaller(dif_list
[j
], set
, &device
) && GetLastError() != ERROR_DI_DO_DEFAULT
)
145 SetupDiDestroyDeviceInfoList(set
);
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
);
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
);