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"
33 #include "wine/heap.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(setupapi
);
37 /***********************************************************************
38 * InstallNewDevice (NEWDEV.@)
40 BOOL WINAPI
InstallNewDevice(HWND hwndParent
, LPGUID ClassGuid
, PDWORD pReboot
)
46 /***********************************************************************
47 * InstallSelectedDriver (NEWDEV.@)
49 BOOL WINAPI
InstallSelectedDriver(HWND parent
, HDEVINFO info
, const WCHAR
*reserved
, BOOL backup
, DWORD
*reboot
)
51 FIXME("Stub! %p %p %s %u %p\n", parent
, info
, debugstr_w(reserved
), backup
, reboot
);
55 /***********************************************************************
56 * UpdateDriverForPlugAndPlayDevicesA (NEWDEV.@)
58 BOOL WINAPI
UpdateDriverForPlugAndPlayDevicesA(HWND parent
, const char *hardware_id
,
59 const char *inf_path
, DWORD flags
, BOOL
*reboot
)
61 WCHAR hardware_idW
[MAX_DEVICE_ID_LEN
];
62 WCHAR inf_pathW
[MAX_PATH
];
64 MultiByteToWideChar(CP_ACP
, 0, hardware_id
, -1, hardware_idW
, ARRAY_SIZE(hardware_idW
));
65 MultiByteToWideChar(CP_ACP
, 0, inf_path
, -1, inf_pathW
, ARRAY_SIZE(inf_pathW
));
67 return UpdateDriverForPlugAndPlayDevicesW(parent
, hardware_idW
, inf_pathW
, flags
, reboot
);
70 static BOOL
hardware_id_matches(const WCHAR
*id
, const WCHAR
*device_ids
)
74 if (!wcscmp(id
, device_ids
))
76 device_ids
+= lstrlenW(device_ids
) + 1;
81 /***********************************************************************
82 * UpdateDriverForPlugAndPlayDevicesW (NEWDEV.@)
84 BOOL WINAPI
UpdateDriverForPlugAndPlayDevicesW(HWND parent
, const WCHAR
*hardware_id
,
85 const WCHAR
*inf_path
, DWORD flags
, BOOL
*reboot
)
87 SP_DEVINSTALL_PARAMS_W params
= {sizeof(params
)};
88 SP_DEVINFO_DATA device
= {sizeof(device
)};
89 WCHAR
*device_ids
= NULL
;
93 static const DWORD dif_list
[] =
95 DIF_SELECTBESTCOMPATDRV
,
97 DIF_INSTALLDEVICEFILES
,
98 DIF_REGISTER_COINSTALLERS
,
99 DIF_INSTALLINTERFACES
,
101 DIF_NEWDEVICEWIZARD_FINISHINSTALL
,
104 TRACE("parent %p, hardware_id %s, inf_path %s, flags %#lx, reboot %p.\n",
105 parent
, debugstr_w(hardware_id
), debugstr_w(inf_path
), flags
, reboot
);
108 FIXME("Unhandled flags %#lx.\n", flags
);
110 if (reboot
) *reboot
= FALSE
;
112 if ((set
= SetupDiGetClassDevsW(NULL
, NULL
, 0, DIGCF_ALLCLASSES
)) == INVALID_HANDLE_VALUE
)
115 for (i
= 0; SetupDiEnumDeviceInfo(set
, i
, &device
); ++i
)
117 if (!SetupDiGetDeviceRegistryPropertyW(set
, &device
, SPDRP_HARDWAREID
, NULL
, (BYTE
*)device_ids
, size
, &size
))
119 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
121 device_ids
= heap_realloc(device_ids
, size
);
122 SetupDiGetDeviceRegistryPropertyW(set
, &device
, SPDRP_HARDWAREID
, NULL
, (BYTE
*)device_ids
, size
, NULL
);
125 if (!hardware_id_matches(hardware_id
, device_ids
))
128 if (!SetupDiGetDeviceInstallParamsW(set
, &device
, ¶ms
))
131 lstrcpyW(params
.DriverPath
, inf_path
);
132 params
.Flags
|= DI_ENUMSINGLEINF
;
133 if (!SetupDiSetDeviceInstallParamsW(set
, &device
, ¶ms
))
136 if (!SetupDiBuildDriverInfoList(set
, &device
, SPDIT_COMPATDRIVER
))
139 for (j
= 0; j
< ARRAY_SIZE(dif_list
); ++j
)
141 if (!SetupDiCallClassInstaller(dif_list
[j
], set
, &device
) && GetLastError() != ERROR_DI_DO_DEFAULT
)
146 SetupDiDestroyDeviceInfoList(set
);
147 heap_free(device_ids
);
152 /***********************************************************************
153 * DiInstallDriverA (NEWDEV.@)
155 BOOL WINAPI
DiInstallDriverA(HWND parent
, const char *inf_path
, DWORD flags
, BOOL
*reboot
)
157 FIXME("parent %p, inf_path %s, flags %#lx, reboot %p, stub!\n", parent
, debugstr_a(inf_path
), flags
, reboot
);
161 /***********************************************************************
162 * DiInstallDriverW (NEWDEV.@)
164 BOOL WINAPI
DiInstallDriverW(HWND parent
, const WCHAR
*inf_path
, DWORD flags
, BOOL
*reboot
)
166 FIXME("parent %p, inf_path %s, flags %#lx, reboot %p, stub!\n", parent
, debugstr_w(inf_path
), flags
, reboot
);