2000-12-13 22:31:37 +01:00
|
|
|
/*
|
|
|
|
* SetupAPI device installer
|
|
|
|
*
|
2003-09-08 21:38:45 +02:00
|
|
|
* Copyright 2000 Andreas Mohr for CodeWeavers
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-12-13 22:31:37 +01:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2000-12-13 22:31:37 +01:00
|
|
|
#include "windef.h"
|
2001-07-25 02:43:29 +02:00
|
|
|
#include "winbase.h"
|
2004-12-02 19:09:53 +01:00
|
|
|
#include "winnt.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "winternl.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "winnls.h"
|
2019-06-27 05:32:26 +02:00
|
|
|
#include "winsvc.h"
|
2002-05-29 00:39:14 +02:00
|
|
|
#include "setupapi.h"
|
2003-09-11 04:58:46 +02:00
|
|
|
#include "wine/debug.h"
|
2018-07-30 03:26:22 +02:00
|
|
|
#include "wine/heap.h"
|
2007-09-22 02:04:09 +02:00
|
|
|
#include "wine/list.h"
|
2006-10-13 23:05:01 +02:00
|
|
|
#include "cfgmgr32.h"
|
2005-03-01 12:44:27 +01:00
|
|
|
#include "winioctl.h"
|
2004-12-02 19:09:53 +01:00
|
|
|
#include "rpc.h"
|
|
|
|
#include "rpcdce.h"
|
2003-09-11 04:58:46 +02:00
|
|
|
|
2005-02-03 14:34:50 +01:00
|
|
|
#include "setupapi_private.h"
|
|
|
|
|
2000-12-13 22:31:37 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
|
2000-12-13 22:31:37 +01:00
|
|
|
|
2004-12-02 19:09:53 +01:00
|
|
|
/* Unicode constants */
|
2010-10-04 18:16:25 +02:00
|
|
|
static const WCHAR Chicago[] = {'$','C','h','i','c','a','g','o','$',0};
|
2004-12-02 19:09:53 +01:00
|
|
|
static const WCHAR ClassGUID[] = {'C','l','a','s','s','G','U','I','D',0};
|
|
|
|
static const WCHAR Class[] = {'C','l','a','s','s',0};
|
|
|
|
static const WCHAR ClassInstall32[] = {'C','l','a','s','s','I','n','s','t','a','l','l','3','2',0};
|
|
|
|
static const WCHAR NoDisplayClass[] = {'N','o','D','i','s','p','l','a','y','C','l','a','s','s',0};
|
2007-09-18 18:50:50 +02:00
|
|
|
static const WCHAR NoInstallClass[] = {'N','o','I','n','s','t','a','l','l','C','l','a','s','s',0};
|
2004-12-02 19:09:53 +01:00
|
|
|
static const WCHAR NoUseClass[] = {'N','o','U','s','e','C','l','a','s','s',0};
|
|
|
|
static const WCHAR NtExtension[] = {'.','N','T',0};
|
2019-05-17 07:21:08 +02:00
|
|
|
#ifdef __i386__
|
2004-12-02 19:09:53 +01:00
|
|
|
static const WCHAR NtPlatformExtension[] = {'.','N','T','x','8','6',0};
|
2019-05-17 07:21:08 +02:00
|
|
|
#elif defined(__x86_64__)
|
|
|
|
static const WCHAR NtPlatformExtension[] = {'.','N','T','a','m','d','6','4',0};
|
|
|
|
#elif defined(__arm__)
|
|
|
|
static const WCHAR NtPlatformExtension[] = {'.','N','T','a','r','m',0};
|
|
|
|
#elif defined(__aarch64__)
|
|
|
|
static const WCHAR NtPlatformExtension[] = {'.','N','T','a','r','m','6','4',0};
|
|
|
|
#endif
|
2010-10-04 18:16:25 +02:00
|
|
|
static const WCHAR Signature[] = {'S','i','g','n','a','t','u','r','e',0};
|
2004-12-02 19:09:53 +01:00
|
|
|
static const WCHAR Version[] = {'V','e','r','s','i','o','n',0};
|
|
|
|
static const WCHAR WinExtension[] = {'.','W','i','n',0};
|
2013-12-17 21:42:00 +01:00
|
|
|
static const WCHAR WindowsNT[] = {'$','W','i','n','d','o','w','s',' ','N','T','$',0};
|
2004-12-02 19:09:53 +01:00
|
|
|
|
|
|
|
/* Registry key and value names */
|
|
|
|
static const WCHAR ControlClass[] = {'S','y','s','t','e','m','\\',
|
|
|
|
'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
|
|
|
|
'C','o','n','t','r','o','l','\\',
|
|
|
|
'C','l','a','s','s',0};
|
|
|
|
|
|
|
|
static const WCHAR DeviceClasses[] = {'S','y','s','t','e','m','\\',
|
|
|
|
'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
|
|
|
|
'C','o','n','t','r','o','l','\\',
|
|
|
|
'D','e','v','i','c','e','C','l','a','s','s','e','s',0};
|
2007-09-20 18:10:10 +02:00
|
|
|
static const WCHAR Enum[] = {'S','y','s','t','e','m','\\',
|
|
|
|
'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
|
|
|
|
'E','n','u','m',0};
|
|
|
|
static const WCHAR DeviceDesc[] = {'D','e','v','i','c','e','D','e','s','c',0};
|
2007-09-20 18:16:45 +02:00
|
|
|
static const WCHAR DeviceInstance[] = {'D','e','v','i','c','e','I','n','s','t','a','n','c','e',0};
|
2018-07-30 03:26:28 +02:00
|
|
|
static const WCHAR DeviceParameters[] = {'D','e','v','i','c','e',' ','P','a','r','a','m','e','t','e','r','s',0};
|
2007-09-20 18:10:10 +02:00
|
|
|
static const WCHAR HardwareId[] = {'H','a','r','d','w','a','r','e','I','D',0};
|
|
|
|
static const WCHAR CompatibleIDs[] = {'C','o','m','p','a','t','i','b','l','e','I','d','s',0};
|
|
|
|
static const WCHAR Service[] = {'S','e','r','v','i','c','e',0};
|
|
|
|
static const WCHAR Driver[] = {'D','r','i','v','e','r',0};
|
|
|
|
static const WCHAR ConfigFlags[] = {'C','o','n','f','i','g','F','l','a','g','s',0};
|
|
|
|
static const WCHAR Mfg[] = {'M','f','g',0};
|
|
|
|
static const WCHAR FriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
|
|
|
|
static const WCHAR LocationInformation[] = {'L','o','c','a','t','i','o','n','I','n','f','o','r','m','a','t','i','o','n',0};
|
|
|
|
static const WCHAR Capabilities[] = {'C','a','p','a','b','i','l','i','t','i','e','s',0};
|
|
|
|
static const WCHAR UINumber[] = {'U','I','N','u','m','b','e','r',0};
|
|
|
|
static const WCHAR UpperFilters[] = {'U','p','p','e','r','F','i','l','t','e','r','s',0};
|
|
|
|
static const WCHAR LowerFilters[] = {'L','o','w','e','r','F','i','l','t','e','r','s',0};
|
2007-09-20 18:14:53 +02:00
|
|
|
static const WCHAR Phantom[] = {'P','h','a','n','t','o','m',0};
|
2007-09-21 20:37:09 +02:00
|
|
|
static const WCHAR SymbolicLink[] = {'S','y','m','b','o','l','i','c','L','i','n','k',0};
|
2018-08-17 01:37:38 +02:00
|
|
|
static const WCHAR Control[] = {'C','o','n','t','r','o','l',0};
|
|
|
|
static const WCHAR Linked[] = {'L','i','n','k','e','d',0};
|
2019-05-23 05:55:55 +02:00
|
|
|
static const WCHAR dotInterfaces[] = {'.','I','n','t','e','r','f','a','c','e','s',0};
|
|
|
|
static const WCHAR AddInterface[] = {'A','d','d','I','n','t','e','r','f','a','c','e',0};
|
2019-05-21 06:55:45 +02:00
|
|
|
static const WCHAR backslashW[] = {'\\',0};
|
2018-11-27 02:26:43 +01:00
|
|
|
static const WCHAR emptyW[] = {0};
|
2004-12-02 19:09:53 +01:00
|
|
|
|
2019-05-21 06:55:43 +02:00
|
|
|
struct driver
|
|
|
|
{
|
|
|
|
WCHAR inf_path[MAX_PATH];
|
|
|
|
WCHAR manufacturer[LINE_LEN];
|
2019-05-22 18:15:37 +02:00
|
|
|
WCHAR mfg_key[LINE_LEN];
|
2019-05-21 06:55:43 +02:00
|
|
|
WCHAR description[LINE_LEN];
|
|
|
|
};
|
|
|
|
|
2006-06-13 19:13:32 +02:00
|
|
|
/* is used to identify if a DeviceInfoSet pointer is
|
|
|
|
valid or not */
|
|
|
|
#define SETUP_DEVICE_INFO_SET_MAGIC 0xd00ff056
|
|
|
|
|
|
|
|
struct DeviceInfoSet
|
|
|
|
{
|
|
|
|
DWORD magic; /* if is equal to SETUP_DEVICE_INFO_SET_MAGIC struct is okay */
|
|
|
|
GUID ClassGuid;
|
|
|
|
HWND hwndParent;
|
2008-04-03 17:19:40 +02:00
|
|
|
struct list devices;
|
|
|
|
};
|
|
|
|
|
2018-07-30 03:26:24 +02:00
|
|
|
struct device
|
2008-04-03 17:19:40 +02:00
|
|
|
{
|
2018-07-30 03:26:24 +02:00
|
|
|
struct DeviceInfoSet *set;
|
|
|
|
HKEY key;
|
|
|
|
BOOL phantom;
|
|
|
|
WCHAR *instanceId;
|
|
|
|
struct list interfaces;
|
2018-07-30 03:26:25 +02:00
|
|
|
GUID class;
|
|
|
|
DEVINST devnode;
|
2018-07-30 03:26:24 +02:00
|
|
|
struct list entry;
|
2018-11-30 23:42:12 +01:00
|
|
|
BOOL removed;
|
2019-05-16 05:56:06 +02:00
|
|
|
SP_DEVINSTALL_PARAMS_W params;
|
2019-05-21 06:55:43 +02:00
|
|
|
struct driver *drivers;
|
|
|
|
unsigned int driver_count;
|
|
|
|
struct driver *selected_driver;
|
2006-06-13 19:13:32 +02:00
|
|
|
};
|
2006-06-09 07:25:31 +02:00
|
|
|
|
2018-07-30 03:26:27 +02:00
|
|
|
struct device_iface
|
2007-09-21 20:36:12 +02:00
|
|
|
{
|
2018-07-30 03:26:27 +02:00
|
|
|
WCHAR *refstr;
|
|
|
|
WCHAR *symlink;
|
2018-07-30 03:26:25 +02:00
|
|
|
struct device *device;
|
2018-07-30 03:26:27 +02:00
|
|
|
GUID class;
|
|
|
|
DWORD flags;
|
2018-11-27 02:26:43 +01:00
|
|
|
HKEY class_key;
|
|
|
|
HKEY refstr_key;
|
2018-07-30 03:26:27 +02:00
|
|
|
struct list entry;
|
2007-09-21 20:36:12 +02:00
|
|
|
};
|
|
|
|
|
2018-11-26 00:31:48 +01:00
|
|
|
static struct DeviceInfoSet *get_device_set(HDEVINFO devinfo)
|
2018-11-26 00:31:46 +01:00
|
|
|
{
|
|
|
|
struct DeviceInfoSet *set = devinfo;
|
|
|
|
|
|
|
|
if (!devinfo || devinfo == INVALID_HANDLE_VALUE || set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-11-26 00:31:48 +01:00
|
|
|
return set;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct device *get_device(HDEVINFO devinfo, const SP_DEVINFO_DATA *data)
|
|
|
|
{
|
|
|
|
struct DeviceInfoSet *set;
|
|
|
|
struct device *device;
|
|
|
|
|
|
|
|
if (!(set = get_device_set(devinfo)))
|
|
|
|
return FALSE;
|
|
|
|
|
2018-11-26 00:31:46 +01:00
|
|
|
if (!data || data->cbSize != sizeof(*data) || !data->Reserved)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
device = (struct device *)data->Reserved;
|
|
|
|
|
|
|
|
if (device->set != set)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-11-30 23:42:12 +01:00
|
|
|
if (device->removed)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_NO_SUCH_DEVINST);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-11-26 00:31:46 +01:00
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
2018-11-26 00:31:47 +01:00
|
|
|
static struct device_iface *get_device_iface(HDEVINFO devinfo, const SP_DEVICE_INTERFACE_DATA *data)
|
|
|
|
{
|
2018-11-26 00:31:48 +01:00
|
|
|
if (!get_device_set(devinfo))
|
|
|
|
return FALSE;
|
2018-11-26 00:31:47 +01:00
|
|
|
|
|
|
|
if (!data || data->cbSize != sizeof(*data) || !data->Reserved)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (struct device_iface *)data->Reserved;
|
|
|
|
}
|
|
|
|
|
2018-07-30 03:26:25 +02:00
|
|
|
static inline void copy_device_data(SP_DEVINFO_DATA *data, const struct device *device)
|
|
|
|
{
|
|
|
|
data->ClassGuid = device->class;
|
|
|
|
data->DevInst = device->devnode;
|
|
|
|
data->Reserved = (ULONG_PTR)device;
|
|
|
|
}
|
|
|
|
|
2018-07-30 03:26:27 +02:00
|
|
|
static inline void copy_device_iface_data(SP_DEVICE_INTERFACE_DATA *data,
|
|
|
|
const struct device_iface *iface)
|
|
|
|
{
|
|
|
|
data->InterfaceClassGuid = iface->class;
|
|
|
|
data->Flags = iface->flags;
|
|
|
|
data->Reserved = (ULONG_PTR)iface;
|
|
|
|
}
|
|
|
|
|
2018-07-30 03:26:24 +02:00
|
|
|
static struct device **devnode_table;
|
2018-07-30 03:26:22 +02:00
|
|
|
static unsigned int devnode_table_size;
|
|
|
|
|
2018-07-30 03:26:24 +02:00
|
|
|
static DEVINST alloc_devnode(struct device *device)
|
2018-07-30 03:26:22 +02:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < devnode_table_size; ++i)
|
|
|
|
{
|
|
|
|
if (!devnode_table[i])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == devnode_table_size)
|
|
|
|
{
|
|
|
|
if (devnode_table)
|
|
|
|
{
|
|
|
|
devnode_table_size *= 2;
|
|
|
|
devnode_table = heap_realloc_zero(devnode_table,
|
|
|
|
devnode_table_size * sizeof(*devnode_table));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
devnode_table_size = 256;
|
|
|
|
devnode_table = heap_alloc_zero(devnode_table_size * sizeof(*devnode_table));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
devnode_table[i] = device;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_devnode(DEVINST devnode)
|
|
|
|
{
|
|
|
|
devnode_table[devnode] = NULL;
|
|
|
|
}
|
|
|
|
|
2018-07-30 03:26:24 +02:00
|
|
|
static struct device *get_devnode_device(DEVINST devnode)
|
2018-07-30 03:26:22 +02:00
|
|
|
{
|
|
|
|
if (devnode < devnode_table_size)
|
|
|
|
return devnode_table[devnode];
|
|
|
|
|
|
|
|
WARN("device node %u not found\n", devnode);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-09-21 20:56:45 +02:00
|
|
|
static void SETUPDI_GuidToString(const GUID *guid, LPWSTR guidStr)
|
|
|
|
{
|
|
|
|
static const WCHAR fmt[] = {'{','%','0','8','X','-','%','0','4','X','-',
|
|
|
|
'%','0','4','X','-','%','0','2','X','%','0','2','X','-','%','0','2',
|
|
|
|
'X','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','%',
|
|
|
|
'0','2','X','}',0};
|
|
|
|
|
2019-07-04 15:41:03 +02:00
|
|
|
swprintf(guidStr, 39, fmt, guid->Data1, guid->Data2, guid->Data3,
|
2007-09-21 20:56:45 +02:00
|
|
|
guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
|
|
|
|
guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
|
|
|
|
}
|
|
|
|
|
2018-07-30 03:26:27 +02:00
|
|
|
static WCHAR *get_iface_key_path(struct device_iface *iface)
|
2018-07-30 03:26:26 +02:00
|
|
|
{
|
2018-11-30 08:14:19 +01:00
|
|
|
static const WCHAR slashW[] = {'\\',0};
|
2018-07-30 03:26:26 +02:00
|
|
|
WCHAR *path, *ptr;
|
2019-07-04 15:41:03 +02:00
|
|
|
size_t len = lstrlenW(DeviceClasses) + 1 + 38 + 1 + lstrlenW(iface->symlink);
|
2018-07-30 03:26:26 +02:00
|
|
|
|
|
|
|
if (!(path = heap_alloc((len + 1) * sizeof(WCHAR))))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcpyW(path, DeviceClasses);
|
|
|
|
lstrcatW(path, slashW);
|
|
|
|
SETUPDI_GuidToString(&iface->class, path + lstrlenW(path));
|
|
|
|
lstrcatW(path, slashW);
|
|
|
|
ptr = path + lstrlenW(path);
|
|
|
|
lstrcatW(path, iface->symlink);
|
|
|
|
if (lstrlenW(iface->symlink) > 3)
|
2018-07-30 03:26:26 +02:00
|
|
|
ptr[0] = ptr[1] = ptr[3] = '#';
|
|
|
|
|
2019-07-04 15:41:03 +02:00
|
|
|
ptr = wcschr(ptr, '\\');
|
2018-07-30 03:26:26 +02:00
|
|
|
if (ptr) *ptr = 0;
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2018-07-30 03:26:27 +02:00
|
|
|
static WCHAR *get_refstr_key_path(struct device_iface *iface)
|
2018-07-30 03:26:26 +02:00
|
|
|
{
|
2018-11-30 08:14:19 +01:00
|
|
|
static const WCHAR hashW[] = {'#',0};
|
|
|
|
static const WCHAR slashW[] = {'\\',0};
|
2018-07-30 03:26:26 +02:00
|
|
|
WCHAR *path, *ptr;
|
2019-07-04 15:41:03 +02:00
|
|
|
size_t len = lstrlenW(DeviceClasses) + 1 + 38 + 1 + lstrlenW(iface->symlink) + 1 + 1;
|
2018-07-30 03:26:26 +02:00
|
|
|
|
2018-07-30 03:26:27 +02:00
|
|
|
if (iface->refstr)
|
2019-07-04 15:41:03 +02:00
|
|
|
len += lstrlenW(iface->refstr);
|
2018-07-30 03:26:26 +02:00
|
|
|
|
|
|
|
if (!(path = heap_alloc((len + 1) * sizeof(WCHAR))))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcpyW(path, DeviceClasses);
|
|
|
|
lstrcatW(path, slashW);
|
|
|
|
SETUPDI_GuidToString(&iface->class, path + lstrlenW(path));
|
|
|
|
lstrcatW(path, slashW);
|
|
|
|
ptr = path + lstrlenW(path);
|
|
|
|
lstrcatW(path, iface->symlink);
|
|
|
|
if (lstrlenW(iface->symlink) > 3)
|
2018-07-30 03:26:26 +02:00
|
|
|
ptr[0] = ptr[1] = ptr[3] = '#';
|
|
|
|
|
2019-07-04 15:41:03 +02:00
|
|
|
ptr = wcschr(ptr, '\\');
|
2018-07-30 03:26:26 +02:00
|
|
|
if (ptr) *ptr = 0;
|
|
|
|
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcatW(path, slashW);
|
|
|
|
lstrcatW(path, hashW);
|
2018-07-30 03:26:26 +02:00
|
|
|
|
2018-07-30 03:26:27 +02:00
|
|
|
if (iface->refstr)
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcatW(path, iface->refstr);
|
2018-07-30 03:26:26 +02:00
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2019-01-30 04:21:18 +01:00
|
|
|
static BOOL is_valid_property_type(DEVPROPTYPE prop_type)
|
|
|
|
{
|
|
|
|
DWORD type = prop_type & DEVPROP_MASK_TYPE;
|
|
|
|
DWORD typemod = prop_type & DEVPROP_MASK_TYPEMOD;
|
|
|
|
|
|
|
|
if (type > MAX_DEVPROP_TYPE)
|
|
|
|
return FALSE;
|
|
|
|
if (typemod > MAX_DEVPROP_TYPEMOD)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (typemod == DEVPROP_TYPEMOD_ARRAY
|
|
|
|
&& (type == DEVPROP_TYPE_EMPTY || type == DEVPROP_TYPE_NULL || type == DEVPROP_TYPE_STRING
|
|
|
|
|| type == DEVPROP_TYPE_SECURITY_DESCRIPTOR_STRING))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (typemod == DEVPROP_TYPEMOD_LIST
|
|
|
|
&& !(type == DEVPROP_TYPE_STRING || type == DEVPROP_TYPE_SECURITY_DESCRIPTOR_STRING))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-09-21 20:56:45 +02:00
|
|
|
static LPWSTR SETUPDI_CreateSymbolicLinkPath(LPCWSTR instanceId,
|
|
|
|
const GUID *InterfaceClassGuid, LPCWSTR ReferenceString)
|
|
|
|
{
|
|
|
|
static const WCHAR fmt[] = {'\\','\\','?','\\','%','s','#','%','s',0};
|
|
|
|
WCHAR guidStr[39];
|
|
|
|
DWORD len;
|
|
|
|
LPWSTR ret;
|
|
|
|
|
|
|
|
SETUPDI_GuidToString(InterfaceClassGuid, guidStr);
|
|
|
|
/* omit length of format specifiers, but include NULL terminator: */
|
|
|
|
len = lstrlenW(fmt) - 4 + 1;
|
|
|
|
len += lstrlenW(instanceId) + lstrlenW(guidStr);
|
2008-04-01 13:24:50 +02:00
|
|
|
if (ReferenceString && *ReferenceString)
|
2007-09-21 20:56:45 +02:00
|
|
|
{
|
|
|
|
/* space for a hash between string and reference string: */
|
|
|
|
len += lstrlenW(ReferenceString) + 1;
|
|
|
|
}
|
|
|
|
ret = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
if (ret)
|
|
|
|
{
|
2019-07-04 15:41:03 +02:00
|
|
|
int printed = swprintf(ret, len, fmt, instanceId, guidStr);
|
2007-09-21 20:56:45 +02:00
|
|
|
LPWSTR ptr;
|
|
|
|
|
|
|
|
/* replace '\\' with '#' after the "\\\\?\\" beginning */
|
2019-07-04 15:41:03 +02:00
|
|
|
for (ptr = wcschr(ret + 4, '\\'); ptr; ptr = wcschr(ptr + 1, '\\'))
|
2007-09-21 20:56:45 +02:00
|
|
|
*ptr = '#';
|
2008-04-01 13:24:50 +02:00
|
|
|
if (ReferenceString && *ReferenceString)
|
2007-09-21 20:56:45 +02:00
|
|
|
{
|
2008-04-01 13:24:50 +02:00
|
|
|
ret[printed] = '\\';
|
|
|
|
lstrcpyW(ret + printed + 1, ReferenceString);
|
2007-09-21 20:56:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-08-17 01:37:38 +02:00
|
|
|
static BOOL is_linked(HKEY key)
|
|
|
|
{
|
|
|
|
DWORD linked, type, size;
|
|
|
|
HKEY control_key;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
if (!RegOpenKeyW(key, Control, &control_key))
|
|
|
|
{
|
|
|
|
size = sizeof(DWORD);
|
|
|
|
if (!RegQueryValueExW(control_key, Linked, NULL, &type, (BYTE *)&linked, &size)
|
|
|
|
&& type == REG_DWORD && linked)
|
|
|
|
ret = TRUE;
|
|
|
|
|
|
|
|
RegCloseKey(control_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-07-30 03:26:27 +02:00
|
|
|
static struct device_iface *SETUPDI_CreateDeviceInterface(struct device *device,
|
|
|
|
const GUID *class, const WCHAR *refstr)
|
2007-09-21 20:36:12 +02:00
|
|
|
{
|
2018-07-30 03:26:27 +02:00
|
|
|
struct device_iface *iface = NULL;
|
|
|
|
WCHAR *refstr2 = NULL, *symlink = NULL, *path = NULL;
|
2018-11-27 02:26:43 +01:00
|
|
|
HKEY key;
|
2018-07-30 03:26:27 +02:00
|
|
|
LONG ret;
|
2007-09-21 20:36:12 +02:00
|
|
|
|
2018-07-30 03:26:27 +02:00
|
|
|
TRACE("%p %s %s\n", device, debugstr_guid(class), debugstr_w(refstr));
|
2007-09-21 20:36:12 +02:00
|
|
|
|
2018-07-30 03:26:27 +02:00
|
|
|
/* check if it already exists */
|
|
|
|
LIST_FOR_EACH_ENTRY(iface, &device->interfaces, struct device_iface, entry)
|
2007-09-21 20:36:12 +02:00
|
|
|
{
|
2018-07-30 03:26:27 +02:00
|
|
|
if (IsEqualGUID(&iface->class, class) && !lstrcmpiW(iface->refstr, refstr))
|
|
|
|
return iface;
|
2007-09-21 20:36:12 +02:00
|
|
|
}
|
|
|
|
|
2018-07-30 03:26:27 +02:00
|
|
|
iface = heap_alloc(sizeof(*iface));
|
|
|
|
symlink = SETUPDI_CreateSymbolicLinkPath(device->instanceId, class, refstr);
|
2007-09-21 20:36:12 +02:00
|
|
|
|
2018-07-30 03:26:27 +02:00
|
|
|
if (!iface || !symlink)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
goto err;
|
|
|
|
}
|
2007-09-21 20:36:12 +02:00
|
|
|
|
2018-07-30 03:26:27 +02:00
|
|
|
if (refstr && !(refstr2 = strdupW(refstr)))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
iface->refstr = refstr2;
|
|
|
|
iface->symlink = symlink;
|
|
|
|
iface->device = device;
|
|
|
|
iface->class = *class;
|
2018-08-17 01:37:38 +02:00
|
|
|
iface->flags = 0;
|
2018-07-30 03:26:26 +02:00
|
|
|
|
2018-07-30 03:26:27 +02:00
|
|
|
if (!(path = get_iface_key_path(iface)))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
goto err;
|
2007-09-21 20:36:12 +02:00
|
|
|
}
|
|
|
|
|
2018-07-30 03:26:27 +02:00
|
|
|
if ((ret = RegCreateKeyW(HKEY_LOCAL_MACHINE, path, &key)))
|
|
|
|
{
|
|
|
|
SetLastError(ret);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
RegSetValueExW(key, DeviceInstance, 0, REG_SZ, (BYTE *)device->instanceId,
|
|
|
|
lstrlenW(device->instanceId) * sizeof(WCHAR));
|
|
|
|
heap_free(path);
|
2007-09-21 20:37:09 +02:00
|
|
|
|
2018-11-27 02:26:43 +01:00
|
|
|
iface->class_key = key;
|
|
|
|
|
2018-07-30 03:26:27 +02:00
|
|
|
if (!(path = get_refstr_key_path(iface)))
|
2007-09-21 20:37:09 +02:00
|
|
|
{
|
2018-07-30 03:26:27 +02:00
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
goto err;
|
2007-09-21 20:37:09 +02:00
|
|
|
}
|
2018-07-30 03:26:27 +02:00
|
|
|
|
|
|
|
if ((ret = RegCreateKeyW(HKEY_LOCAL_MACHINE, path, &key)))
|
|
|
|
{
|
|
|
|
SetLastError(ret);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
RegSetValueExW(key, SymbolicLink, 0, REG_SZ, (BYTE *)iface->symlink,
|
|
|
|
lstrlenW(iface->symlink) * sizeof(WCHAR));
|
2018-08-17 01:37:38 +02:00
|
|
|
|
|
|
|
if (is_linked(key))
|
|
|
|
iface->flags |= SPINT_ACTIVE;
|
|
|
|
|
2018-07-30 03:26:27 +02:00
|
|
|
heap_free(path);
|
|
|
|
|
2018-11-27 02:26:43 +01:00
|
|
|
iface->refstr_key = key;
|
|
|
|
|
2018-07-30 03:26:27 +02:00
|
|
|
list_add_tail(&device->interfaces, &iface->entry);
|
|
|
|
return iface;
|
|
|
|
|
|
|
|
err:
|
|
|
|
heap_free(iface);
|
|
|
|
heap_free(refstr2);
|
|
|
|
heap_free(symlink);
|
|
|
|
heap_free(path);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL SETUPDI_SetInterfaceSymbolicLink(struct device_iface *iface,
|
|
|
|
const WCHAR *symlink)
|
|
|
|
{
|
|
|
|
heap_free(iface->symlink);
|
|
|
|
if ((iface->symlink = strdupW(symlink)))
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
2007-09-21 20:37:09 +02:00
|
|
|
}
|
|
|
|
|
2018-07-30 03:26:24 +02:00
|
|
|
static HKEY SETUPDI_CreateDevKey(struct device *device)
|
2007-10-11 22:24:42 +02:00
|
|
|
{
|
|
|
|
HKEY enumKey, key = INVALID_HANDLE_VALUE;
|
|
|
|
LONG l;
|
|
|
|
|
|
|
|
l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_ALL_ACCESS,
|
|
|
|
NULL, &enumKey, NULL);
|
|
|
|
if (!l)
|
|
|
|
{
|
2018-07-30 03:26:24 +02:00
|
|
|
RegCreateKeyExW(enumKey, device->instanceId, 0, NULL, 0,
|
2007-10-11 22:24:42 +02:00
|
|
|
KEY_READ | KEY_WRITE, NULL, &key, NULL);
|
|
|
|
RegCloseKey(enumKey);
|
|
|
|
}
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
2019-02-25 05:08:18 +01:00
|
|
|
static LONG open_driver_key(struct device *device, REGSAM access, HKEY *key)
|
2007-10-11 22:25:52 +02:00
|
|
|
{
|
2019-02-25 05:08:18 +01:00
|
|
|
HKEY class_key;
|
2019-01-23 05:10:29 +01:00
|
|
|
WCHAR path[50];
|
|
|
|
DWORD size = sizeof(path);
|
|
|
|
LONG l;
|
|
|
|
|
|
|
|
if ((l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, ControlClass, 0, NULL, 0,
|
|
|
|
KEY_CREATE_SUB_KEY, NULL, &class_key, NULL)))
|
|
|
|
{
|
|
|
|
ERR("Failed to open driver class root key, error %u.\n", l);
|
2019-02-25 05:08:18 +01:00
|
|
|
return l;
|
2019-01-23 05:10:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(l = RegGetValueW(device->key, NULL, Driver, RRF_RT_REG_SZ, NULL, path, &size)))
|
|
|
|
{
|
2019-02-25 05:08:18 +01:00
|
|
|
if (!(l = RegOpenKeyExW(class_key, path, 0, access, key)))
|
2019-01-23 05:10:29 +01:00
|
|
|
{
|
|
|
|
RegCloseKey(class_key);
|
2019-02-25 05:08:18 +01:00
|
|
|
return l;
|
2019-01-23 05:10:29 +01:00
|
|
|
}
|
|
|
|
ERR("Failed to open driver key, error %u.\n", l);
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(class_key);
|
2019-02-25 05:08:18 +01:00
|
|
|
return l;
|
2019-01-23 05:10:29 +01:00
|
|
|
}
|
|
|
|
|
2019-02-25 05:08:20 +01:00
|
|
|
static LONG create_driver_key(struct device *device, HKEY *key)
|
2019-01-23 05:10:29 +01:00
|
|
|
{
|
|
|
|
static const WCHAR formatW[] = {'%','0','4','u',0};
|
2007-10-11 22:25:52 +02:00
|
|
|
static const WCHAR slash[] = { '\\',0 };
|
2019-01-23 05:10:30 +01:00
|
|
|
unsigned int i = 0;
|
2019-01-23 05:10:29 +01:00
|
|
|
WCHAR path[50];
|
2019-02-25 05:08:20 +01:00
|
|
|
HKEY class_key;
|
2019-01-23 05:10:30 +01:00
|
|
|
DWORD dispos;
|
2007-10-11 22:25:52 +02:00
|
|
|
LONG l;
|
|
|
|
|
2019-02-25 05:08:20 +01:00
|
|
|
if (!open_driver_key(device, KEY_READ | KEY_WRITE, key))
|
|
|
|
return ERROR_SUCCESS;
|
2019-01-23 05:10:29 +01:00
|
|
|
|
|
|
|
if ((l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, ControlClass, 0, NULL, 0,
|
|
|
|
KEY_CREATE_SUB_KEY, NULL, &class_key, NULL)))
|
2007-10-11 22:25:52 +02:00
|
|
|
{
|
2019-01-23 05:10:29 +01:00
|
|
|
ERR("Failed to open driver class root key, error %u.\n", l);
|
2019-02-25 05:08:20 +01:00
|
|
|
return l;
|
2019-01-23 05:10:29 +01:00
|
|
|
}
|
2007-10-11 22:25:52 +02:00
|
|
|
|
2019-01-23 05:10:29 +01:00
|
|
|
SETUPDI_GuidToString(&device->class, path);
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcatW(path, slash);
|
2019-01-23 05:10:30 +01:00
|
|
|
/* Allocate a new driver key, by finding the first integer value that's not
|
|
|
|
* already taken. */
|
|
|
|
for (;;)
|
2019-01-23 05:10:29 +01:00
|
|
|
{
|
2019-07-04 15:41:03 +02:00
|
|
|
swprintf(path + 39, ARRAY_SIZE(path) - 39, formatW, i++);
|
2019-02-25 05:08:20 +01:00
|
|
|
if ((l = RegCreateKeyExW(class_key, path, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, key, &dispos)))
|
2019-01-23 05:10:30 +01:00
|
|
|
break;
|
|
|
|
else if (dispos == REG_CREATED_NEW_KEY)
|
|
|
|
{
|
2019-07-04 15:41:03 +02:00
|
|
|
RegSetValueExW(device->key, Driver, 0, REG_SZ, (BYTE *)path, lstrlenW(path) * sizeof(WCHAR));
|
2019-01-23 05:10:30 +01:00
|
|
|
RegCloseKey(class_key);
|
2019-02-25 05:08:20 +01:00
|
|
|
return ERROR_SUCCESS;
|
2019-01-23 05:10:30 +01:00
|
|
|
}
|
2019-02-25 05:08:20 +01:00
|
|
|
RegCloseKey(*key);
|
2007-10-11 22:25:52 +02:00
|
|
|
}
|
2019-01-23 05:10:29 +01:00
|
|
|
ERR("Failed to create driver key, error %u.\n", l);
|
|
|
|
RegCloseKey(class_key);
|
2019-02-25 05:08:20 +01:00
|
|
|
return l;
|
2019-01-23 05:10:29 +01:00
|
|
|
}
|
|
|
|
|
2019-02-25 05:08:19 +01:00
|
|
|
static LONG delete_driver_key(struct device *device)
|
2019-01-23 05:10:29 +01:00
|
|
|
{
|
|
|
|
HKEY key;
|
|
|
|
LONG l;
|
|
|
|
|
2019-02-25 05:08:18 +01:00
|
|
|
if (!(l = open_driver_key(device, KEY_READ | KEY_WRITE, &key)))
|
2019-01-23 05:10:29 +01:00
|
|
|
{
|
|
|
|
l = RegDeleteKeyW(key, emptyW);
|
|
|
|
RegCloseKey(key);
|
|
|
|
}
|
|
|
|
|
2019-02-25 05:08:19 +01:00
|
|
|
return l;
|
2007-10-11 22:25:52 +02:00
|
|
|
}
|
|
|
|
|
2018-07-30 03:26:23 +02:00
|
|
|
struct PropertyMapEntry
|
|
|
|
{
|
|
|
|
DWORD regType;
|
|
|
|
LPCSTR nameA;
|
|
|
|
LPCWSTR nameW;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct PropertyMapEntry PropertyMap[] = {
|
|
|
|
{ REG_SZ, "DeviceDesc", DeviceDesc },
|
|
|
|
{ REG_MULTI_SZ, "HardwareId", HardwareId },
|
|
|
|
{ REG_MULTI_SZ, "CompatibleIDs", CompatibleIDs },
|
|
|
|
{ 0, NULL, NULL }, /* SPDRP_UNUSED0 */
|
|
|
|
{ REG_SZ, "Service", Service },
|
|
|
|
{ 0, NULL, NULL }, /* SPDRP_UNUSED1 */
|
|
|
|
{ 0, NULL, NULL }, /* SPDRP_UNUSED2 */
|
|
|
|
{ REG_SZ, "Class", Class },
|
|
|
|
{ REG_SZ, "ClassGUID", ClassGUID },
|
|
|
|
{ REG_SZ, "Driver", Driver },
|
|
|
|
{ REG_DWORD, "ConfigFlags", ConfigFlags },
|
|
|
|
{ REG_SZ, "Mfg", Mfg },
|
|
|
|
{ REG_SZ, "FriendlyName", FriendlyName },
|
|
|
|
{ REG_SZ, "LocationInformation", LocationInformation },
|
|
|
|
{ 0, NULL, NULL }, /* SPDRP_PHYSICAL_DEVICE_OBJECT_NAME */
|
|
|
|
{ REG_DWORD, "Capabilities", Capabilities },
|
|
|
|
{ REG_DWORD, "UINumber", UINumber },
|
|
|
|
{ REG_MULTI_SZ, "UpperFilters", UpperFilters },
|
|
|
|
{ REG_MULTI_SZ, "LowerFilters", LowerFilters },
|
|
|
|
};
|
|
|
|
|
2018-07-30 03:26:24 +02:00
|
|
|
static BOOL SETUPDI_SetDeviceRegistryPropertyW(struct device *device,
|
2018-07-30 03:26:23 +02:00
|
|
|
DWORD prop, const BYTE *buffer, DWORD size)
|
|
|
|
{
|
|
|
|
if (prop < ARRAY_SIZE(PropertyMap) && PropertyMap[prop].nameW)
|
|
|
|
{
|
|
|
|
LONG ret = RegSetValueExW(device->key, PropertyMap[prop].nameW, 0,
|
|
|
|
PropertyMap[prop].regType, buffer, size);
|
|
|
|
if (!ret)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
SetLastError(ret);
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-11-30 23:42:10 +01:00
|
|
|
static void remove_device_iface(struct device_iface *iface)
|
|
|
|
{
|
|
|
|
RegDeleteTreeW(iface->refstr_key, NULL);
|
|
|
|
RegDeleteKeyW(iface->refstr_key, emptyW);
|
|
|
|
RegCloseKey(iface->refstr_key);
|
|
|
|
iface->refstr_key = NULL;
|
|
|
|
/* Also remove the class key if it's empty. */
|
|
|
|
RegDeleteKeyW(iface->class_key, emptyW);
|
|
|
|
RegCloseKey(iface->class_key);
|
|
|
|
iface->class_key = NULL;
|
|
|
|
iface->flags |= SPINT_REMOVED;
|
|
|
|
}
|
|
|
|
|
2018-12-04 06:36:14 +01:00
|
|
|
static void delete_device_iface(struct device_iface *iface)
|
|
|
|
{
|
|
|
|
list_remove(&iface->entry);
|
|
|
|
RegCloseKey(iface->refstr_key);
|
|
|
|
RegCloseKey(iface->class_key);
|
|
|
|
heap_free(iface->refstr);
|
|
|
|
heap_free(iface->symlink);
|
|
|
|
heap_free(iface);
|
|
|
|
}
|
|
|
|
|
2018-11-30 23:42:12 +01:00
|
|
|
static void remove_device(struct device *device)
|
|
|
|
{
|
2018-11-30 23:42:13 +01:00
|
|
|
WCHAR id[MAX_DEVICE_ID_LEN], *p;
|
2018-11-30 23:42:12 +01:00
|
|
|
struct device_iface *iface;
|
2018-11-30 23:42:13 +01:00
|
|
|
HKEY enum_key;
|
2018-11-30 23:42:12 +01:00
|
|
|
|
2019-01-23 05:10:32 +01:00
|
|
|
delete_driver_key(device);
|
|
|
|
|
2018-11-30 23:42:12 +01:00
|
|
|
LIST_FOR_EACH_ENTRY(iface, &device->interfaces, struct device_iface, entry)
|
|
|
|
{
|
|
|
|
remove_device_iface(iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
RegDeleteTreeW(device->key, NULL);
|
|
|
|
RegDeleteKeyW(device->key, emptyW);
|
2018-11-30 23:42:13 +01:00
|
|
|
|
|
|
|
/* delete all empty parents of the key */
|
|
|
|
if (!RegOpenKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, 0, &enum_key))
|
|
|
|
{
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcpyW(id, device->instanceId);
|
2018-11-30 23:42:13 +01:00
|
|
|
|
2019-07-04 15:41:03 +02:00
|
|
|
while ((p = wcsrchr(id, '\\')))
|
2018-11-30 23:42:13 +01:00
|
|
|
{
|
|
|
|
*p = 0;
|
|
|
|
RegDeleteKeyW(enum_key, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(enum_key);
|
|
|
|
}
|
|
|
|
|
2018-11-30 23:42:12 +01:00
|
|
|
RegCloseKey(device->key);
|
|
|
|
device->key = NULL;
|
|
|
|
device->removed = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void delete_device(struct device *device)
|
2007-09-20 18:09:18 +02:00
|
|
|
{
|
2018-07-30 03:26:27 +02:00
|
|
|
struct device_iface *iface, *next;
|
2019-05-22 18:15:40 +02:00
|
|
|
SP_DEVINFO_DATA device_data;
|
|
|
|
|
|
|
|
device_data.cbSize = sizeof(device_data);
|
|
|
|
copy_device_data(&device_data, device);
|
|
|
|
SetupDiCallClassInstaller(DIF_DESTROYPRIVATEDATA, device->set, &device_data);
|
2007-09-21 20:36:12 +02:00
|
|
|
|
2018-07-30 03:26:24 +02:00
|
|
|
if (device->phantom)
|
2018-11-30 23:42:12 +01:00
|
|
|
remove_device(device);
|
2007-09-20 18:14:53 +02:00
|
|
|
|
2018-11-30 23:42:12 +01:00
|
|
|
RegCloseKey(device->key);
|
2018-07-30 03:26:24 +02:00
|
|
|
heap_free(device->instanceId);
|
2018-11-30 23:42:12 +01:00
|
|
|
|
2018-07-30 03:26:24 +02:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(iface, next, &device->interfaces,
|
2018-07-30 03:26:27 +02:00
|
|
|
struct device_iface, entry)
|
2007-09-22 02:04:09 +02:00
|
|
|
{
|
2018-12-04 06:36:14 +01:00
|
|
|
delete_device_iface(iface);
|
2007-09-22 02:04:09 +02:00
|
|
|
}
|
2018-07-30 03:26:25 +02:00
|
|
|
free_devnode(device->devnode);
|
2018-07-30 03:26:24 +02:00
|
|
|
list_remove(&device->entry);
|
|
|
|
heap_free(device);
|
2007-09-20 18:09:18 +02:00
|
|
|
}
|
|
|
|
|
2019-05-28 05:13:20 +02:00
|
|
|
/* Create a new device, or return a device already in the set. */
|
|
|
|
static struct device *create_device(struct DeviceInfoSet *set,
|
2018-07-30 03:26:24 +02:00
|
|
|
const GUID *class, const WCHAR *instanceid, BOOL phantom)
|
2007-09-20 18:09:18 +02:00
|
|
|
{
|
2019-03-15 04:41:02 +01:00
|
|
|
const DWORD one = 1;
|
2018-07-30 03:26:24 +02:00
|
|
|
struct device *device;
|
|
|
|
WCHAR guidstr[39];
|
2007-09-20 18:09:18 +02:00
|
|
|
|
2018-07-30 03:26:24 +02:00
|
|
|
TRACE("%p, %s, %s, %d\n", set, debugstr_guid(class),
|
|
|
|
debugstr_w(instanceid), phantom);
|
2007-09-20 18:16:45 +02:00
|
|
|
|
2019-05-28 05:13:20 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(device, &set->devices, struct device, entry)
|
|
|
|
{
|
2019-07-04 15:41:03 +02:00
|
|
|
if (!wcsicmp(instanceid, device->instanceId))
|
2019-05-28 05:13:20 +02:00
|
|
|
{
|
|
|
|
TRACE("Found device %p already in set.\n", device);
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-16 05:56:06 +02:00
|
|
|
if (!(device = heap_alloc_zero(sizeof(*device))))
|
2007-09-20 18:09:18 +02:00
|
|
|
{
|
2018-07-30 03:26:24 +02:00
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-04-03 17:19:40 +02:00
|
|
|
|
2018-07-30 03:26:24 +02:00
|
|
|
if (!(device->instanceId = strdupW(instanceid)))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
heap_free(device);
|
|
|
|
return NULL;
|
2007-09-20 18:09:18 +02:00
|
|
|
}
|
2018-07-30 03:26:24 +02:00
|
|
|
|
2019-07-04 15:41:03 +02:00
|
|
|
wcsupr(device->instanceId);
|
2018-07-30 03:26:24 +02:00
|
|
|
device->set = set;
|
|
|
|
device->key = SETUPDI_CreateDevKey(device);
|
|
|
|
device->phantom = phantom;
|
|
|
|
list_init(&device->interfaces);
|
2018-07-30 03:26:25 +02:00
|
|
|
device->class = *class;
|
|
|
|
device->devnode = alloc_devnode(device);
|
2018-11-30 23:42:12 +01:00
|
|
|
device->removed = FALSE;
|
2018-07-30 03:26:24 +02:00
|
|
|
list_add_tail(&set->devices, &device->entry);
|
2019-05-16 05:56:06 +02:00
|
|
|
device->params.cbSize = sizeof(SP_DEVINSTALL_PARAMS_W);
|
2018-07-30 03:26:24 +02:00
|
|
|
|
2019-03-15 04:41:02 +01:00
|
|
|
if (phantom)
|
|
|
|
RegSetValueExW(device->key, Phantom, 0, REG_DWORD, (const BYTE *)&one, sizeof(one));
|
|
|
|
|
2018-07-30 03:26:24 +02:00
|
|
|
SETUPDI_GuidToString(class, guidstr);
|
|
|
|
SETUPDI_SetDeviceRegistryPropertyW(device, SPDRP_CLASSGUID,
|
|
|
|
(const BYTE *)guidstr, sizeof(guidstr));
|
2019-05-28 05:13:20 +02:00
|
|
|
|
|
|
|
TRACE("Created new device %p.\n", device);
|
2018-07-30 03:26:25 +02:00
|
|
|
return device;
|
2007-09-20 18:09:18 +02:00
|
|
|
}
|
|
|
|
|
2002-06-05 00:12:50 +02:00
|
|
|
/***********************************************************************
|
2004-12-02 19:09:53 +01:00
|
|
|
* SetupDiBuildClassInfoList (SETUPAPI.@)
|
2006-06-09 07:25:31 +02:00
|
|
|
*
|
|
|
|
* Returns a list of setup class GUIDs that identify the classes
|
|
|
|
* that are installed on a local machine.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* Flags [I] control exclusion of classes from the list.
|
|
|
|
* ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
|
|
|
|
* ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
|
|
|
|
* RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE.
|
|
|
|
* Failure: FALSE.
|
2002-06-05 00:12:50 +02:00
|
|
|
*/
|
2004-12-02 19:09:53 +01:00
|
|
|
BOOL WINAPI SetupDiBuildClassInfoList(
|
|
|
|
DWORD Flags,
|
|
|
|
LPGUID ClassGuidList,
|
|
|
|
DWORD ClassGuidListSize,
|
|
|
|
PDWORD RequiredSize)
|
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
return SetupDiBuildClassInfoListExW(Flags, ClassGuidList,
|
|
|
|
ClassGuidListSize, RequiredSize,
|
|
|
|
NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiBuildClassInfoListExA (SETUPAPI.@)
|
2006-06-09 07:25:31 +02:00
|
|
|
*
|
|
|
|
* Returns a list of setup class GUIDs that identify the classes
|
2011-08-02 22:20:32 +02:00
|
|
|
* that are installed on a local or remote machine.
|
2006-06-09 07:25:31 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* Flags [I] control exclusion of classes from the list.
|
|
|
|
* ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
|
|
|
|
* ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
|
|
|
|
* RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
|
|
|
|
* MachineName [I] name of a remote machine.
|
|
|
|
* Reserved [I] must be NULL.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE.
|
|
|
|
* Failure: FALSE.
|
2004-12-02 19:09:53 +01:00
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiBuildClassInfoListExA(
|
|
|
|
DWORD Flags,
|
|
|
|
LPGUID ClassGuidList,
|
|
|
|
DWORD ClassGuidListSize,
|
|
|
|
PDWORD RequiredSize,
|
|
|
|
LPCSTR MachineName,
|
|
|
|
PVOID Reserved)
|
2002-05-29 00:39:14 +02:00
|
|
|
{
|
2005-02-03 14:34:50 +01:00
|
|
|
LPWSTR MachineNameW = NULL;
|
|
|
|
BOOL bResult;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
if (MachineName)
|
|
|
|
{
|
|
|
|
MachineNameW = MultiByteToUnicode(MachineName, CP_ACP);
|
|
|
|
if (MachineNameW == NULL) return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bResult = SetupDiBuildClassInfoListExW(Flags, ClassGuidList,
|
|
|
|
ClassGuidListSize, RequiredSize,
|
|
|
|
MachineNameW, Reserved);
|
|
|
|
|
2006-07-19 19:39:48 +02:00
|
|
|
MyFree(MachineNameW);
|
2005-02-03 14:34:50 +01:00
|
|
|
|
|
|
|
return bResult;
|
2002-05-29 00:39:14 +02:00
|
|
|
}
|
|
|
|
|
2002-06-05 00:12:50 +02:00
|
|
|
/***********************************************************************
|
2006-06-09 07:25:31 +02:00
|
|
|
* SetupDiBuildClassInfoListExW (SETUPAPI.@)
|
|
|
|
*
|
|
|
|
* Returns a list of setup class GUIDs that identify the classes
|
2011-08-02 22:20:32 +02:00
|
|
|
* that are installed on a local or remote machine.
|
2006-06-09 07:25:31 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* Flags [I] control exclusion of classes from the list.
|
|
|
|
* ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
|
|
|
|
* ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
|
|
|
|
* RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
|
|
|
|
* MachineName [I] name of a remote machine.
|
|
|
|
* Reserved [I] must be NULL.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE.
|
|
|
|
* Failure: FALSE.
|
2002-06-05 00:12:50 +02:00
|
|
|
*/
|
2004-12-02 19:09:53 +01:00
|
|
|
BOOL WINAPI SetupDiBuildClassInfoListExW(
|
|
|
|
DWORD Flags,
|
|
|
|
LPGUID ClassGuidList,
|
|
|
|
DWORD ClassGuidListSize,
|
|
|
|
PDWORD RequiredSize,
|
|
|
|
LPCWSTR MachineName,
|
|
|
|
PVOID Reserved)
|
2002-05-29 00:39:14 +02:00
|
|
|
{
|
2004-12-02 19:09:53 +01:00
|
|
|
WCHAR szKeyName[40];
|
|
|
|
HKEY hClassesKey;
|
|
|
|
HKEY hClassKey;
|
|
|
|
DWORD dwLength;
|
|
|
|
DWORD dwIndex;
|
|
|
|
LONG lError;
|
|
|
|
DWORD dwGuidListIndex = 0;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
if (RequiredSize != NULL)
|
|
|
|
*RequiredSize = 0;
|
|
|
|
|
|
|
|
hClassesKey = SetupDiOpenClassRegKeyExW(NULL,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
DIOCR_INSTALLER,
|
|
|
|
MachineName,
|
|
|
|
Reserved);
|
|
|
|
if (hClassesKey == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (dwIndex = 0; ; dwIndex++)
|
|
|
|
{
|
|
|
|
dwLength = 40;
|
|
|
|
lError = RegEnumKeyExW(hClassesKey,
|
|
|
|
dwIndex,
|
|
|
|
szKeyName,
|
|
|
|
&dwLength,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2006-10-13 23:32:50 +02:00
|
|
|
TRACE("RegEnumKeyExW() returns %d\n", lError);
|
2004-12-02 19:09:53 +01:00
|
|
|
if (lError == ERROR_SUCCESS || lError == ERROR_MORE_DATA)
|
|
|
|
{
|
|
|
|
TRACE("Key name: %p\n", szKeyName);
|
|
|
|
|
|
|
|
if (RegOpenKeyExW(hClassesKey,
|
|
|
|
szKeyName,
|
|
|
|
0,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
&hClassKey))
|
|
|
|
{
|
|
|
|
RegCloseKey(hClassesKey);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!RegQueryValueExW(hClassKey,
|
|
|
|
NoUseClass,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL))
|
|
|
|
{
|
|
|
|
TRACE("'NoUseClass' value found!\n");
|
|
|
|
RegCloseKey(hClassKey);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((Flags & DIBCI_NOINSTALLCLASS) &&
|
|
|
|
(!RegQueryValueExW(hClassKey,
|
|
|
|
NoInstallClass,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL)))
|
|
|
|
{
|
|
|
|
TRACE("'NoInstallClass' value found!\n");
|
|
|
|
RegCloseKey(hClassKey);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((Flags & DIBCI_NODISPLAYCLASS) &&
|
|
|
|
(!RegQueryValueExW(hClassKey,
|
|
|
|
NoDisplayClass,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL)))
|
|
|
|
{
|
|
|
|
TRACE("'NoDisplayClass' value found!\n");
|
|
|
|
RegCloseKey(hClassKey);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(hClassKey);
|
|
|
|
|
|
|
|
TRACE("Guid: %p\n", szKeyName);
|
|
|
|
if (dwGuidListIndex < ClassGuidListSize)
|
|
|
|
{
|
2007-06-21 22:56:32 +02:00
|
|
|
if (szKeyName[0] == '{' && szKeyName[37] == '}')
|
2004-12-02 19:09:53 +01:00
|
|
|
{
|
|
|
|
szKeyName[37] = 0;
|
|
|
|
}
|
|
|
|
TRACE("Guid: %p\n", &szKeyName[1]);
|
|
|
|
|
|
|
|
UuidFromStringW(&szKeyName[1],
|
|
|
|
&ClassGuidList[dwGuidListIndex]);
|
|
|
|
}
|
|
|
|
|
|
|
|
dwGuidListIndex++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lError != ERROR_SUCCESS)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(hClassesKey);
|
|
|
|
|
|
|
|
if (RequiredSize != NULL)
|
|
|
|
*RequiredSize = dwGuidListIndex;
|
|
|
|
|
|
|
|
if (ClassGuidListSize < dwGuidListIndex)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiClassGuidsFromNameA (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiClassGuidsFromNameA(
|
|
|
|
LPCSTR ClassName,
|
|
|
|
LPGUID ClassGuidList,
|
|
|
|
DWORD ClassGuidListSize,
|
|
|
|
PDWORD RequiredSize)
|
|
|
|
{
|
|
|
|
return SetupDiClassGuidsFromNameExA(ClassName, ClassGuidList,
|
|
|
|
ClassGuidListSize, RequiredSize,
|
|
|
|
NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiClassGuidsFromNameW (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiClassGuidsFromNameW(
|
|
|
|
LPCWSTR ClassName,
|
|
|
|
LPGUID ClassGuidList,
|
|
|
|
DWORD ClassGuidListSize,
|
|
|
|
PDWORD RequiredSize)
|
|
|
|
{
|
|
|
|
return SetupDiClassGuidsFromNameExW(ClassName, ClassGuidList,
|
|
|
|
ClassGuidListSize, RequiredSize,
|
|
|
|
NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiClassGuidsFromNameExA (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiClassGuidsFromNameExA(
|
|
|
|
LPCSTR ClassName,
|
|
|
|
LPGUID ClassGuidList,
|
|
|
|
DWORD ClassGuidListSize,
|
|
|
|
PDWORD RequiredSize,
|
|
|
|
LPCSTR MachineName,
|
|
|
|
PVOID Reserved)
|
|
|
|
{
|
2005-02-03 14:34:50 +01:00
|
|
|
LPWSTR ClassNameW = NULL;
|
|
|
|
LPWSTR MachineNameW = NULL;
|
|
|
|
BOOL bResult;
|
|
|
|
|
|
|
|
ClassNameW = MultiByteToUnicode(ClassName, CP_ACP);
|
|
|
|
if (ClassNameW == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2006-09-17 10:24:41 +02:00
|
|
|
if (MachineName)
|
2005-02-03 14:34:50 +01:00
|
|
|
{
|
|
|
|
MachineNameW = MultiByteToUnicode(MachineName, CP_ACP);
|
|
|
|
if (MachineNameW == NULL)
|
|
|
|
{
|
|
|
|
MyFree(ClassNameW);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bResult = SetupDiClassGuidsFromNameExW(ClassNameW, ClassGuidList,
|
|
|
|
ClassGuidListSize, RequiredSize,
|
|
|
|
MachineNameW, Reserved);
|
|
|
|
|
2006-07-19 19:39:48 +02:00
|
|
|
MyFree(MachineNameW);
|
2005-02-03 14:34:50 +01:00
|
|
|
MyFree(ClassNameW);
|
|
|
|
|
|
|
|
return bResult;
|
2004-12-02 19:09:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiClassGuidsFromNameExW (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiClassGuidsFromNameExW(
|
|
|
|
LPCWSTR ClassName,
|
|
|
|
LPGUID ClassGuidList,
|
|
|
|
DWORD ClassGuidListSize,
|
|
|
|
PDWORD RequiredSize,
|
|
|
|
LPCWSTR MachineName,
|
|
|
|
PVOID Reserved)
|
|
|
|
{
|
|
|
|
WCHAR szKeyName[40];
|
|
|
|
WCHAR szClassName[256];
|
|
|
|
HKEY hClassesKey;
|
|
|
|
HKEY hClassKey;
|
|
|
|
DWORD dwLength;
|
|
|
|
DWORD dwIndex;
|
|
|
|
LONG lError;
|
|
|
|
DWORD dwGuidListIndex = 0;
|
|
|
|
|
|
|
|
if (RequiredSize != NULL)
|
|
|
|
*RequiredSize = 0;
|
|
|
|
|
|
|
|
hClassesKey = SetupDiOpenClassRegKeyExW(NULL,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
DIOCR_INSTALLER,
|
|
|
|
MachineName,
|
|
|
|
Reserved);
|
|
|
|
if (hClassesKey == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (dwIndex = 0; ; dwIndex++)
|
|
|
|
{
|
2018-09-15 00:10:28 +02:00
|
|
|
dwLength = ARRAY_SIZE(szKeyName);
|
2004-12-02 19:09:53 +01:00
|
|
|
lError = RegEnumKeyExW(hClassesKey,
|
|
|
|
dwIndex,
|
|
|
|
szKeyName,
|
|
|
|
&dwLength,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2006-10-13 23:32:50 +02:00
|
|
|
TRACE("RegEnumKeyExW() returns %d\n", lError);
|
2004-12-02 19:09:53 +01:00
|
|
|
if (lError == ERROR_SUCCESS || lError == ERROR_MORE_DATA)
|
|
|
|
{
|
|
|
|
TRACE("Key name: %p\n", szKeyName);
|
|
|
|
|
|
|
|
if (RegOpenKeyExW(hClassesKey,
|
|
|
|
szKeyName,
|
|
|
|
0,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
&hClassKey))
|
|
|
|
{
|
|
|
|
RegCloseKey(hClassesKey);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-02-08 13:11:42 +01:00
|
|
|
dwLength = sizeof(szClassName);
|
2004-12-02 19:09:53 +01:00
|
|
|
if (!RegQueryValueExW(hClassKey,
|
|
|
|
Class,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(LPBYTE)szClassName,
|
|
|
|
&dwLength))
|
|
|
|
{
|
|
|
|
TRACE("Class name: %p\n", szClassName);
|
|
|
|
|
2019-07-04 15:41:03 +02:00
|
|
|
if (wcsicmp(szClassName, ClassName) == 0)
|
2004-12-02 19:09:53 +01:00
|
|
|
{
|
|
|
|
TRACE("Found matching class name\n");
|
|
|
|
|
|
|
|
TRACE("Guid: %p\n", szKeyName);
|
|
|
|
if (dwGuidListIndex < ClassGuidListSize)
|
|
|
|
{
|
2007-06-21 22:56:32 +02:00
|
|
|
if (szKeyName[0] == '{' && szKeyName[37] == '}')
|
2004-12-02 19:09:53 +01:00
|
|
|
{
|
|
|
|
szKeyName[37] = 0;
|
|
|
|
}
|
|
|
|
TRACE("Guid: %p\n", &szKeyName[1]);
|
|
|
|
|
|
|
|
UuidFromStringW(&szKeyName[1],
|
|
|
|
&ClassGuidList[dwGuidListIndex]);
|
|
|
|
}
|
|
|
|
|
|
|
|
dwGuidListIndex++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(hClassKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lError != ERROR_SUCCESS)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(hClassesKey);
|
|
|
|
|
|
|
|
if (RequiredSize != NULL)
|
|
|
|
*RequiredSize = dwGuidListIndex;
|
|
|
|
|
|
|
|
if (ClassGuidListSize < dwGuidListIndex)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiClassNameFromGuidA (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiClassNameFromGuidA(
|
|
|
|
const GUID* ClassGuid,
|
|
|
|
PSTR ClassName,
|
|
|
|
DWORD ClassNameSize,
|
|
|
|
PDWORD RequiredSize)
|
|
|
|
{
|
|
|
|
return SetupDiClassNameFromGuidExA(ClassGuid, ClassName,
|
|
|
|
ClassNameSize, RequiredSize,
|
|
|
|
NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiClassNameFromGuidW (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiClassNameFromGuidW(
|
|
|
|
const GUID* ClassGuid,
|
|
|
|
PWSTR ClassName,
|
|
|
|
DWORD ClassNameSize,
|
|
|
|
PDWORD RequiredSize)
|
|
|
|
{
|
|
|
|
return SetupDiClassNameFromGuidExW(ClassGuid, ClassName,
|
|
|
|
ClassNameSize, RequiredSize,
|
|
|
|
NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiClassNameFromGuidExA (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiClassNameFromGuidExA(
|
|
|
|
const GUID* ClassGuid,
|
|
|
|
PSTR ClassName,
|
|
|
|
DWORD ClassNameSize,
|
|
|
|
PDWORD RequiredSize,
|
|
|
|
PCSTR MachineName,
|
|
|
|
PVOID Reserved)
|
|
|
|
{
|
2005-04-11 14:59:45 +02:00
|
|
|
WCHAR ClassNameW[MAX_CLASS_NAME_LEN];
|
|
|
|
LPWSTR MachineNameW = NULL;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (MachineName)
|
|
|
|
MachineNameW = MultiByteToUnicode(MachineName, CP_ACP);
|
|
|
|
ret = SetupDiClassNameFromGuidExW(ClassGuid, ClassNameW, MAX_CLASS_NAME_LEN,
|
|
|
|
NULL, MachineNameW, Reserved);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
int len = WideCharToMultiByte(CP_ACP, 0, ClassNameW, -1, ClassName,
|
|
|
|
ClassNameSize, NULL, NULL);
|
|
|
|
|
|
|
|
if (!ClassNameSize && RequiredSize)
|
|
|
|
*RequiredSize = len;
|
|
|
|
}
|
|
|
|
MyFree(MachineNameW);
|
|
|
|
return ret;
|
2004-12-02 19:09:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiClassNameFromGuidExW (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiClassNameFromGuidExW(
|
|
|
|
const GUID* ClassGuid,
|
|
|
|
PWSTR ClassName,
|
|
|
|
DWORD ClassNameSize,
|
|
|
|
PDWORD RequiredSize,
|
|
|
|
PCWSTR MachineName,
|
|
|
|
PVOID Reserved)
|
|
|
|
{
|
|
|
|
HKEY hKey;
|
|
|
|
DWORD dwLength;
|
|
|
|
|
|
|
|
hKey = SetupDiOpenClassRegKeyExW(ClassGuid,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
DIOCR_INSTALLER,
|
|
|
|
MachineName,
|
|
|
|
Reserved);
|
|
|
|
if (hKey == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RequiredSize != NULL)
|
|
|
|
{
|
|
|
|
dwLength = 0;
|
|
|
|
if (RegQueryValueExW(hKey,
|
|
|
|
Class,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&dwLength))
|
|
|
|
{
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*RequiredSize = dwLength / sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
|
|
|
|
dwLength = ClassNameSize * sizeof(WCHAR);
|
|
|
|
if (RegQueryValueExW(hKey,
|
|
|
|
Class,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(LPBYTE)ClassName,
|
|
|
|
&dwLength))
|
|
|
|
{
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiCreateDeviceInfoList (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
HDEVINFO WINAPI
|
|
|
|
SetupDiCreateDeviceInfoList(const GUID *ClassGuid,
|
|
|
|
HWND hwndParent)
|
|
|
|
{
|
|
|
|
return SetupDiCreateDeviceInfoListExW(ClassGuid, hwndParent, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiCreateDeviceInfoListExA (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
HDEVINFO WINAPI
|
|
|
|
SetupDiCreateDeviceInfoListExA(const GUID *ClassGuid,
|
|
|
|
HWND hwndParent,
|
|
|
|
PCSTR MachineName,
|
|
|
|
PVOID Reserved)
|
|
|
|
{
|
2005-02-03 14:34:50 +01:00
|
|
|
LPWSTR MachineNameW = NULL;
|
|
|
|
HDEVINFO hDevInfo;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
if (MachineName)
|
|
|
|
{
|
|
|
|
MachineNameW = MultiByteToUnicode(MachineName, CP_ACP);
|
|
|
|
if (MachineNameW == NULL)
|
2008-01-19 15:56:39 +01:00
|
|
|
return INVALID_HANDLE_VALUE;
|
2005-02-03 14:34:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
hDevInfo = SetupDiCreateDeviceInfoListExW(ClassGuid, hwndParent,
|
|
|
|
MachineNameW, Reserved);
|
|
|
|
|
2006-07-19 19:39:48 +02:00
|
|
|
MyFree(MachineNameW);
|
2005-02-03 14:34:50 +01:00
|
|
|
|
|
|
|
return hDevInfo;
|
2004-12-02 19:09:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiCreateDeviceInfoListExW (SETUPAPI.@)
|
2006-06-13 19:13:32 +02:00
|
|
|
*
|
|
|
|
* Create an empty DeviceInfoSet list.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2008-04-21 07:17:27 +02:00
|
|
|
* ClassGuid [I] if not NULL only devices with GUID ClassGuid are associated
|
2006-06-13 19:13:32 +02:00
|
|
|
* with this list.
|
|
|
|
* hwndParent [I] hwnd needed for interface related actions.
|
2016-05-01 10:24:05 +02:00
|
|
|
* MachineName [I] name of machine to create empty DeviceInfoSet list, if NULL
|
2007-02-20 12:03:31 +01:00
|
|
|
* local registry will be used.
|
2006-06-13 19:13:32 +02:00
|
|
|
* Reserved [I] must be NULL
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: empty list.
|
|
|
|
* Failure: INVALID_HANDLE_VALUE.
|
2004-12-02 19:09:53 +01:00
|
|
|
*/
|
|
|
|
HDEVINFO WINAPI
|
|
|
|
SetupDiCreateDeviceInfoListExW(const GUID *ClassGuid,
|
|
|
|
HWND hwndParent,
|
|
|
|
PCWSTR MachineName,
|
|
|
|
PVOID Reserved)
|
|
|
|
{
|
2006-06-13 19:13:32 +02:00
|
|
|
struct DeviceInfoSet *list = NULL;
|
|
|
|
DWORD size = sizeof(struct DeviceInfoSet);
|
|
|
|
|
|
|
|
TRACE("%s %p %s %p\n", debugstr_guid(ClassGuid), hwndParent,
|
|
|
|
debugstr_w(MachineName), Reserved);
|
|
|
|
|
2011-06-09 20:35:11 +02:00
|
|
|
if (MachineName && *MachineName)
|
2006-06-13 19:13:32 +02:00
|
|
|
{
|
2006-10-05 11:11:03 +02:00
|
|
|
FIXME("remote support is not implemented\n");
|
2006-06-13 19:13:32 +02:00
|
|
|
SetLastError(ERROR_INVALID_MACHINENAME);
|
2008-01-19 15:56:39 +01:00
|
|
|
return INVALID_HANDLE_VALUE;
|
2006-06-13 19:13:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Reserved != NULL)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
2008-01-19 15:56:39 +01:00
|
|
|
return INVALID_HANDLE_VALUE;
|
2006-06-13 19:13:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
list = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
if (!list)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
2008-01-19 15:56:39 +01:00
|
|
|
return INVALID_HANDLE_VALUE;
|
2006-06-13 19:13:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
list->magic = SETUP_DEVICE_INFO_SET_MAGIC;
|
|
|
|
list->hwndParent = hwndParent;
|
|
|
|
memcpy(&list->ClassGuid,
|
|
|
|
ClassGuid ? ClassGuid : &GUID_NULL,
|
|
|
|
sizeof(list->ClassGuid));
|
2008-04-03 17:19:40 +02:00
|
|
|
list_init(&list->devices);
|
2006-06-13 19:13:32 +02:00
|
|
|
|
2008-12-08 04:06:20 +01:00
|
|
|
return list;
|
2004-12-02 19:09:53 +01:00
|
|
|
}
|
|
|
|
|
2007-10-11 22:23:56 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiCreateDevRegKeyA (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
HKEY WINAPI SetupDiCreateDevRegKeyA(
|
|
|
|
HDEVINFO DeviceInfoSet,
|
|
|
|
PSP_DEVINFO_DATA DeviceInfoData,
|
|
|
|
DWORD Scope,
|
|
|
|
DWORD HwProfile,
|
|
|
|
DWORD KeyType,
|
|
|
|
HINF InfHandle,
|
|
|
|
PCSTR InfSectionName)
|
|
|
|
{
|
2007-10-11 22:24:19 +02:00
|
|
|
PWSTR InfSectionNameW = NULL;
|
|
|
|
HKEY key;
|
|
|
|
|
|
|
|
TRACE("%p %p %d %d %d %p %s\n", DeviceInfoSet, DeviceInfoData, Scope,
|
2007-10-11 22:23:56 +02:00
|
|
|
HwProfile, KeyType, InfHandle, debugstr_a(InfSectionName));
|
2007-10-11 22:24:19 +02:00
|
|
|
|
|
|
|
if (InfHandle)
|
|
|
|
{
|
|
|
|
if (!InfSectionName)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
InfSectionNameW = MultiByteToUnicode(InfSectionName, CP_ACP);
|
|
|
|
if (InfSectionNameW == NULL) return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
key = SetupDiCreateDevRegKeyW(DeviceInfoSet, DeviceInfoData, Scope,
|
|
|
|
HwProfile, KeyType, InfHandle, InfSectionNameW);
|
|
|
|
MyFree(InfSectionNameW);
|
|
|
|
return key;
|
2007-10-11 22:23:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiCreateDevRegKeyW (SETUPAPI.@)
|
|
|
|
*/
|
2018-11-26 00:31:46 +01:00
|
|
|
HKEY WINAPI SetupDiCreateDevRegKeyW(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data, DWORD Scope,
|
|
|
|
DWORD HwProfile, DWORD KeyType, HINF InfHandle, const WCHAR *InfSectionName)
|
2007-10-11 22:23:56 +02:00
|
|
|
{
|
2018-07-30 03:26:24 +02:00
|
|
|
struct device *device;
|
2007-10-11 22:25:52 +02:00
|
|
|
HKEY key = INVALID_HANDLE_VALUE;
|
2019-02-25 05:08:17 +01:00
|
|
|
LONG l;
|
2007-10-11 22:25:52 +02:00
|
|
|
|
2018-11-26 00:31:46 +01:00
|
|
|
TRACE("devinfo %p, device_data %p, scope %d, profile %d, type %d, inf_handle %p, inf_section %s.\n",
|
|
|
|
devinfo, device_data, Scope, HwProfile, KeyType, InfHandle, debugstr_w(InfSectionName));
|
2007-10-11 22:25:52 +02:00
|
|
|
|
2018-11-26 00:31:46 +01:00
|
|
|
if (!(device = get_device(devinfo, device_data)))
|
2007-10-11 22:25:52 +02:00
|
|
|
return INVALID_HANDLE_VALUE;
|
2018-11-26 00:31:46 +01:00
|
|
|
|
2007-10-12 17:25:51 +02:00
|
|
|
if (Scope != DICS_FLAG_GLOBAL && Scope != DICS_FLAG_CONFIGSPECIFIC)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_FLAGS);
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
if (KeyType != DIREG_DEV && KeyType != DIREG_DRV)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_FLAGS);
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
2018-07-30 03:26:24 +02:00
|
|
|
if (device->phantom)
|
2007-10-11 22:25:52 +02:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_DEVINFO_NOT_REGISTERED);
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
if (Scope != DICS_FLAG_GLOBAL)
|
|
|
|
FIXME("unimplemented for scope %d\n", Scope);
|
|
|
|
switch (KeyType)
|
|
|
|
{
|
|
|
|
case DIREG_DEV:
|
2019-02-25 05:08:20 +01:00
|
|
|
l = RegCreateKeyExW(device->key, DeviceParameters, 0, NULL, 0,
|
|
|
|
KEY_READ | KEY_WRITE, NULL, &key, NULL);
|
2007-10-11 22:25:52 +02:00
|
|
|
break;
|
|
|
|
case DIREG_DRV:
|
2019-02-25 05:08:20 +01:00
|
|
|
l = create_driver_key(device, &key);
|
2007-10-11 22:25:52 +02:00
|
|
|
break;
|
|
|
|
default:
|
2019-02-25 05:08:20 +01:00
|
|
|
FIXME("Unhandled type %#x.\n", KeyType);
|
|
|
|
l = ERROR_CALL_NOT_IMPLEMENTED;
|
2007-10-11 22:25:52 +02:00
|
|
|
}
|
|
|
|
if (InfHandle)
|
|
|
|
SetupInstallFromInfSectionW(NULL, InfHandle, InfSectionName, SPINST_ALL,
|
2018-11-26 00:31:46 +01:00
|
|
|
NULL, NULL, SP_COPY_NEWER_ONLY, NULL, NULL, devinfo, device_data);
|
2019-02-25 05:08:20 +01:00
|
|
|
SetLastError(l);
|
|
|
|
return l ? INVALID_HANDLE_VALUE : key;
|
2007-10-11 22:23:56 +02:00
|
|
|
}
|
|
|
|
|
2006-07-20 16:08:43 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiCreateDeviceInfoA (SETUPAPI.@)
|
|
|
|
*/
|
2018-11-28 02:55:34 +01:00
|
|
|
BOOL WINAPI SetupDiCreateDeviceInfoA(HDEVINFO DeviceInfoSet, const char *name,
|
2013-09-23 00:37:16 +02:00
|
|
|
const GUID *ClassGuid, PCSTR DeviceDescription, HWND hwndParent, DWORD CreationFlags,
|
|
|
|
PSP_DEVINFO_DATA DeviceInfoData)
|
2006-07-20 16:08:43 +02:00
|
|
|
{
|
2018-11-28 02:55:35 +01:00
|
|
|
WCHAR nameW[MAX_DEVICE_ID_LEN];
|
2006-07-20 16:08:43 +02:00
|
|
|
BOOL ret = FALSE;
|
|
|
|
LPWSTR DeviceDescriptionW = NULL;
|
|
|
|
|
2018-11-28 02:55:34 +01:00
|
|
|
if (!name || strlen(name) >= MAX_DEVICE_ID_LEN)
|
2006-07-20 16:08:43 +02:00
|
|
|
{
|
2018-11-28 02:55:34 +01:00
|
|
|
SetLastError(ERROR_INVALID_DEVINST_NAME);
|
|
|
|
return FALSE;
|
2006-07-20 16:08:43 +02:00
|
|
|
}
|
2018-11-28 02:55:34 +01:00
|
|
|
|
2018-11-29 13:30:21 +01:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, name, -1, nameW, ARRAY_SIZE(nameW));
|
2018-11-28 02:55:34 +01:00
|
|
|
|
2006-07-20 16:08:43 +02:00
|
|
|
if (DeviceDescription)
|
|
|
|
{
|
|
|
|
DeviceDescriptionW = MultiByteToUnicode(DeviceDescription, CP_ACP);
|
|
|
|
if (DeviceDescriptionW == NULL)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-11-28 02:55:35 +01:00
|
|
|
ret = SetupDiCreateDeviceInfoW(DeviceInfoSet, nameW, ClassGuid, DeviceDescriptionW,
|
2006-07-20 16:08:43 +02:00
|
|
|
hwndParent, CreationFlags, DeviceInfoData);
|
|
|
|
|
|
|
|
MyFree(DeviceDescriptionW);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-07-19 19:58:47 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiCreateDeviceInfoW (SETUPAPI.@)
|
|
|
|
*/
|
2018-11-28 02:55:37 +01:00
|
|
|
BOOL WINAPI SetupDiCreateDeviceInfoW(HDEVINFO devinfo, const WCHAR *name, const GUID *class,
|
|
|
|
const WCHAR *description, HWND parent, DWORD flags, SP_DEVINFO_DATA *device_data)
|
2006-07-19 19:58:47 +02:00
|
|
|
{
|
2018-11-28 02:55:37 +01:00
|
|
|
WCHAR id[MAX_DEVICE_ID_LEN];
|
2018-11-26 00:31:48 +01:00
|
|
|
struct DeviceInfoSet *set;
|
2019-03-15 04:42:29 +01:00
|
|
|
HKEY enum_hkey;
|
|
|
|
HKEY instance_hkey;
|
2018-11-28 02:55:37 +01:00
|
|
|
struct device *device;
|
2019-04-01 04:22:11 +02:00
|
|
|
LONG l;
|
2007-09-20 02:49:17 +02:00
|
|
|
|
2018-11-26 00:31:48 +01:00
|
|
|
TRACE("devinfo %p, name %s, class %s, description %s, hwnd %p, flags %#x, device_data %p.\n",
|
2018-11-28 02:55:37 +01:00
|
|
|
devinfo, debugstr_w(name), debugstr_guid(class), debugstr_w(description),
|
|
|
|
parent, flags, device_data);
|
2006-07-19 19:58:47 +02:00
|
|
|
|
2019-07-04 15:41:03 +02:00
|
|
|
if (!name || lstrlenW(name) >= MAX_DEVICE_ID_LEN)
|
2007-09-20 02:49:17 +02:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_DEVINST_NAME);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-11-26 00:31:48 +01:00
|
|
|
|
|
|
|
if (!(set = get_device_set(devinfo)))
|
2007-09-20 02:49:17 +02:00
|
|
|
return FALSE;
|
2018-11-26 00:31:48 +01:00
|
|
|
|
2018-11-28 02:55:37 +01:00
|
|
|
if (!class)
|
2007-09-20 02:49:17 +02:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-11-26 00:31:48 +01:00
|
|
|
|
2018-11-28 02:55:37 +01:00
|
|
|
if (!IsEqualGUID(&set->ClassGuid, &GUID_NULL) && !IsEqualGUID(class, &set->ClassGuid))
|
2007-09-20 18:09:18 +02:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_CLASS_MISMATCH);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-11-28 02:55:37 +01:00
|
|
|
if ((flags & DICD_GENERATE_ID))
|
2007-09-20 18:09:18 +02:00
|
|
|
{
|
2019-04-01 04:22:11 +02:00
|
|
|
static const WCHAR formatW[] = {'R','O','O','T','\\','%','s','\\','%','0','4','u',0};
|
|
|
|
unsigned int instance_id;
|
2018-11-28 02:55:37 +01:00
|
|
|
|
2019-07-04 15:41:03 +02:00
|
|
|
if (wcschr(name, '\\'))
|
2018-11-28 02:55:37 +01:00
|
|
|
{
|
2007-09-20 18:09:18 +02:00
|
|
|
SetLastError(ERROR_INVALID_DEVINST_NAME);
|
2018-11-28 02:55:37 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-04-01 04:22:11 +02:00
|
|
|
for (instance_id = 0; ; ++instance_id)
|
2018-11-28 02:55:37 +01:00
|
|
|
{
|
2019-07-04 15:41:03 +02:00
|
|
|
if (swprintf(id, ARRAY_SIZE(id), formatW, name, instance_id) == -1)
|
2019-04-01 04:22:11 +02:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_DEVINST_NAME);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_READ, NULL, &enum_hkey, NULL);
|
|
|
|
if (!(l = RegOpenKeyExW(enum_hkey, id, 0, KEY_READ, &instance_hkey)))
|
|
|
|
RegCloseKey(instance_hkey);
|
|
|
|
if (l == ERROR_FILE_NOT_FOUND)
|
|
|
|
break;
|
|
|
|
RegCloseKey(enum_hkey);
|
2007-09-20 02:49:17 +02:00
|
|
|
}
|
2007-09-20 18:09:18 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-15 04:42:29 +01:00
|
|
|
/* Check if instance is already in registry */
|
|
|
|
RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_READ, NULL, &enum_hkey, NULL);
|
|
|
|
if (!RegOpenKeyExW(enum_hkey, name, 0, KEY_READ, &instance_hkey))
|
|
|
|
{
|
|
|
|
RegCloseKey(instance_hkey);
|
|
|
|
RegCloseKey(enum_hkey);
|
|
|
|
SetLastError(ERROR_DEVINST_ALREADY_EXISTS);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
RegCloseKey(enum_hkey);
|
|
|
|
|
|
|
|
/* Check if instance is already in set */
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcpyW(id, name);
|
2018-07-30 03:26:24 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(device, &set->devices, struct device, entry)
|
2007-09-20 02:49:17 +02:00
|
|
|
{
|
2018-11-28 02:55:37 +01:00
|
|
|
if (!lstrcmpiW(name, device->instanceId))
|
2007-09-20 18:09:18 +02:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_DEVINST_ALREADY_EXISTS);
|
2018-11-28 02:55:37 +01:00
|
|
|
return FALSE;
|
2007-09-20 18:09:18 +02:00
|
|
|
}
|
2007-09-20 02:49:17 +02:00
|
|
|
}
|
|
|
|
}
|
2018-11-28 02:55:37 +01:00
|
|
|
|
2019-05-28 05:13:20 +02:00
|
|
|
if (!(device = create_device(set, class, id, TRUE)))
|
2018-11-28 02:55:37 +01:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (description)
|
2007-09-20 18:09:18 +02:00
|
|
|
{
|
2018-11-28 02:55:37 +01:00
|
|
|
SETUPDI_SetDeviceRegistryPropertyW(device, SPDRP_DEVICEDESC,
|
|
|
|
(const BYTE *)description, lstrlenW(description) * sizeof(WCHAR));
|
|
|
|
}
|
2007-09-20 18:09:18 +02:00
|
|
|
|
2018-11-28 02:55:37 +01:00
|
|
|
if (device_data)
|
|
|
|
{
|
|
|
|
if (device_data->cbSize != sizeof(SP_DEVINFO_DATA))
|
2007-09-20 18:09:18 +02:00
|
|
|
{
|
2018-11-28 02:55:37 +01:00
|
|
|
SetLastError(ERROR_INVALID_USER_BUFFER);
|
|
|
|
return FALSE;
|
2007-09-20 18:09:18 +02:00
|
|
|
}
|
2018-11-28 02:55:37 +01:00
|
|
|
else
|
|
|
|
copy_device_data(device_data, device);
|
2007-09-20 18:09:18 +02:00
|
|
|
}
|
2006-07-19 19:58:47 +02:00
|
|
|
|
2018-11-28 02:55:37 +01:00
|
|
|
return TRUE;
|
2006-07-19 19:58:47 +02:00
|
|
|
}
|
|
|
|
|
2007-09-20 18:15:32 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiRegisterDeviceInfo (SETUPAPI.@)
|
|
|
|
*/
|
2018-11-26 00:31:46 +01:00
|
|
|
BOOL WINAPI SetupDiRegisterDeviceInfo(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data, DWORD flags,
|
|
|
|
PSP_DETSIG_CMPPROC compare_proc, void *context, SP_DEVINFO_DATA *duplicate_data)
|
2007-09-20 18:15:32 +02:00
|
|
|
{
|
2018-07-30 03:26:24 +02:00
|
|
|
struct device *device;
|
2007-09-20 18:16:25 +02:00
|
|
|
|
2018-11-26 00:31:46 +01:00
|
|
|
TRACE("devinfo %p, data %p, flags %#x, compare_proc %p, context %p, duplicate_data %p.\n",
|
|
|
|
devinfo, device_data, flags, compare_proc, context, duplicate_data);
|
2007-09-20 18:15:32 +02:00
|
|
|
|
2018-11-26 00:31:46 +01:00
|
|
|
if (!(device = get_device(devinfo, device_data)))
|
2007-09-20 18:16:25 +02:00
|
|
|
return FALSE;
|
2018-11-26 00:31:46 +01:00
|
|
|
|
2018-07-30 03:26:24 +02:00
|
|
|
if (device->phantom)
|
2007-09-20 18:16:25 +02:00
|
|
|
{
|
2018-07-30 03:26:24 +02:00
|
|
|
device->phantom = FALSE;
|
|
|
|
RegDeleteValueW(device->key, Phantom);
|
2007-09-20 18:16:25 +02:00
|
|
|
}
|
|
|
|
return TRUE;
|
2007-09-20 18:15:32 +02:00
|
|
|
}
|
|
|
|
|
2010-03-13 13:16:01 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiRemoveDevice (SETUPAPI.@)
|
|
|
|
*/
|
2018-11-30 23:42:12 +01:00
|
|
|
BOOL WINAPI SetupDiRemoveDevice(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data)
|
2010-03-13 13:16:01 +01:00
|
|
|
{
|
2018-11-30 23:42:12 +01:00
|
|
|
struct device *device;
|
|
|
|
|
|
|
|
TRACE("devinfo %p, device_data %p.\n", devinfo, device_data);
|
|
|
|
|
|
|
|
if (!(device = get_device(devinfo, device_data)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
remove_device(device);
|
|
|
|
|
|
|
|
return TRUE;
|
2010-03-13 13:16:01 +01:00
|
|
|
}
|
|
|
|
|
2018-12-04 06:36:16 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiDeleteDeviceInfo (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiDeleteDeviceInfo(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data)
|
|
|
|
{
|
|
|
|
struct device *device;
|
|
|
|
|
|
|
|
TRACE("devinfo %p, device_data %p.\n", devinfo, device_data);
|
|
|
|
|
|
|
|
if (!(device = get_device(devinfo, device_data)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
delete_device(device);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-12-07 11:03:00 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiRemoveDeviceInterface (SETUPAPI.@)
|
|
|
|
*/
|
2018-11-30 23:42:10 +01:00
|
|
|
BOOL WINAPI SetupDiRemoveDeviceInterface(HDEVINFO devinfo, SP_DEVICE_INTERFACE_DATA *iface_data)
|
2016-12-07 11:03:00 +01:00
|
|
|
{
|
2018-11-30 23:42:10 +01:00
|
|
|
struct device_iface *iface;
|
|
|
|
|
|
|
|
TRACE("devinfo %p, iface_data %p.\n", devinfo, iface_data);
|
|
|
|
|
|
|
|
if (!(iface = get_device_iface(devinfo, iface_data)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
remove_device_iface(iface);
|
|
|
|
|
|
|
|
return TRUE;
|
2016-12-07 11:03:00 +01:00
|
|
|
}
|
|
|
|
|
2018-12-04 06:36:14 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiDeleteDeviceInterfaceData (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiDeleteDeviceInterfaceData(HDEVINFO devinfo, SP_DEVICE_INTERFACE_DATA *iface_data)
|
|
|
|
{
|
|
|
|
struct device_iface *iface;
|
|
|
|
|
|
|
|
TRACE("devinfo %p, iface_data %p.\n", devinfo, iface_data);
|
|
|
|
|
|
|
|
if (!(iface = get_device_iface(devinfo, iface_data)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
delete_device_iface(iface);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-12-02 19:09:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiEnumDeviceInfo (SETUPAPI.@)
|
|
|
|
*/
|
2019-04-23 13:28:49 +02:00
|
|
|
BOOL WINAPI DECLSPEC_HOTPATCH SetupDiEnumDeviceInfo(HDEVINFO devinfo, DWORD index, SP_DEVINFO_DATA *device_data)
|
2004-12-02 19:09:53 +01:00
|
|
|
{
|
2018-11-26 00:31:48 +01:00
|
|
|
struct DeviceInfoSet *set;
|
|
|
|
struct device *device;
|
|
|
|
DWORD i = 0;
|
2007-09-20 02:46:58 +02:00
|
|
|
|
2018-11-26 00:31:48 +01:00
|
|
|
TRACE("devinfo %p, index %d, device_data %p\n", devinfo, index, device_data);
|
2004-12-02 19:09:53 +01:00
|
|
|
|
2018-11-26 00:31:48 +01:00
|
|
|
if (!(set = get_device_set(devinfo)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!device_data)
|
2007-09-21 20:35:46 +02:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
2004-12-02 19:09:53 +01:00
|
|
|
return FALSE;
|
2007-09-21 20:35:46 +02:00
|
|
|
}
|
2018-11-26 00:31:48 +01:00
|
|
|
|
|
|
|
if (device_data->cbSize != sizeof(SP_DEVINFO_DATA))
|
2007-09-20 02:46:58 +02:00
|
|
|
{
|
2018-11-26 00:31:48 +01:00
|
|
|
SetLastError(ERROR_INVALID_USER_BUFFER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-04-03 17:19:40 +02:00
|
|
|
|
2018-11-26 00:31:48 +01:00
|
|
|
LIST_FOR_EACH_ENTRY(device, &set->devices, struct device, entry)
|
|
|
|
{
|
|
|
|
if (i++ == index)
|
|
|
|
{
|
|
|
|
copy_device_data(device_data, device);
|
2018-12-04 06:36:15 +01:00
|
|
|
return TRUE;
|
2007-09-20 02:46:58 +02:00
|
|
|
}
|
|
|
|
}
|
2018-11-26 00:31:48 +01:00
|
|
|
|
2018-12-04 06:36:15 +01:00
|
|
|
SetLastError(ERROR_NO_MORE_ITEMS);
|
|
|
|
return FALSE;
|
2002-05-29 00:39:14 +02:00
|
|
|
}
|
|
|
|
|
2007-09-20 02:45:31 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiGetDeviceInstanceIdA (SETUPAPI.@)
|
|
|
|
*/
|
2018-11-28 02:55:36 +01:00
|
|
|
BOOL WINAPI SetupDiGetDeviceInstanceIdA(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data,
|
|
|
|
char *id, DWORD size, DWORD *needed)
|
2007-09-20 02:45:31 +02:00
|
|
|
{
|
2018-11-28 02:55:36 +01:00
|
|
|
WCHAR idW[MAX_DEVICE_ID_LEN];
|
|
|
|
|
|
|
|
TRACE("devinfo %p, device_data %p, id %p, size %d, needed %p.\n",
|
|
|
|
devinfo, device_data, id, size, needed);
|
|
|
|
|
|
|
|
if (!SetupDiGetDeviceInstanceIdW(devinfo, device_data, idW, ARRAY_SIZE(idW), NULL))
|
2007-09-20 02:47:52 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2018-11-28 02:55:36 +01:00
|
|
|
if (needed)
|
|
|
|
*needed = WideCharToMultiByte(CP_ACP, 0, idW, -1, NULL, 0, NULL, NULL);
|
|
|
|
|
|
|
|
if (size && WideCharToMultiByte(CP_ACP, 0, idW, -1, id, size, NULL, NULL))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
return FALSE;
|
2007-09-20 02:45:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiGetDeviceInstanceIdW (SETUPAPI.@)
|
|
|
|
*/
|
2018-11-26 00:31:46 +01:00
|
|
|
BOOL WINAPI SetupDiGetDeviceInstanceIdW(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data,
|
|
|
|
WCHAR *DeviceInstanceId, DWORD DeviceInstanceIdSize, DWORD *RequiredSize)
|
2007-09-20 02:45:31 +02:00
|
|
|
{
|
2018-07-30 03:26:24 +02:00
|
|
|
struct device *device;
|
2007-09-20 18:09:43 +02:00
|
|
|
|
2018-11-26 00:31:46 +01:00
|
|
|
TRACE("devinfo %p, device_data %p, DeviceInstanceId %p, DeviceInstanceIdSize %d, RequiredSize %p.\n",
|
|
|
|
devinfo, device_data, DeviceInstanceId, DeviceInstanceIdSize, RequiredSize);
|
2007-09-20 18:09:43 +02:00
|
|
|
|
2018-11-26 00:31:46 +01:00
|
|
|
if (!(device = get_device(devinfo, device_data)))
|
2007-09-20 18:09:43 +02:00
|
|
|
return FALSE;
|
2018-11-26 00:31:46 +01:00
|
|
|
|
2018-07-30 03:26:24 +02:00
|
|
|
TRACE("instance ID: %s\n", debugstr_w(device->instanceId));
|
2019-07-04 15:41:03 +02:00
|
|
|
if (DeviceInstanceIdSize < lstrlenW(device->instanceId) + 1)
|
2007-09-20 18:09:43 +02:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
if (RequiredSize)
|
2018-07-30 03:26:24 +02:00
|
|
|
*RequiredSize = lstrlenW(device->instanceId) + 1;
|
2007-09-20 18:09:43 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2018-07-30 03:26:24 +02:00
|
|
|
lstrcpyW(DeviceInstanceId, device->instanceId);
|
2007-09-20 18:09:43 +02:00
|
|
|
if (RequiredSize)
|
2018-07-30 03:26:24 +02:00
|
|
|
*RequiredSize = lstrlenW(device->instanceId) + 1;
|
2007-09-20 18:09:43 +02:00
|
|
|
return TRUE;
|
2007-09-20 02:45:31 +02:00
|
|
|
}
|
|
|
|
|
2004-12-02 19:09:53 +01:00
|
|
|
/***********************************************************************
|
2019-05-17 07:21:07 +02:00
|
|
|
* SetupDiGetActualSectionToInstallA (SETUPAPI.@)
|
2004-12-02 19:09:53 +01:00
|
|
|
*/
|
2019-05-17 07:21:07 +02:00
|
|
|
BOOL WINAPI SetupDiGetActualSectionToInstallA(HINF hinf, const char *section,
|
|
|
|
char *section_ext, DWORD size, DWORD *needed, char **extptr)
|
2004-12-02 19:09:53 +01:00
|
|
|
{
|
2019-05-17 07:21:07 +02:00
|
|
|
WCHAR sectionW[LINE_LEN], section_extW[LINE_LEN], *extptrW;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, section, -1, sectionW, ARRAY_SIZE(sectionW));
|
|
|
|
|
|
|
|
ret = SetupDiGetActualSectionToInstallW(hinf, sectionW, section_extW,
|
|
|
|
ARRAY_SIZE(section_extW), NULL, &extptrW);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (needed)
|
|
|
|
*needed = WideCharToMultiByte(CP_ACP, 0, section_extW, -1, NULL, 0, NULL, NULL);
|
|
|
|
|
|
|
|
if (section_ext)
|
|
|
|
ret = !!WideCharToMultiByte(CP_ACP, 0, section_extW, -1, section_ext, size, NULL, NULL);
|
|
|
|
|
|
|
|
if (extptr)
|
|
|
|
{
|
|
|
|
if (extptrW)
|
|
|
|
*extptr = section_ext + WideCharToMultiByte(CP_ACP, 0, section_extW,
|
|
|
|
extptrW - section_extW, NULL, 0, NULL, NULL);
|
|
|
|
else
|
|
|
|
*extptr = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2004-12-02 19:09:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiGetActualSectionToInstallW (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiGetActualSectionToInstallW(
|
|
|
|
HINF InfHandle,
|
|
|
|
PCWSTR InfSectionName,
|
|
|
|
PWSTR InfSectionWithExt,
|
|
|
|
DWORD InfSectionWithExtSize,
|
|
|
|
PDWORD RequiredSize,
|
|
|
|
PWSTR *Extension)
|
|
|
|
{
|
|
|
|
WCHAR szBuffer[MAX_PATH];
|
|
|
|
DWORD dwLength;
|
|
|
|
DWORD dwFullLength;
|
|
|
|
LONG lLineCount = -1;
|
|
|
|
|
|
|
|
lstrcpyW(szBuffer, InfSectionName);
|
|
|
|
dwLength = lstrlenW(szBuffer);
|
|
|
|
|
|
|
|
if (OsVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
|
|
|
|
{
|
|
|
|
/* Test section name with '.NTx86' extension */
|
|
|
|
lstrcpyW(&szBuffer[dwLength], NtPlatformExtension);
|
|
|
|
lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
|
|
|
|
|
|
|
|
if (lLineCount == -1)
|
|
|
|
{
|
|
|
|
/* Test section name with '.NT' extension */
|
|
|
|
lstrcpyW(&szBuffer[dwLength], NtExtension);
|
|
|
|
lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Test section name with '.Win' extension */
|
|
|
|
lstrcpyW(&szBuffer[dwLength], WinExtension);
|
|
|
|
lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lLineCount == -1)
|
2019-05-17 07:21:10 +02:00
|
|
|
szBuffer[dwLength] = 0;
|
2004-12-02 19:09:53 +01:00
|
|
|
|
|
|
|
dwFullLength = lstrlenW(szBuffer);
|
|
|
|
|
|
|
|
if (InfSectionWithExt != NULL && InfSectionWithExtSize != 0)
|
|
|
|
{
|
|
|
|
if (InfSectionWithExtSize < (dwFullLength + 1))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
lstrcpyW(InfSectionWithExt, szBuffer);
|
|
|
|
if (Extension != NULL)
|
|
|
|
{
|
|
|
|
*Extension = (dwLength == dwFullLength) ? NULL : &InfSectionWithExt[dwLength];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RequiredSize != NULL)
|
|
|
|
{
|
|
|
|
*RequiredSize = dwFullLength + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiGetClassDescriptionA (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiGetClassDescriptionA(
|
|
|
|
const GUID* ClassGuid,
|
|
|
|
PSTR ClassDescription,
|
|
|
|
DWORD ClassDescriptionSize,
|
|
|
|
PDWORD RequiredSize)
|
|
|
|
{
|
|
|
|
return SetupDiGetClassDescriptionExA(ClassGuid, ClassDescription,
|
|
|
|
ClassDescriptionSize,
|
|
|
|
RequiredSize, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiGetClassDescriptionW (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiGetClassDescriptionW(
|
|
|
|
const GUID* ClassGuid,
|
|
|
|
PWSTR ClassDescription,
|
|
|
|
DWORD ClassDescriptionSize,
|
|
|
|
PDWORD RequiredSize)
|
|
|
|
{
|
|
|
|
return SetupDiGetClassDescriptionExW(ClassGuid, ClassDescription,
|
|
|
|
ClassDescriptionSize,
|
|
|
|
RequiredSize, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiGetClassDescriptionExA (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiGetClassDescriptionExA(
|
|
|
|
const GUID* ClassGuid,
|
|
|
|
PSTR ClassDescription,
|
|
|
|
DWORD ClassDescriptionSize,
|
|
|
|
PDWORD RequiredSize,
|
|
|
|
PCSTR MachineName,
|
|
|
|
PVOID Reserved)
|
|
|
|
{
|
2007-09-20 18:15:16 +02:00
|
|
|
HKEY hKey;
|
|
|
|
DWORD dwLength;
|
2007-09-21 12:21:17 +02:00
|
|
|
BOOL ret;
|
2007-09-20 18:15:16 +02:00
|
|
|
|
|
|
|
hKey = SetupDiOpenClassRegKeyExA(ClassGuid,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
DIOCR_INSTALLER,
|
|
|
|
MachineName,
|
|
|
|
Reserved);
|
|
|
|
if (hKey == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
WARN("SetupDiOpenClassRegKeyExA() failed (Error %u)\n", GetLastError());
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
dwLength = ClassDescriptionSize;
|
2007-09-21 12:21:17 +02:00
|
|
|
ret = !RegQueryValueExA( hKey, NULL, NULL, NULL,
|
|
|
|
(LPBYTE)ClassDescription, &dwLength );
|
|
|
|
if (RequiredSize) *RequiredSize = dwLength;
|
2007-09-20 18:15:16 +02:00
|
|
|
RegCloseKey(hKey);
|
2007-09-21 12:21:17 +02:00
|
|
|
return ret;
|
2004-12-02 19:09:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiGetClassDescriptionExW (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiGetClassDescriptionExW(
|
|
|
|
const GUID* ClassGuid,
|
|
|
|
PWSTR ClassDescription,
|
|
|
|
DWORD ClassDescriptionSize,
|
|
|
|
PDWORD RequiredSize,
|
|
|
|
PCWSTR MachineName,
|
|
|
|
PVOID Reserved)
|
|
|
|
{
|
|
|
|
HKEY hKey;
|
|
|
|
DWORD dwLength;
|
2007-09-21 12:21:17 +02:00
|
|
|
BOOL ret;
|
2004-12-02 19:09:53 +01:00
|
|
|
|
|
|
|
hKey = SetupDiOpenClassRegKeyExW(ClassGuid,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
DIOCR_INSTALLER,
|
|
|
|
MachineName,
|
|
|
|
Reserved);
|
|
|
|
if (hKey == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2006-10-13 23:32:50 +02:00
|
|
|
WARN("SetupDiOpenClassRegKeyExW() failed (Error %u)\n", GetLastError());
|
2004-12-02 19:09:53 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
dwLength = ClassDescriptionSize * sizeof(WCHAR);
|
2007-09-21 12:21:17 +02:00
|
|
|
ret = !RegQueryValueExW( hKey, NULL, NULL, NULL,
|
|
|
|
(LPBYTE)ClassDescription, &dwLength );
|
|
|
|
if (RequiredSize) *RequiredSize = dwLength / sizeof(WCHAR);
|
2004-12-02 19:09:53 +01:00
|
|
|
RegCloseKey(hKey);
|
2007-09-21 12:21:17 +02:00
|
|
|
return ret;
|
2004-12-02 19:09:53 +01:00
|
|
|
}
|
|
|
|
|
2002-06-05 00:12:50 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiGetClassDevsA (SETUPAPI.@)
|
|
|
|
*/
|
2013-09-23 00:37:16 +02:00
|
|
|
HDEVINFO WINAPI SetupDiGetClassDevsA(const GUID *class, LPCSTR enumstr, HWND parent, DWORD flags)
|
2002-05-29 00:39:14 +02:00
|
|
|
{
|
2005-03-01 12:44:27 +01:00
|
|
|
HDEVINFO ret;
|
|
|
|
LPWSTR enumstrW = NULL;
|
2002-05-29 00:39:14 +02:00
|
|
|
|
2005-03-01 12:44:27 +01:00
|
|
|
if (enumstr)
|
|
|
|
{
|
|
|
|
int len = MultiByteToWideChar(CP_ACP, 0, enumstr, -1, NULL, 0);
|
|
|
|
enumstrW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
if (!enumstrW)
|
|
|
|
{
|
2008-01-19 15:56:39 +01:00
|
|
|
ret = INVALID_HANDLE_VALUE;
|
2005-03-01 12:44:27 +01:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, enumstr, -1, enumstrW, len);
|
|
|
|
}
|
2007-09-24 22:02:58 +02:00
|
|
|
ret = SetupDiGetClassDevsExW(class, enumstrW, parent, flags, NULL, NULL,
|
|
|
|
NULL);
|
2005-03-01 12:44:27 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, enumstrW);
|
|
|
|
|
|
|
|
end:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-09-24 22:32:46 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiGetClassDevsExA (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
HDEVINFO WINAPI SetupDiGetClassDevsExA(
|
|
|
|
const GUID *class,
|
|
|
|
PCSTR enumstr,
|
|
|
|
HWND parent,
|
|
|
|
DWORD flags,
|
|
|
|
HDEVINFO deviceset,
|
|
|
|
PCSTR machine,
|
|
|
|
PVOID reserved)
|
|
|
|
{
|
|
|
|
HDEVINFO ret;
|
|
|
|
LPWSTR enumstrW = NULL, machineW = NULL;
|
|
|
|
|
|
|
|
if (enumstr)
|
|
|
|
{
|
|
|
|
int len = MultiByteToWideChar(CP_ACP, 0, enumstr, -1, NULL, 0);
|
|
|
|
enumstrW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
if (!enumstrW)
|
|
|
|
{
|
2008-01-19 15:56:39 +01:00
|
|
|
ret = INVALID_HANDLE_VALUE;
|
2007-09-24 22:32:46 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, enumstr, -1, enumstrW, len);
|
|
|
|
}
|
|
|
|
if (machine)
|
|
|
|
{
|
|
|
|
int len = MultiByteToWideChar(CP_ACP, 0, machine, -1, NULL, 0);
|
|
|
|
machineW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
if (!machineW)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, enumstrW);
|
2008-01-19 15:56:39 +01:00
|
|
|
ret = INVALID_HANDLE_VALUE;
|
2007-09-24 22:32:46 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, machine, -1, machineW, len);
|
|
|
|
}
|
|
|
|
ret = SetupDiGetClassDevsExW(class, enumstrW, parent, flags, deviceset,
|
|
|
|
machineW, reserved);
|
|
|
|
HeapFree(GetProcessHeap(), 0, enumstrW);
|
|
|
|
HeapFree(GetProcessHeap(), 0, machineW);
|
|
|
|
|
|
|
|
end:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-08-17 01:37:39 +02:00
|
|
|
static void SETUPDI_AddDeviceInterfaces(struct device *device, HKEY key,
|
|
|
|
const GUID *guid, DWORD flags)
|
2007-09-21 20:37:09 +02:00
|
|
|
{
|
|
|
|
DWORD i, len;
|
|
|
|
WCHAR subKeyName[MAX_PATH];
|
|
|
|
LONG l = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
for (i = 0; !l; i++)
|
|
|
|
{
|
2018-09-15 00:10:28 +02:00
|
|
|
len = ARRAY_SIZE(subKeyName);
|
2007-09-21 20:37:09 +02:00
|
|
|
l = RegEnumKeyExW(key, i, subKeyName, &len, NULL, NULL, NULL, NULL);
|
|
|
|
if (!l)
|
|
|
|
{
|
|
|
|
HKEY subKey;
|
2018-07-30 03:26:27 +02:00
|
|
|
struct device_iface *iface;
|
2007-09-21 20:37:09 +02:00
|
|
|
|
2008-03-28 16:49:34 +01:00
|
|
|
if (*subKeyName == '#')
|
2007-09-21 20:37:09 +02:00
|
|
|
{
|
2008-03-28 16:49:34 +01:00
|
|
|
/* The subkey name is the reference string, with a '#' prepended */
|
|
|
|
l = RegOpenKeyExW(key, subKeyName, 0, KEY_READ, &subKey);
|
|
|
|
if (!l)
|
|
|
|
{
|
|
|
|
WCHAR symbolicLink[MAX_PATH];
|
|
|
|
DWORD dataType;
|
|
|
|
|
2018-08-17 01:37:39 +02:00
|
|
|
if (!(flags & DIGCF_PRESENT) || is_linked(subKey))
|
|
|
|
{
|
|
|
|
iface = SETUPDI_CreateDeviceInterface(device, guid, subKeyName + 1);
|
|
|
|
|
|
|
|
len = sizeof(symbolicLink);
|
|
|
|
l = RegQueryValueExW(subKey, SymbolicLink, NULL, &dataType,
|
|
|
|
(BYTE *)symbolicLink, &len);
|
|
|
|
if (!l && dataType == REG_SZ)
|
|
|
|
SETUPDI_SetInterfaceSymbolicLink(iface, symbolicLink);
|
|
|
|
RegCloseKey(subKey);
|
|
|
|
}
|
2008-03-28 16:49:34 +01:00
|
|
|
}
|
2007-09-21 20:37:09 +02:00
|
|
|
}
|
2007-10-12 17:26:56 +02:00
|
|
|
/* Allow enumeration to continue */
|
|
|
|
l = ERROR_SUCCESS;
|
2007-09-21 20:37:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* FIXME: find and add all the device's interfaces to the device */
|
|
|
|
}
|
|
|
|
|
2007-09-20 18:16:45 +02:00
|
|
|
static void SETUPDI_EnumerateMatchingInterfaces(HDEVINFO DeviceInfoSet,
|
2018-08-17 01:37:39 +02:00
|
|
|
HKEY key, const GUID *guid, const WCHAR *enumstr, DWORD flags)
|
2007-09-20 18:16:45 +02:00
|
|
|
{
|
2009-01-28 10:24:55 +01:00
|
|
|
struct DeviceInfoSet *set = DeviceInfoSet;
|
2007-09-20 18:16:45 +02:00
|
|
|
DWORD i, len;
|
|
|
|
WCHAR subKeyName[MAX_PATH];
|
|
|
|
LONG l;
|
|
|
|
HKEY enumKey = INVALID_HANDLE_VALUE;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(enumstr));
|
|
|
|
|
|
|
|
l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_READ, NULL,
|
|
|
|
&enumKey, NULL);
|
|
|
|
for (i = 0; !l; i++)
|
|
|
|
{
|
2018-09-15 00:10:28 +02:00
|
|
|
len = ARRAY_SIZE(subKeyName);
|
2007-09-20 18:16:45 +02:00
|
|
|
l = RegEnumKeyExW(key, i, subKeyName, &len, NULL, NULL, NULL, NULL);
|
|
|
|
if (!l)
|
|
|
|
{
|
|
|
|
HKEY subKey;
|
|
|
|
|
|
|
|
l = RegOpenKeyExW(key, subKeyName, 0, KEY_READ, &subKey);
|
|
|
|
if (!l)
|
|
|
|
{
|
|
|
|
WCHAR deviceInst[MAX_PATH * 3];
|
|
|
|
DWORD dataType;
|
|
|
|
|
|
|
|
len = sizeof(deviceInst);
|
|
|
|
l = RegQueryValueExW(subKey, DeviceInstance, NULL, &dataType,
|
|
|
|
(BYTE *)deviceInst, &len);
|
|
|
|
if (!l && dataType == REG_SZ)
|
|
|
|
{
|
|
|
|
TRACE("found instance ID %s\n", debugstr_w(deviceInst));
|
|
|
|
if (!enumstr || !lstrcmpiW(enumstr, deviceInst))
|
|
|
|
{
|
|
|
|
HKEY deviceKey;
|
|
|
|
|
|
|
|
l = RegOpenKeyExW(enumKey, deviceInst, 0, KEY_READ,
|
|
|
|
&deviceKey);
|
|
|
|
if (!l)
|
|
|
|
{
|
|
|
|
WCHAR deviceClassStr[40];
|
|
|
|
|
|
|
|
len = sizeof(deviceClassStr);
|
|
|
|
l = RegQueryValueExW(deviceKey, ClassGUID, NULL,
|
|
|
|
&dataType, (BYTE *)deviceClassStr, &len);
|
|
|
|
if (!l && dataType == REG_SZ &&
|
|
|
|
deviceClassStr[0] == '{' &&
|
|
|
|
deviceClassStr[37] == '}')
|
|
|
|
{
|
|
|
|
GUID deviceClass;
|
2018-07-30 03:26:25 +02:00
|
|
|
struct device *device;
|
2007-09-20 18:16:45 +02:00
|
|
|
|
|
|
|
deviceClassStr[37] = 0;
|
|
|
|
UuidFromStringW(&deviceClassStr[1],
|
|
|
|
&deviceClass);
|
2019-05-28 05:13:20 +02:00
|
|
|
if ((device = create_device(set, &deviceClass, deviceInst, FALSE)))
|
2018-08-17 01:37:39 +02:00
|
|
|
SETUPDI_AddDeviceInterfaces(device, subKey, guid, flags);
|
2007-09-20 18:16:45 +02:00
|
|
|
}
|
|
|
|
RegCloseKey(deviceKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RegCloseKey(subKey);
|
|
|
|
}
|
2007-10-12 17:26:56 +02:00
|
|
|
/* Allow enumeration to continue */
|
|
|
|
l = ERROR_SUCCESS;
|
2007-09-20 18:16:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (enumKey != INVALID_HANDLE_VALUE)
|
|
|
|
RegCloseKey(enumKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SETUPDI_EnumerateInterfaces(HDEVINFO DeviceInfoSet,
|
2009-02-09 13:04:55 +01:00
|
|
|
const GUID *guid, LPCWSTR enumstr, DWORD flags)
|
2007-09-20 18:16:45 +02:00
|
|
|
{
|
2009-02-09 13:04:55 +01:00
|
|
|
HKEY interfacesKey = SetupDiOpenClassRegKeyExW(guid, KEY_READ,
|
2007-09-20 18:16:45 +02:00
|
|
|
DIOCR_INTERFACE, NULL, NULL);
|
|
|
|
|
2009-02-09 13:04:55 +01:00
|
|
|
TRACE("%p, %s, %s, %08x\n", DeviceInfoSet, debugstr_guid(guid),
|
2007-09-20 18:16:45 +02:00
|
|
|
debugstr_w(enumstr), flags);
|
|
|
|
|
|
|
|
if (interfacesKey != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
if (flags & DIGCF_ALLCLASSES)
|
|
|
|
{
|
|
|
|
DWORD i, len;
|
|
|
|
WCHAR interfaceGuidStr[40];
|
|
|
|
LONG l = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
for (i = 0; !l; i++)
|
|
|
|
{
|
2018-09-15 00:10:28 +02:00
|
|
|
len = ARRAY_SIZE(interfaceGuidStr);
|
2007-09-20 18:16:45 +02:00
|
|
|
l = RegEnumKeyExW(interfacesKey, i, interfaceGuidStr, &len,
|
|
|
|
NULL, NULL, NULL, NULL);
|
|
|
|
if (!l)
|
|
|
|
{
|
|
|
|
if (interfaceGuidStr[0] == '{' &&
|
|
|
|
interfaceGuidStr[37] == '}')
|
|
|
|
{
|
|
|
|
HKEY interfaceKey;
|
|
|
|
GUID interfaceGuid;
|
|
|
|
|
|
|
|
interfaceGuidStr[37] = 0;
|
|
|
|
UuidFromStringW(&interfaceGuidStr[1], &interfaceGuid);
|
2015-05-01 14:58:37 +02:00
|
|
|
interfaceGuidStr[37] = '}';
|
|
|
|
interfaceGuidStr[38] = 0;
|
2007-09-20 18:16:45 +02:00
|
|
|
l = RegOpenKeyExW(interfacesKey, interfaceGuidStr, 0,
|
|
|
|
KEY_READ, &interfaceKey);
|
|
|
|
if (!l)
|
|
|
|
{
|
|
|
|
SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet,
|
2018-08-17 01:37:39 +02:00
|
|
|
interfaceKey, &interfaceGuid, enumstr, flags);
|
2007-09-20 18:16:45 +02:00
|
|
|
RegCloseKey(interfaceKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* In this case, SetupDiOpenClassRegKeyExW opened the specific
|
|
|
|
* interface's key, so just pass that long
|
|
|
|
*/
|
|
|
|
SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet,
|
2018-08-17 01:37:39 +02:00
|
|
|
interfacesKey, guid, enumstr, flags);
|
2007-09-20 18:16:45 +02:00
|
|
|
}
|
|
|
|
RegCloseKey(interfacesKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-12 17:30:10 +02:00
|
|
|
static void SETUPDI_EnumerateMatchingDeviceInstances(struct DeviceInfoSet *set,
|
|
|
|
LPCWSTR enumerator, LPCWSTR deviceName, HKEY deviceKey,
|
|
|
|
const GUID *class, DWORD flags)
|
2007-09-20 18:16:45 +02:00
|
|
|
{
|
2018-11-28 02:55:38 +01:00
|
|
|
WCHAR id[MAX_DEVICE_ID_LEN];
|
2007-09-20 18:16:45 +02:00
|
|
|
DWORD i, len;
|
2007-10-12 17:30:10 +02:00
|
|
|
WCHAR deviceInstance[MAX_PATH];
|
2007-09-20 18:16:45 +02:00
|
|
|
LONG l = ERROR_SUCCESS;
|
|
|
|
|
2007-10-12 17:30:10 +02:00
|
|
|
TRACE("%s %s\n", debugstr_w(enumerator), debugstr_w(deviceName));
|
2007-09-20 18:16:45 +02:00
|
|
|
|
|
|
|
for (i = 0; !l; i++)
|
|
|
|
{
|
2018-09-15 00:10:28 +02:00
|
|
|
len = ARRAY_SIZE(deviceInstance);
|
2007-10-12 17:30:10 +02:00
|
|
|
l = RegEnumKeyExW(deviceKey, i, deviceInstance, &len, NULL, NULL, NULL,
|
|
|
|
NULL);
|
2007-09-20 18:16:45 +02:00
|
|
|
if (!l)
|
|
|
|
{
|
|
|
|
HKEY subKey;
|
|
|
|
|
2007-10-12 17:30:10 +02:00
|
|
|
l = RegOpenKeyExW(deviceKey, deviceInstance, 0, KEY_READ, &subKey);
|
2007-09-20 18:16:45 +02:00
|
|
|
if (!l)
|
|
|
|
{
|
|
|
|
WCHAR classGuid[40];
|
|
|
|
DWORD dataType;
|
|
|
|
|
|
|
|
len = sizeof(classGuid);
|
|
|
|
l = RegQueryValueExW(subKey, ClassGUID, NULL, &dataType,
|
|
|
|
(BYTE *)classGuid, &len);
|
|
|
|
if (!l && dataType == REG_SZ)
|
|
|
|
{
|
|
|
|
if (classGuid[0] == '{' && classGuid[37] == '}')
|
|
|
|
{
|
|
|
|
GUID deviceClass;
|
|
|
|
|
|
|
|
classGuid[37] = 0;
|
|
|
|
UuidFromStringW(&classGuid[1], &deviceClass);
|
|
|
|
if ((flags & DIGCF_ALLCLASSES) ||
|
|
|
|
IsEqualGUID(class, &deviceClass))
|
|
|
|
{
|
2007-10-25 17:10:59 +02:00
|
|
|
static const WCHAR fmt[] =
|
|
|
|
{'%','s','\\','%','s','\\','%','s',0};
|
2007-09-20 18:16:45 +02:00
|
|
|
|
2019-07-04 15:41:03 +02:00
|
|
|
if (swprintf(id, ARRAY_SIZE(id), fmt, enumerator,
|
2018-11-28 02:55:38 +01:00
|
|
|
deviceName, deviceInstance) != -1)
|
2007-09-20 18:16:45 +02:00
|
|
|
{
|
2019-05-28 05:13:20 +02:00
|
|
|
create_device(set, &deviceClass, id, FALSE);
|
2007-09-20 18:16:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RegCloseKey(subKey);
|
|
|
|
}
|
2007-10-12 17:26:56 +02:00
|
|
|
/* Allow enumeration to continue */
|
|
|
|
l = ERROR_SUCCESS;
|
2007-09-20 18:16:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-12 17:30:10 +02:00
|
|
|
static void SETUPDI_EnumerateMatchingDevices(HDEVINFO DeviceInfoSet,
|
|
|
|
LPCWSTR parent, HKEY key, const GUID *class, DWORD flags)
|
|
|
|
{
|
2009-01-28 10:24:55 +01:00
|
|
|
struct DeviceInfoSet *set = DeviceInfoSet;
|
2007-10-12 17:30:10 +02:00
|
|
|
DWORD i, len;
|
|
|
|
WCHAR subKeyName[MAX_PATH];
|
|
|
|
LONG l = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(parent));
|
|
|
|
|
|
|
|
for (i = 0; !l; i++)
|
|
|
|
{
|
2018-09-15 00:10:28 +02:00
|
|
|
len = ARRAY_SIZE(subKeyName);
|
2007-10-12 17:30:10 +02:00
|
|
|
l = RegEnumKeyExW(key, i, subKeyName, &len, NULL, NULL, NULL, NULL);
|
|
|
|
if (!l)
|
|
|
|
{
|
|
|
|
HKEY subKey;
|
|
|
|
|
|
|
|
l = RegOpenKeyExW(key, subKeyName, 0, KEY_READ, &subKey);
|
|
|
|
if (!l)
|
|
|
|
{
|
|
|
|
TRACE("%s\n", debugstr_w(subKeyName));
|
|
|
|
SETUPDI_EnumerateMatchingDeviceInstances(set, parent,
|
|
|
|
subKeyName, subKey, class, flags);
|
|
|
|
RegCloseKey(subKey);
|
|
|
|
}
|
|
|
|
/* Allow enumeration to continue */
|
|
|
|
l = ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-20 18:16:45 +02:00
|
|
|
static void SETUPDI_EnumerateDevices(HDEVINFO DeviceInfoSet, const GUID *class,
|
|
|
|
LPCWSTR enumstr, DWORD flags)
|
|
|
|
{
|
2007-10-12 17:30:10 +02:00
|
|
|
HKEY enumKey;
|
|
|
|
LONG l;
|
2007-09-20 18:16:45 +02:00
|
|
|
|
|
|
|
TRACE("%p, %s, %s, %08x\n", DeviceInfoSet, debugstr_guid(class),
|
|
|
|
debugstr_w(enumstr), flags);
|
|
|
|
|
2007-10-12 17:30:10 +02:00
|
|
|
l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_READ, NULL,
|
|
|
|
&enumKey, NULL);
|
|
|
|
if (enumKey != INVALID_HANDLE_VALUE)
|
2007-09-20 18:16:45 +02:00
|
|
|
{
|
|
|
|
if (enumstr)
|
|
|
|
{
|
2007-10-12 17:30:10 +02:00
|
|
|
HKEY enumStrKey;
|
2007-09-20 18:16:45 +02:00
|
|
|
|
2007-10-12 17:30:10 +02:00
|
|
|
l = RegOpenKeyExW(enumKey, enumstr, 0, KEY_READ,
|
|
|
|
&enumStrKey);
|
2007-09-20 18:16:45 +02:00
|
|
|
if (!l)
|
|
|
|
{
|
2019-07-16 11:36:48 +02:00
|
|
|
WCHAR *bus, *device;
|
|
|
|
|
|
|
|
if (!wcschr(enumstr, '\\'))
|
|
|
|
{
|
|
|
|
SETUPDI_EnumerateMatchingDevices(DeviceInfoSet, enumstr, enumStrKey, class, flags);
|
|
|
|
}
|
|
|
|
else if ((bus = strdupW(enumstr)))
|
|
|
|
{
|
|
|
|
device = wcschr(bus, '\\');
|
|
|
|
*device++ = 0;
|
|
|
|
|
|
|
|
SETUPDI_EnumerateMatchingDeviceInstances(DeviceInfoSet, bus, device, enumStrKey, class, flags);
|
|
|
|
HeapFree(GetProcessHeap(), 0, bus);
|
|
|
|
}
|
|
|
|
|
2007-10-12 17:30:10 +02:00
|
|
|
RegCloseKey(enumStrKey);
|
2007-09-20 18:16:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD i, len;
|
|
|
|
WCHAR subKeyName[MAX_PATH];
|
|
|
|
|
2007-10-12 17:30:10 +02:00
|
|
|
l = ERROR_SUCCESS;
|
2007-09-20 18:16:45 +02:00
|
|
|
for (i = 0; !l; i++)
|
|
|
|
{
|
2018-09-15 00:10:28 +02:00
|
|
|
len = ARRAY_SIZE(subKeyName);
|
2007-10-12 17:30:10 +02:00
|
|
|
l = RegEnumKeyExW(enumKey, i, subKeyName, &len, NULL,
|
2007-09-20 18:16:45 +02:00
|
|
|
NULL, NULL, NULL);
|
|
|
|
if (!l)
|
|
|
|
{
|
|
|
|
HKEY subKey;
|
|
|
|
|
2007-10-12 17:30:10 +02:00
|
|
|
l = RegOpenKeyExW(enumKey, subKeyName, 0, KEY_READ,
|
2007-09-20 18:16:45 +02:00
|
|
|
&subKey);
|
|
|
|
if (!l)
|
|
|
|
{
|
|
|
|
SETUPDI_EnumerateMatchingDevices(DeviceInfoSet,
|
|
|
|
subKeyName, subKey, class, flags);
|
|
|
|
RegCloseKey(subKey);
|
|
|
|
}
|
2007-10-12 17:26:56 +02:00
|
|
|
/* Allow enumeration to continue */
|
|
|
|
l = ERROR_SUCCESS;
|
2007-09-20 18:16:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-10-12 17:30:10 +02:00
|
|
|
RegCloseKey(enumKey);
|
2007-09-20 18:16:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-10 20:57:32 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiGetClassDevsW (SETUPAPI.@)
|
|
|
|
*/
|
2013-09-23 00:37:16 +02:00
|
|
|
HDEVINFO WINAPI SetupDiGetClassDevsW(const GUID *class, LPCWSTR enumstr, HWND parent, DWORD flags)
|
2002-10-10 20:57:32 +02:00
|
|
|
{
|
2007-09-24 22:02:01 +02:00
|
|
|
return SetupDiGetClassDevsExW(class, enumstr, parent, flags, NULL, NULL,
|
|
|
|
NULL);
|
2005-03-01 12:44:27 +01:00
|
|
|
}
|
|
|
|
|
2006-07-24 13:13:47 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiGetClassDevsExW (SETUPAPI.@)
|
|
|
|
*/
|
2013-09-23 00:37:16 +02:00
|
|
|
HDEVINFO WINAPI SetupDiGetClassDevsExW(const GUID *class, PCWSTR enumstr, HWND parent, DWORD flags,
|
|
|
|
HDEVINFO deviceset, PCWSTR machine, void *reserved)
|
2006-07-24 13:13:47 +02:00
|
|
|
{
|
2018-08-17 01:37:39 +02:00
|
|
|
static const DWORD unsupportedFlags = DIGCF_DEFAULT | DIGCF_PROFILE;
|
2007-09-24 22:00:42 +02:00
|
|
|
HDEVINFO set;
|
|
|
|
|
|
|
|
TRACE("%s %s %p 0x%08x %p %s %p\n", debugstr_guid(class),
|
|
|
|
debugstr_w(enumstr), parent, flags, deviceset, debugstr_w(machine),
|
|
|
|
reserved);
|
|
|
|
|
|
|
|
if (!(flags & DIGCF_ALLCLASSES) && !class)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
2015-07-22 11:57:14 +02:00
|
|
|
return INVALID_HANDLE_VALUE;
|
2007-09-24 22:00:42 +02:00
|
|
|
}
|
2019-05-28 05:13:16 +02:00
|
|
|
if (flags & DIGCF_ALLCLASSES)
|
|
|
|
class = NULL;
|
|
|
|
|
2007-09-24 22:00:42 +02:00
|
|
|
if (flags & unsupportedFlags)
|
|
|
|
WARN("unsupported flags %08x\n", flags & unsupportedFlags);
|
|
|
|
if (deviceset)
|
|
|
|
set = deviceset;
|
|
|
|
else
|
2019-05-28 05:13:18 +02:00
|
|
|
set = SetupDiCreateDeviceInfoListExW((flags & DIGCF_DEVICEINTERFACE) ? NULL : class, parent, machine, reserved);
|
2015-07-22 11:57:19 +02:00
|
|
|
if (set != INVALID_HANDLE_VALUE)
|
2007-09-24 22:00:42 +02:00
|
|
|
{
|
2011-06-09 20:35:11 +02:00
|
|
|
if (machine && *machine)
|
2007-09-24 22:00:42 +02:00
|
|
|
FIXME("%s: unimplemented for remote machines\n",
|
|
|
|
debugstr_w(machine));
|
|
|
|
else if (flags & DIGCF_DEVICEINTERFACE)
|
|
|
|
SETUPDI_EnumerateInterfaces(set, class, enumstr, flags);
|
|
|
|
else
|
|
|
|
SETUPDI_EnumerateDevices(set, class, enumstr, flags);
|
|
|
|
}
|
|
|
|
return set;
|
2006-07-24 13:13:47 +02:00
|
|
|
}
|
|
|
|
|
2007-09-24 21:45:42 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiGetDeviceInfoListDetailA (SETUPAPI.@)
|
|
|
|
*/
|
2018-11-26 00:31:48 +01:00
|
|
|
BOOL WINAPI SetupDiGetDeviceInfoListDetailA(HDEVINFO devinfo, SP_DEVINFO_LIST_DETAIL_DATA_A *DevInfoData)
|
2007-09-24 21:45:42 +02:00
|
|
|
{
|
2018-11-26 00:31:48 +01:00
|
|
|
struct DeviceInfoSet *set;
|
2007-09-24 21:45:42 +02:00
|
|
|
|
2018-11-26 00:31:48 +01:00
|
|
|
TRACE("devinfo %p, detail_data %p.\n", devinfo, DevInfoData);
|
2007-09-24 21:45:42 +02:00
|
|
|
|
2018-11-26 00:31:48 +01:00
|
|
|
if (!(set = get_device_set(devinfo)))
|
2007-09-24 21:45:42 +02:00
|
|
|
return FALSE;
|
2018-11-26 00:31:48 +01:00
|
|
|
|
2007-09-24 21:45:42 +02:00
|
|
|
if (!DevInfoData ||
|
|
|
|
DevInfoData->cbSize != sizeof(SP_DEVINFO_LIST_DETAIL_DATA_A))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-03-16 00:25:45 +01:00
|
|
|
DevInfoData->ClassGuid = set->ClassGuid;
|
2007-09-24 21:45:42 +02:00
|
|
|
DevInfoData->RemoteMachineHandle = NULL;
|
|
|
|
DevInfoData->RemoteMachineName[0] = '\0';
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiGetDeviceInfoListDetailW (SETUPAPI.@)
|
|
|
|
*/
|
2018-11-26 00:31:48 +01:00
|
|
|
BOOL WINAPI SetupDiGetDeviceInfoListDetailW(HDEVINFO devinfo, SP_DEVINFO_LIST_DETAIL_DATA_W *DevInfoData)
|
2007-09-24 21:45:42 +02:00
|
|
|
{
|
2018-11-26 00:31:48 +01:00
|
|
|
struct DeviceInfoSet *set;
|
2007-09-24 21:45:42 +02:00
|
|
|
|
2018-11-26 00:31:48 +01:00
|
|
|
TRACE("devinfo %p, detail_data %p.\n", devinfo, DevInfoData);
|
2007-09-24 21:45:42 +02:00
|
|
|
|
2018-11-26 00:31:48 +01:00
|
|
|
if (!(set = get_device_set(devinfo)))
|
2007-09-24 21:45:42 +02:00
|
|
|
return FALSE;
|
2018-11-26 00:31:48 +01:00
|
|
|
|
2007-09-24 21:45:42 +02:00
|
|
|
if (!DevInfoData ||
|
|
|
|
DevInfoData->cbSize != sizeof(SP_DEVINFO_LIST_DETAIL_DATA_W))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-03-16 00:25:45 +01:00
|
|
|
DevInfoData->ClassGuid = set->ClassGuid;
|
2007-09-24 21:45:42 +02:00
|
|
|
DevInfoData->RemoteMachineHandle = NULL;
|
|
|
|
DevInfoData->RemoteMachineName[0] = '\0';
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-09-21 20:33:43 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiCreateDeviceInterfaceA (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiCreateDeviceInterfaceA(
|
|
|
|
HDEVINFO DeviceInfoSet,
|
|
|
|
PSP_DEVINFO_DATA DeviceInfoData,
|
|
|
|
const GUID *InterfaceClassGuid,
|
|
|
|
PCSTR ReferenceString,
|
|
|
|
DWORD CreationFlags,
|
|
|
|
PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
|
|
|
|
{
|
2007-09-21 20:34:30 +02:00
|
|
|
BOOL ret;
|
|
|
|
LPWSTR ReferenceStringW = NULL;
|
|
|
|
|
2007-09-21 20:33:43 +02:00
|
|
|
TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet, DeviceInfoData,
|
|
|
|
debugstr_guid(InterfaceClassGuid), debugstr_a(ReferenceString),
|
|
|
|
CreationFlags, DeviceInterfaceData);
|
|
|
|
|
2007-09-21 20:34:30 +02:00
|
|
|
if (ReferenceString)
|
|
|
|
{
|
|
|
|
ReferenceStringW = MultiByteToUnicode(ReferenceString, CP_ACP);
|
|
|
|
if (ReferenceStringW == NULL) return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = SetupDiCreateDeviceInterfaceW(DeviceInfoSet, DeviceInfoData,
|
|
|
|
InterfaceClassGuid, ReferenceStringW, CreationFlags,
|
|
|
|
DeviceInterfaceData);
|
|
|
|
|
|
|
|
MyFree(ReferenceStringW);
|
|
|
|
|
|
|
|
return ret;
|
2007-09-21 20:33:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiCreateDeviceInterfaceW (SETUPAPI.@)
|
|
|
|
*/
|
2018-11-26 00:31:46 +01:00
|
|
|
BOOL WINAPI SetupDiCreateDeviceInterfaceW(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data,
|
|
|
|
const GUID *class, const WCHAR *refstr, DWORD flags, SP_DEVICE_INTERFACE_DATA *iface_data)
|
2007-09-21 20:33:43 +02:00
|
|
|
{
|
2018-07-30 03:26:24 +02:00
|
|
|
struct device *device;
|
2018-07-30 03:26:27 +02:00
|
|
|
struct device_iface *iface;
|
2007-09-21 20:34:53 +02:00
|
|
|
|
2018-11-26 00:31:46 +01:00
|
|
|
TRACE("devinfo %p, device_data %p, class %s, refstr %s, flags %#x, iface_data %p.\n",
|
|
|
|
devinfo, device_data, debugstr_guid(class), debugstr_w(refstr), flags, iface_data);
|
2007-09-21 20:33:43 +02:00
|
|
|
|
2018-11-26 00:31:46 +01:00
|
|
|
if (!(device = get_device(devinfo, device_data)))
|
2007-09-22 02:07:37 +02:00
|
|
|
return FALSE;
|
2018-11-26 00:31:46 +01:00
|
|
|
|
|
|
|
if (!class)
|
2007-09-21 20:34:53 +02:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_USER_BUFFER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-11-26 00:31:46 +01:00
|
|
|
|
|
|
|
if (!(iface = SETUPDI_CreateDeviceInterface(device, class, refstr)))
|
2018-07-30 03:26:27 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (iface_data)
|
2007-09-21 20:36:12 +02:00
|
|
|
{
|
2018-07-30 03:26:27 +02:00
|
|
|
if (iface_data->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA))
|
2007-09-21 20:36:12 +02:00
|
|
|
{
|
2018-07-30 03:26:27 +02:00
|
|
|
SetLastError(ERROR_INVALID_USER_BUFFER);
|
|
|
|
return FALSE;
|
2007-09-21 20:36:12 +02:00
|
|
|
}
|
2018-07-30 03:26:27 +02:00
|
|
|
|
|
|
|
copy_device_iface_data(iface_data, iface);
|
2007-09-21 20:36:12 +02:00
|
|
|
}
|
2018-07-30 03:26:27 +02:00
|
|
|
return TRUE;
|
2007-09-21 20:33:43 +02:00
|
|
|
}
|
|
|
|
|
2007-09-22 02:05:48 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiCreateDeviceInterfaceRegKeyA (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
HKEY WINAPI SetupDiCreateDeviceInterfaceRegKeyA(
|
|
|
|
HDEVINFO DeviceInfoSet,
|
|
|
|
PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
|
|
|
|
DWORD Reserved,
|
|
|
|
REGSAM samDesired,
|
|
|
|
HINF InfHandle,
|
|
|
|
PCSTR InfSectionName)
|
|
|
|
{
|
2007-09-22 02:07:16 +02:00
|
|
|
HKEY key;
|
|
|
|
PWSTR InfSectionNameW = NULL;
|
|
|
|
|
|
|
|
TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet, DeviceInterfaceData, Reserved,
|
2007-09-22 02:05:48 +02:00
|
|
|
samDesired, InfHandle, InfSectionName);
|
2007-09-22 02:07:16 +02:00
|
|
|
if (InfHandle)
|
|
|
|
{
|
|
|
|
if (!InfSectionName)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
InfSectionNameW = MultiByteToUnicode(InfSectionName, CP_ACP);
|
|
|
|
if (!InfSectionNameW)
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
key = SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet,
|
|
|
|
DeviceInterfaceData, Reserved, samDesired, InfHandle,
|
|
|
|
InfSectionNameW);
|
|
|
|
MyFree(InfSectionNameW);
|
|
|
|
return key;
|
2007-09-22 02:05:48 +02:00
|
|
|
}
|
|
|
|
|
2019-05-23 05:55:57 +02:00
|
|
|
static LONG create_iface_key(const struct device_iface *iface, REGSAM access, HKEY *key)
|
|
|
|
{
|
|
|
|
return RegCreateKeyExW(iface->refstr_key, DeviceParameters, 0, NULL, 0, access, NULL, key, NULL);
|
|
|
|
}
|
|
|
|
|
2007-09-22 02:05:48 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiCreateDeviceInterfaceRegKeyW (SETUPAPI.@)
|
|
|
|
*/
|
2018-07-30 03:26:28 +02:00
|
|
|
HKEY WINAPI SetupDiCreateDeviceInterfaceRegKeyW(HDEVINFO devinfo,
|
|
|
|
SP_DEVICE_INTERFACE_DATA *iface_data, DWORD reserved, REGSAM access,
|
|
|
|
HINF hinf, const WCHAR *section)
|
2007-09-22 02:05:48 +02:00
|
|
|
{
|
2018-07-30 03:26:28 +02:00
|
|
|
struct device_iface *iface;
|
2018-11-27 02:26:43 +01:00
|
|
|
HKEY params_key;
|
2018-07-30 03:26:28 +02:00
|
|
|
LONG ret;
|
2007-09-22 02:07:16 +02:00
|
|
|
|
2018-11-26 00:31:47 +01:00
|
|
|
TRACE("devinfo %p, iface_data %p, reserved %d, access %#x, hinf %p, section %s.\n",
|
|
|
|
devinfo, iface_data, reserved, access, hinf, debugstr_w(section));
|
|
|
|
|
|
|
|
if (!(iface = get_device_iface(devinfo, iface_data)))
|
2019-02-20 11:57:21 +01:00
|
|
|
return INVALID_HANDLE_VALUE;
|
2007-09-22 02:07:16 +02:00
|
|
|
|
2018-07-30 03:26:28 +02:00
|
|
|
if (hinf && !section)
|
2007-09-22 02:07:16 +02:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
2019-05-23 05:55:57 +02:00
|
|
|
ret = create_iface_key(iface, access, ¶ms_key);
|
2018-07-30 03:26:28 +02:00
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
SetLastError(ret);
|
|
|
|
return INVALID_HANDLE_VALUE;
|
2007-09-22 02:07:16 +02:00
|
|
|
}
|
2018-07-30 03:26:28 +02:00
|
|
|
|
|
|
|
return params_key;
|
2007-09-22 02:05:48 +02:00
|
|
|
}
|
|
|
|
|
2007-09-22 02:08:28 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiDeleteDeviceInterfaceRegKey (SETUPAPI.@)
|
|
|
|
*/
|
2018-07-30 03:26:29 +02:00
|
|
|
BOOL WINAPI SetupDiDeleteDeviceInterfaceRegKey(HDEVINFO devinfo,
|
|
|
|
SP_DEVICE_INTERFACE_DATA *iface_data, DWORD reserved)
|
2007-09-22 02:08:28 +02:00
|
|
|
{
|
2018-07-30 03:26:29 +02:00
|
|
|
struct device_iface *iface;
|
|
|
|
LONG ret;
|
2007-09-22 02:08:28 +02:00
|
|
|
|
2018-11-26 00:31:47 +01:00
|
|
|
TRACE("devinfo %p, iface_data %p, reserved %d.\n", devinfo, iface_data, reserved);
|
2007-09-22 02:08:28 +02:00
|
|
|
|
2018-11-26 00:31:47 +01:00
|
|
|
if (!(iface = get_device_iface(devinfo, iface_data)))
|
2007-09-22 02:08:28 +02:00
|
|
|
return FALSE;
|
2018-07-30 03:26:29 +02:00
|
|
|
|
2018-11-27 02:26:43 +01:00
|
|
|
ret = RegDeleteKeyW(iface->refstr_key, DeviceParameters);
|
2018-07-30 03:26:29 +02:00
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
SetLastError(ret);
|
|
|
|
return FALSE;
|
2007-09-22 02:08:28 +02:00
|
|
|
}
|
2018-07-30 03:26:29 +02:00
|
|
|
|
|
|
|
return TRUE;
|
2007-09-22 02:08:28 +02:00
|
|
|
}
|
|
|
|
|
2005-03-01 12:44:27 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiEnumDeviceInterfaces (SETUPAPI.@)
|
2007-09-21 20:36:37 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* DeviceInfoSet [I] Set of devices from which to enumerate
|
|
|
|
* interfaces
|
|
|
|
* DeviceInfoData [I] (Optional) If specified, a specific device
|
|
|
|
* instance from which to enumerate interfaces.
|
|
|
|
* If it isn't specified, all interfaces for all
|
|
|
|
* devices in the set are enumerated.
|
|
|
|
* InterfaceClassGuid [I] The interface class to enumerate.
|
|
|
|
* MemberIndex [I] An index of the interface instance to enumerate.
|
|
|
|
* A caller should start with MemberIndex set to 0,
|
|
|
|
* and continue until the function fails with
|
|
|
|
* ERROR_NO_MORE_ITEMS.
|
|
|
|
* DeviceInterfaceData [I/O] Returns an enumerated interface. Its cbSize
|
|
|
|
* member must be set to
|
|
|
|
* sizeof(SP_DEVICE_INTERFACE_DATA).
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: non-zero value.
|
|
|
|
* Failure: FALSE. Call GetLastError() for more info.
|
2005-03-01 12:44:27 +01:00
|
|
|
*/
|
2018-07-30 03:26:27 +02:00
|
|
|
BOOL WINAPI SetupDiEnumDeviceInterfaces(HDEVINFO devinfo,
|
|
|
|
SP_DEVINFO_DATA *device_data, const GUID *class, DWORD index,
|
|
|
|
SP_DEVICE_INTERFACE_DATA *iface_data)
|
2005-03-01 12:44:27 +01:00
|
|
|
{
|
2018-11-26 00:31:48 +01:00
|
|
|
struct DeviceInfoSet *set;
|
2018-07-30 03:26:27 +02:00
|
|
|
struct device *device;
|
|
|
|
struct device_iface *iface;
|
|
|
|
DWORD i = 0;
|
2005-03-01 12:44:27 +01:00
|
|
|
|
2018-11-26 00:31:48 +01:00
|
|
|
TRACE("devinfo %p, device_data %p, class %s, index %u, iface_data %p.\n",
|
|
|
|
devinfo, device_data, debugstr_guid(class), index, iface_data);
|
2005-03-01 12:44:27 +01:00
|
|
|
|
2018-07-30 03:26:27 +02:00
|
|
|
if (!iface_data || iface_data->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA))
|
2007-09-21 20:36:37 +02:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-03-15 00:45:19 +01:00
|
|
|
|
2011-05-14 23:55:28 +02:00
|
|
|
/* In case application fails to check return value, clear output */
|
2018-07-30 03:26:27 +02:00
|
|
|
memset(iface_data, 0, sizeof(*iface_data));
|
|
|
|
iface_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
|
2014-03-15 00:45:19 +01:00
|
|
|
|
2018-07-30 03:26:27 +02:00
|
|
|
if (device_data)
|
2007-09-21 20:36:37 +02:00
|
|
|
{
|
2018-11-26 00:31:48 +01:00
|
|
|
if (!(device = get_device(devinfo, device_data)))
|
|
|
|
return FALSE;
|
2007-09-21 20:36:37 +02:00
|
|
|
|
2018-07-30 03:26:27 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(iface, &device->interfaces, struct device_iface, entry)
|
2007-09-21 20:36:37 +02:00
|
|
|
{
|
2018-07-30 03:26:27 +02:00
|
|
|
if (IsEqualGUID(&iface->class, class))
|
2007-09-21 20:36:37 +02:00
|
|
|
{
|
2018-07-30 03:26:27 +02:00
|
|
|
if (i == index)
|
|
|
|
{
|
|
|
|
copy_device_iface_data(iface_data, iface);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
i++;
|
2007-09-21 20:36:37 +02:00
|
|
|
}
|
|
|
|
}
|
2006-08-04 22:31:59 +02:00
|
|
|
}
|
|
|
|
else
|
2007-09-21 20:36:37 +02:00
|
|
|
{
|
2018-11-26 00:31:48 +01:00
|
|
|
if (!(set = get_device_set(devinfo)))
|
|
|
|
return FALSE;
|
|
|
|
|
2018-07-30 03:26:24 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(device, &set->devices, struct device, entry)
|
2007-09-21 20:36:37 +02:00
|
|
|
{
|
2018-07-30 03:26:27 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(iface, &device->interfaces, struct device_iface, entry)
|
2007-09-21 20:36:37 +02:00
|
|
|
{
|
2018-07-30 03:26:27 +02:00
|
|
|
if (IsEqualGUID(&iface->class, class))
|
2007-09-21 20:36:37 +02:00
|
|
|
{
|
2018-07-30 03:26:27 +02:00
|
|
|
if (i == index)
|
|
|
|
{
|
|
|
|
copy_device_iface_data(iface_data, iface);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
i++;
|
2007-09-21 20:36:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-30 03:26:27 +02:00
|
|
|
|
|
|
|
SetLastError(ERROR_NO_MORE_ITEMS);
|
|
|
|
return FALSE;
|
2005-03-01 12:44:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiDestroyDeviceInfoList (SETUPAPI.@)
|
2006-06-13 19:13:32 +02:00
|
|
|
*
|
|
|
|
* Destroy a DeviceInfoList and free all used memory of the list.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* devinfo [I] DeviceInfoList pointer to list to destroy
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: non zero value.
|
|
|
|
* Failure: zero value.
|
2005-03-01 12:44:27 +01:00
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
|
|
|
|
{
|
2018-11-26 00:31:48 +01:00
|
|
|
struct DeviceInfoSet *set;
|
|
|
|
struct device *device, *device2;
|
2005-03-01 12:44:27 +01:00
|
|
|
|
2018-11-26 00:31:48 +01:00
|
|
|
TRACE("devinfo %p.\n", devinfo);
|
2005-03-01 12:44:27 +01:00
|
|
|
|
2018-11-26 00:31:48 +01:00
|
|
|
if (!(set = get_device_set(devinfo)))
|
|
|
|
return FALSE;
|
2007-09-20 18:09:18 +02:00
|
|
|
|
2018-11-26 00:31:48 +01:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(device, device2, &set->devices, struct device, entry)
|
|
|
|
{
|
2018-11-30 23:42:12 +01:00
|
|
|
delete_device(device);
|
2005-03-01 12:44:27 +01:00
|
|
|
}
|
2018-11-26 00:31:48 +01:00
|
|
|
heap_free(set);
|
2006-06-13 19:13:32 +02:00
|
|
|
|
2018-11-26 00:31:48 +01:00
|
|
|
return TRUE;
|
2002-10-10 20:57:32 +02:00
|
|
|
}
|
2004-12-02 19:09:53 +01:00
|
|
|
|
2002-06-05 00:12:50 +02:00
|
|
|
/***********************************************************************
|
2004-12-02 19:09:53 +01:00
|
|
|
* SetupDiGetDeviceInterfaceDetailA (SETUPAPI.@)
|
2002-06-05 00:12:50 +02:00
|
|
|
*/
|
2018-11-26 00:31:47 +01:00
|
|
|
BOOL WINAPI SetupDiGetDeviceInterfaceDetailA(HDEVINFO devinfo, SP_DEVICE_INTERFACE_DATA *iface_data,
|
|
|
|
SP_DEVICE_INTERFACE_DETAIL_DATA_A *DeviceInterfaceDetailData,
|
|
|
|
DWORD DeviceInterfaceDetailDataSize, DWORD *RequiredSize, SP_DEVINFO_DATA *device_data)
|
2002-05-29 00:39:14 +02:00
|
|
|
{
|
2018-07-30 03:26:27 +02:00
|
|
|
struct device_iface *iface;
|
2009-08-27 20:23:40 +02:00
|
|
|
DWORD bytesNeeded = FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A, DevicePath[1]);
|
2005-03-01 12:44:27 +01:00
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
2018-11-26 00:31:47 +01:00
|
|
|
TRACE("devinfo %p, iface_data %p, detail_data %p, size %d, needed %p, device_data %p.\n",
|
|
|
|
devinfo, iface_data, DeviceInterfaceDetailData, DeviceInterfaceDetailDataSize,
|
|
|
|
RequiredSize, device_data);
|
2005-03-01 12:44:27 +01:00
|
|
|
|
2018-11-26 00:31:47 +01:00
|
|
|
if (!(iface = get_device_iface(devinfo, iface_data)))
|
2007-09-21 20:38:55 +02:00
|
|
|
return FALSE;
|
2018-11-26 00:31:47 +01:00
|
|
|
|
2009-08-27 20:23:40 +02:00
|
|
|
if (DeviceInterfaceDetailData &&
|
|
|
|
DeviceInterfaceDetailData->cbSize != sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A))
|
2007-09-21 20:38:55 +02:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_USER_BUFFER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!DeviceInterfaceDetailData && DeviceInterfaceDetailDataSize)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_USER_BUFFER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-11-26 00:31:47 +01:00
|
|
|
|
2018-07-30 03:26:27 +02:00
|
|
|
if (iface->symlink)
|
|
|
|
bytesNeeded += WideCharToMultiByte(CP_ACP, 0, iface->symlink, -1,
|
2007-09-21 20:38:55 +02:00
|
|
|
NULL, 0, NULL, NULL);
|
|
|
|
if (DeviceInterfaceDetailDataSize >= bytesNeeded)
|
|
|
|
{
|
2018-07-30 03:26:27 +02:00
|
|
|
if (iface->symlink)
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, iface->symlink, -1,
|
2007-09-21 20:38:55 +02:00
|
|
|
DeviceInterfaceDetailData->DevicePath,
|
|
|
|
DeviceInterfaceDetailDataSize -
|
|
|
|
offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A, DevicePath),
|
|
|
|
NULL, NULL);
|
|
|
|
else
|
|
|
|
DeviceInterfaceDetailData->DevicePath[0] = '\0';
|
2018-07-30 03:26:25 +02:00
|
|
|
|
2007-09-21 20:38:55 +02:00
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (RequiredSize)
|
|
|
|
*RequiredSize = bytesNeeded;
|
|
|
|
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
}
|
2018-12-06 04:08:11 +01:00
|
|
|
|
|
|
|
if (device_data && device_data->cbSize == sizeof(SP_DEVINFO_DATA))
|
|
|
|
copy_device_data(device_data, iface->device);
|
|
|
|
|
2005-03-01 12:44:27 +01:00
|
|
|
return ret;
|
2002-05-29 00:39:14 +02:00
|
|
|
}
|
|
|
|
|
2002-06-05 00:12:50 +02:00
|
|
|
/***********************************************************************
|
2004-12-02 19:09:53 +01:00
|
|
|
* SetupDiGetDeviceInterfaceDetailW (SETUPAPI.@)
|
2002-06-05 00:12:50 +02:00
|
|
|
*/
|
2018-11-26 00:31:47 +01:00
|
|
|
BOOL WINAPI SetupDiGetDeviceInterfaceDetailW(HDEVINFO devinfo, SP_DEVICE_INTERFACE_DATA *iface_data,
|
|
|
|
SP_DEVICE_INTERFACE_DETAIL_DATA_W *DeviceInterfaceDetailData,
|
|
|
|
DWORD DeviceInterfaceDetailDataSize, DWORD *RequiredSize, SP_DEVINFO_DATA *device_data)
|
2002-05-29 00:39:14 +02:00
|
|
|
{
|
2018-07-30 03:26:27 +02:00
|
|
|
struct device_iface *iface;
|
2007-09-21 20:38:55 +02:00
|
|
|
DWORD bytesNeeded = offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W, DevicePath)
|
|
|
|
+ sizeof(WCHAR); /* include NULL terminator */
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
2018-11-26 00:31:47 +01:00
|
|
|
TRACE("devinfo %p, iface_data %p, detail_data %p, size %d, needed %p, device_data %p.\n",
|
|
|
|
devinfo, iface_data, DeviceInterfaceDetailData, DeviceInterfaceDetailDataSize,
|
|
|
|
RequiredSize, device_data);
|
2007-09-21 20:38:55 +02:00
|
|
|
|
2018-11-26 00:31:47 +01:00
|
|
|
if (!(iface = get_device_iface(devinfo, iface_data)))
|
2007-09-21 20:38:55 +02:00
|
|
|
return FALSE;
|
2018-11-26 00:31:47 +01:00
|
|
|
|
2007-09-21 20:38:55 +02:00
|
|
|
if (DeviceInterfaceDetailData && (DeviceInterfaceDetailData->cbSize <
|
|
|
|
offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W, DevicePath) + sizeof(WCHAR) ||
|
|
|
|
DeviceInterfaceDetailData->cbSize > sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W)))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_USER_BUFFER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!DeviceInterfaceDetailData && DeviceInterfaceDetailDataSize)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_USER_BUFFER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-11-26 00:31:47 +01:00
|
|
|
|
2018-07-30 03:26:27 +02:00
|
|
|
if (iface->symlink)
|
|
|
|
bytesNeeded += sizeof(WCHAR) * lstrlenW(iface->symlink);
|
2007-09-21 20:38:55 +02:00
|
|
|
if (DeviceInterfaceDetailDataSize >= bytesNeeded)
|
|
|
|
{
|
2018-07-30 03:26:27 +02:00
|
|
|
if (iface->symlink)
|
|
|
|
lstrcpyW(DeviceInterfaceDetailData->DevicePath, iface->symlink);
|
2007-09-21 20:38:55 +02:00
|
|
|
else
|
|
|
|
DeviceInterfaceDetailData->DevicePath[0] = '\0';
|
2018-07-30 03:26:25 +02:00
|
|
|
|
2007-09-21 20:38:55 +02:00
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (RequiredSize)
|
|
|
|
*RequiredSize = bytesNeeded;
|
|
|
|
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
}
|
2018-12-06 04:08:11 +01:00
|
|
|
|
|
|
|
if (device_data && device_data->cbSize == sizeof(SP_DEVINFO_DATA))
|
|
|
|
copy_device_data(device_data, iface->device);
|
|
|
|
|
2007-09-21 20:38:55 +02:00
|
|
|
return ret;
|
2002-05-29 00:39:14 +02:00
|
|
|
}
|
|
|
|
|
2002-06-05 00:12:50 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiGetDeviceRegistryPropertyA (SETUPAPI.@)
|
|
|
|
*/
|
2018-11-26 00:31:46 +01:00
|
|
|
BOOL WINAPI SetupDiGetDeviceRegistryPropertyA(HDEVINFO devinfo,
|
|
|
|
SP_DEVINFO_DATA *device_data, DWORD Property, DWORD *PropertyRegDataType,
|
|
|
|
BYTE *PropertyBuffer, DWORD PropertyBufferSize, DWORD *RequiredSize)
|
2002-05-29 00:39:14 +02:00
|
|
|
{
|
2007-09-20 18:10:10 +02:00
|
|
|
BOOL ret = FALSE;
|
2018-07-30 03:26:24 +02:00
|
|
|
struct device *device;
|
2007-09-20 18:10:10 +02:00
|
|
|
|
2018-11-26 00:31:46 +01:00
|
|
|
TRACE("devinfo %p, device_data %p, property %d, type %p, buffer %p, size %d, required %p\n",
|
|
|
|
devinfo, device_data, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize);
|
2007-09-20 18:10:10 +02:00
|
|
|
|
2018-11-26 00:31:46 +01:00
|
|
|
if (!(device = get_device(devinfo, device_data)))
|
2007-09-20 18:10:10 +02:00
|
|
|
return FALSE;
|
2018-11-26 00:31:46 +01:00
|
|
|
|
2008-04-17 18:28:14 +02:00
|
|
|
if (PropertyBufferSize && PropertyBuffer == NULL)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_DATA);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-11-26 00:31:46 +01:00
|
|
|
|
2018-09-15 00:10:28 +02:00
|
|
|
if (Property < ARRAY_SIZE(PropertyMap) && PropertyMap[Property].nameA)
|
2007-09-20 18:10:10 +02:00
|
|
|
{
|
|
|
|
DWORD size = PropertyBufferSize;
|
2018-07-30 03:26:24 +02:00
|
|
|
LONG l = RegQueryValueExA(device->key, PropertyMap[Property].nameA,
|
2007-09-20 18:10:10 +02:00
|
|
|
NULL, PropertyRegDataType, PropertyBuffer, &size);
|
|
|
|
|
2017-05-02 05:14:57 +02:00
|
|
|
if (l == ERROR_FILE_NOT_FOUND)
|
|
|
|
SetLastError(ERROR_INVALID_DATA);
|
|
|
|
else if (l == ERROR_MORE_DATA || !PropertyBufferSize)
|
2008-04-17 18:28:09 +02:00
|
|
|
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
2007-10-24 19:37:29 +02:00
|
|
|
else if (!l)
|
2007-09-20 18:10:10 +02:00
|
|
|
ret = TRUE;
|
|
|
|
else
|
|
|
|
SetLastError(l);
|
2008-04-17 18:28:09 +02:00
|
|
|
if (RequiredSize)
|
|
|
|
*RequiredSize = size;
|
2007-09-20 18:10:10 +02:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiGetDeviceRegistryPropertyW (SETUPAPI.@)
|
|
|
|
*/
|
2018-11-26 00:31:46 +01:00
|
|
|
BOOL WINAPI SetupDiGetDeviceRegistryPropertyW(HDEVINFO devinfo,
|
|
|
|
SP_DEVINFO_DATA *device_data, DWORD Property, DWORD *PropertyRegDataType,
|
|
|
|
BYTE *PropertyBuffer, DWORD PropertyBufferSize, DWORD *RequiredSize)
|
2007-09-20 18:10:10 +02:00
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
2018-07-30 03:26:24 +02:00
|
|
|
struct device *device;
|
2007-09-20 18:10:10 +02:00
|
|
|
|
2018-11-26 00:31:46 +01:00
|
|
|
TRACE("devinfo %p, device_data %p, prop %d, type %p, buffer %p, size %d, required %p\n",
|
|
|
|
devinfo, device_data, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize);
|
2007-09-20 18:10:10 +02:00
|
|
|
|
2018-11-26 00:31:46 +01:00
|
|
|
if (!(device = get_device(devinfo, device_data)))
|
2007-09-20 18:10:10 +02:00
|
|
|
return FALSE;
|
2018-11-26 00:31:46 +01:00
|
|
|
|
2008-04-17 18:28:14 +02:00
|
|
|
if (PropertyBufferSize && PropertyBuffer == NULL)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_DATA);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-11-26 00:31:46 +01:00
|
|
|
|
2018-09-15 00:10:28 +02:00
|
|
|
if (Property < ARRAY_SIZE(PropertyMap) && PropertyMap[Property].nameW)
|
2007-09-20 18:10:10 +02:00
|
|
|
{
|
|
|
|
DWORD size = PropertyBufferSize;
|
2018-07-30 03:26:24 +02:00
|
|
|
LONG l = RegQueryValueExW(device->key, PropertyMap[Property].nameW,
|
2007-09-20 18:10:10 +02:00
|
|
|
NULL, PropertyRegDataType, PropertyBuffer, &size);
|
|
|
|
|
2017-05-02 05:14:57 +02:00
|
|
|
if (l == ERROR_FILE_NOT_FOUND)
|
|
|
|
SetLastError(ERROR_INVALID_DATA);
|
|
|
|
else if (l == ERROR_MORE_DATA || !PropertyBufferSize)
|
2008-04-17 18:28:09 +02:00
|
|
|
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
2007-10-24 19:37:29 +02:00
|
|
|
else if (!l)
|
2007-09-20 18:10:10 +02:00
|
|
|
ret = TRUE;
|
|
|
|
else
|
|
|
|
SetLastError(l);
|
2008-04-17 18:28:09 +02:00
|
|
|
if (RequiredSize)
|
|
|
|
*RequiredSize = size;
|
2007-09-20 18:10:10 +02:00
|
|
|
}
|
|
|
|
return ret;
|
2002-05-29 00:39:14 +02:00
|
|
|
}
|
2004-12-02 19:09:53 +01:00
|
|
|
|
2007-09-20 18:10:32 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiSetDeviceRegistryPropertyA (SETUPAPI.@)
|
|
|
|
*/
|
2018-11-26 00:31:46 +01:00
|
|
|
BOOL WINAPI SetupDiSetDeviceRegistryPropertyA(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data,
|
|
|
|
DWORD Property, const BYTE *PropertyBuffer, DWORD PropertyBufferSize)
|
2007-09-20 18:10:32 +02:00
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
2018-07-30 03:26:24 +02:00
|
|
|
struct device *device;
|
2007-09-20 18:10:32 +02:00
|
|
|
|
2018-11-26 00:31:46 +01:00
|
|
|
TRACE("devinfo %p, device_data %p, prop %d, buffer %p, size %d.\n",
|
|
|
|
devinfo, device_data, Property, PropertyBuffer, PropertyBufferSize);
|
2007-09-20 18:10:32 +02:00
|
|
|
|
2018-11-26 00:31:46 +01:00
|
|
|
if (!(device = get_device(devinfo, device_data)))
|
2007-09-20 18:10:32 +02:00
|
|
|
return FALSE;
|
2018-11-26 00:31:46 +01:00
|
|
|
|
2018-09-15 00:10:28 +02:00
|
|
|
if (Property < ARRAY_SIZE(PropertyMap) && PropertyMap[Property].nameA)
|
2007-09-20 18:10:32 +02:00
|
|
|
{
|
2018-07-30 03:26:24 +02:00
|
|
|
LONG l = RegSetValueExA(device->key, PropertyMap[Property].nameA, 0,
|
2007-09-20 18:10:32 +02:00
|
|
|
PropertyMap[Property].regType, PropertyBuffer,
|
|
|
|
PropertyBufferSize);
|
|
|
|
if (!l)
|
|
|
|
ret = TRUE;
|
|
|
|
else
|
|
|
|
SetLastError(l);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiSetDeviceRegistryPropertyW (SETUPAPI.@)
|
|
|
|
*/
|
2018-07-30 03:26:23 +02:00
|
|
|
BOOL WINAPI SetupDiSetDeviceRegistryPropertyW(HDEVINFO devinfo,
|
|
|
|
SP_DEVINFO_DATA *device_data, DWORD prop, const BYTE *buffer, DWORD size)
|
2007-09-20 18:10:32 +02:00
|
|
|
{
|
2018-07-30 03:26:24 +02:00
|
|
|
struct device *device;
|
2007-09-20 18:10:32 +02:00
|
|
|
|
2018-11-26 00:31:46 +01:00
|
|
|
TRACE("devinfo %p, device_data %p, prop %d, buffer %p, size %d.\n",
|
|
|
|
devinfo, device_data, prop, buffer, size);
|
2007-09-20 18:10:32 +02:00
|
|
|
|
2018-11-26 00:31:46 +01:00
|
|
|
if (!(device = get_device(devinfo, device_data)))
|
2007-09-20 18:10:32 +02:00
|
|
|
return FALSE;
|
2018-07-30 03:26:23 +02:00
|
|
|
|
|
|
|
return SETUPDI_SetDeviceRegistryPropertyW(device, prop, buffer, size);
|
2007-09-20 18:10:32 +02:00
|
|
|
}
|
|
|
|
|
2004-12-02 19:09:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiInstallClassA (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiInstallClassA(
|
|
|
|
HWND hwndParent,
|
|
|
|
PCSTR InfFileName,
|
|
|
|
DWORD Flags,
|
|
|
|
HSPFILEQ FileQueue)
|
|
|
|
{
|
|
|
|
UNICODE_STRING FileNameW;
|
|
|
|
BOOL Result;
|
|
|
|
|
2007-10-12 17:24:04 +02:00
|
|
|
if (!InfFileName)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-12-02 19:09:53 +01:00
|
|
|
if (!RtlCreateUnicodeStringFromAsciiz(&FileNameW, InfFileName))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Result = SetupDiInstallClassW(hwndParent, FileNameW.Buffer, Flags, FileQueue);
|
|
|
|
|
|
|
|
RtlFreeUnicodeString(&FileNameW);
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HKEY CreateClassKey(HINF hInf)
|
|
|
|
{
|
2007-10-11 22:22:55 +02:00
|
|
|
static const WCHAR slash[] = { '\\',0 };
|
2004-12-02 19:09:53 +01:00
|
|
|
WCHAR FullBuffer[MAX_PATH];
|
|
|
|
WCHAR Buffer[MAX_PATH];
|
|
|
|
DWORD RequiredSize;
|
|
|
|
HKEY hClassKey;
|
|
|
|
|
|
|
|
if (!SetupGetLineTextW(NULL,
|
|
|
|
hInf,
|
|
|
|
Version,
|
|
|
|
ClassGUID,
|
|
|
|
Buffer,
|
|
|
|
MAX_PATH,
|
|
|
|
&RequiredSize))
|
|
|
|
{
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
lstrcpyW(FullBuffer, ControlClass);
|
2007-10-11 22:22:55 +02:00
|
|
|
lstrcatW(FullBuffer, slash);
|
2004-12-02 19:09:53 +01:00
|
|
|
lstrcatW(FullBuffer, Buffer);
|
|
|
|
|
|
|
|
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
|
|
|
FullBuffer,
|
|
|
|
0,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
&hClassKey))
|
|
|
|
{
|
|
|
|
if (!SetupGetLineTextW(NULL,
|
|
|
|
hInf,
|
|
|
|
Version,
|
|
|
|
Class,
|
|
|
|
Buffer,
|
|
|
|
MAX_PATH,
|
|
|
|
&RequiredSize))
|
|
|
|
{
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RegCreateKeyExW(HKEY_LOCAL_MACHINE,
|
|
|
|
FullBuffer,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
REG_OPTION_NON_VOLATILE,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
NULL,
|
|
|
|
&hClassKey,
|
|
|
|
NULL))
|
|
|
|
{
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RegSetValueExW(hClassKey,
|
|
|
|
Class,
|
|
|
|
0,
|
|
|
|
REG_SZ,
|
|
|
|
(LPBYTE)Buffer,
|
|
|
|
RequiredSize * sizeof(WCHAR)))
|
|
|
|
{
|
|
|
|
RegCloseKey(hClassKey);
|
|
|
|
RegDeleteKeyW(HKEY_LOCAL_MACHINE,
|
|
|
|
FullBuffer);
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hClassKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiInstallClassW (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiInstallClassW(
|
|
|
|
HWND hwndParent,
|
|
|
|
PCWSTR InfFileName,
|
|
|
|
DWORD Flags,
|
|
|
|
HSPFILEQ FileQueue)
|
|
|
|
{
|
|
|
|
WCHAR SectionName[MAX_PATH];
|
|
|
|
DWORD SectionNameLength = 0;
|
|
|
|
HINF hInf;
|
|
|
|
BOOL bFileQueueCreated = FALSE;
|
|
|
|
HKEY hClassKey;
|
|
|
|
|
|
|
|
|
|
|
|
FIXME("\n");
|
|
|
|
|
2007-10-12 17:24:04 +02:00
|
|
|
if (!InfFileName)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-12-02 19:09:53 +01:00
|
|
|
if ((Flags & DI_NOVCP) && (FileQueue == NULL || FileQueue == INVALID_HANDLE_VALUE))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Open the .inf file */
|
|
|
|
hInf = SetupOpenInfFileW(InfFileName,
|
|
|
|
NULL,
|
|
|
|
INF_STYLE_WIN4,
|
|
|
|
NULL);
|
|
|
|
if (hInf == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create or open the class registry key 'HKLM\\CurrentControlSet\\Class\\{GUID}' */
|
|
|
|
hClassKey = CreateClassKey(hInf);
|
|
|
|
if (hClassKey == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
SetupCloseInfFile(hInf);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Try to append a layout file */
|
|
|
|
SetupOpenAppendInfFileW(NULL, hInf, NULL);
|
|
|
|
|
|
|
|
/* Retrieve the actual section name */
|
|
|
|
SetupDiGetActualSectionToInstallW(hInf,
|
|
|
|
ClassInstall32,
|
|
|
|
SectionName,
|
|
|
|
MAX_PATH,
|
|
|
|
&SectionNameLength,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (!(Flags & DI_NOVCP))
|
|
|
|
{
|
|
|
|
FileQueue = SetupOpenFileQueue();
|
|
|
|
if (FileQueue == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
SetupCloseInfFile(hInf);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bFileQueueCreated = TRUE;
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
SetupInstallFromInfSectionW(NULL,
|
|
|
|
hInf,
|
|
|
|
SectionName,
|
2007-10-11 22:23:21 +02:00
|
|
|
SPINST_COPYINF | SPINST_FILES | SPINST_REGISTRY,
|
2004-12-02 19:09:53 +01:00
|
|
|
hClassKey,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
INVALID_HANDLE_VALUE,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* FIXME: More code! */
|
|
|
|
|
|
|
|
if (bFileQueueCreated)
|
|
|
|
SetupCloseFileQueue(FileQueue);
|
|
|
|
|
|
|
|
SetupCloseInfFile(hInf);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiOpenClassRegKey (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
HKEY WINAPI SetupDiOpenClassRegKey(
|
|
|
|
const GUID* ClassGuid,
|
|
|
|
REGSAM samDesired)
|
|
|
|
{
|
|
|
|
return SetupDiOpenClassRegKeyExW(ClassGuid, samDesired,
|
|
|
|
DIOCR_INSTALLER, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiOpenClassRegKeyExA (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
HKEY WINAPI SetupDiOpenClassRegKeyExA(
|
|
|
|
const GUID* ClassGuid,
|
|
|
|
REGSAM samDesired,
|
|
|
|
DWORD Flags,
|
|
|
|
PCSTR MachineName,
|
|
|
|
PVOID Reserved)
|
|
|
|
{
|
2005-02-03 14:34:50 +01:00
|
|
|
PWSTR MachineNameW = NULL;
|
|
|
|
HKEY hKey;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
if (MachineName)
|
|
|
|
{
|
|
|
|
MachineNameW = MultiByteToUnicode(MachineName, CP_ACP);
|
|
|
|
if (MachineNameW == NULL)
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
hKey = SetupDiOpenClassRegKeyExW(ClassGuid, samDesired,
|
|
|
|
Flags, MachineNameW, Reserved);
|
|
|
|
|
2006-07-19 19:39:48 +02:00
|
|
|
MyFree(MachineNameW);
|
2005-02-03 14:34:50 +01:00
|
|
|
|
|
|
|
return hKey;
|
2004-12-02 19:09:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiOpenClassRegKeyExW (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
HKEY WINAPI SetupDiOpenClassRegKeyExW(
|
|
|
|
const GUID* ClassGuid,
|
|
|
|
REGSAM samDesired,
|
|
|
|
DWORD Flags,
|
|
|
|
PCWSTR MachineName,
|
|
|
|
PVOID Reserved)
|
|
|
|
{
|
|
|
|
HKEY hClassesKey;
|
2007-09-21 20:33:05 +02:00
|
|
|
HKEY key;
|
2004-12-02 19:09:53 +01:00
|
|
|
LPCWSTR lpKeyName;
|
2007-09-21 20:33:05 +02:00
|
|
|
LONG l;
|
2004-12-02 19:09:53 +01:00
|
|
|
|
2011-06-09 20:35:11 +02:00
|
|
|
if (MachineName && *MachineName)
|
2004-12-02 19:09:53 +01:00
|
|
|
{
|
|
|
|
FIXME("Remote access not supported yet!\n");
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Flags == DIOCR_INSTALLER)
|
|
|
|
{
|
|
|
|
lpKeyName = ControlClass;
|
|
|
|
}
|
|
|
|
else if (Flags == DIOCR_INTERFACE)
|
|
|
|
{
|
|
|
|
lpKeyName = DeviceClasses;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("Invalid Flags parameter!\n");
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
2007-09-21 20:32:24 +02:00
|
|
|
if (!ClassGuid)
|
2004-12-02 19:09:53 +01:00
|
|
|
{
|
2007-09-21 20:33:05 +02:00
|
|
|
if ((l = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
2007-09-21 20:32:24 +02:00
|
|
|
lpKeyName,
|
|
|
|
0,
|
|
|
|
samDesired,
|
2007-09-21 20:33:05 +02:00
|
|
|
&hClassesKey)))
|
2007-09-21 20:32:24 +02:00
|
|
|
{
|
2007-09-21 20:33:05 +02:00
|
|
|
SetLastError(l);
|
|
|
|
hClassesKey = INVALID_HANDLE_VALUE;
|
2007-09-21 20:32:24 +02:00
|
|
|
}
|
2007-09-21 20:33:05 +02:00
|
|
|
key = hClassesKey;
|
2007-09-21 20:32:24 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WCHAR bracedGuidString[39];
|
2004-12-02 19:09:53 +01:00
|
|
|
|
2007-09-21 20:32:24 +02:00
|
|
|
SETUPDI_GuidToString(ClassGuid, bracedGuidString);
|
2004-12-02 19:09:53 +01:00
|
|
|
|
2007-09-21 20:33:05 +02:00
|
|
|
if (!(l = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
2007-09-21 20:32:24 +02:00
|
|
|
lpKeyName,
|
|
|
|
0,
|
|
|
|
samDesired,
|
2007-09-21 20:33:05 +02:00
|
|
|
&hClassesKey)))
|
2007-09-21 20:32:24 +02:00
|
|
|
{
|
2007-09-21 20:33:05 +02:00
|
|
|
if ((l = RegOpenKeyExW(hClassesKey,
|
|
|
|
bracedGuidString,
|
|
|
|
0,
|
|
|
|
samDesired,
|
|
|
|
&key)))
|
|
|
|
{
|
|
|
|
SetLastError(l);
|
|
|
|
key = INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
RegCloseKey(hClassesKey);
|
2007-09-21 20:32:24 +02:00
|
|
|
}
|
2007-09-21 20:33:05 +02:00
|
|
|
else
|
2007-09-21 20:32:24 +02:00
|
|
|
{
|
2007-09-21 20:33:05 +02:00
|
|
|
SetLastError(l);
|
|
|
|
key = INVALID_HANDLE_VALUE;
|
2007-09-21 20:32:24 +02:00
|
|
|
}
|
|
|
|
}
|
2007-09-21 20:33:05 +02:00
|
|
|
return key;
|
2004-12-02 19:09:53 +01:00
|
|
|
}
|
2004-12-06 17:19:15 +01:00
|
|
|
|
2019-03-15 04:41:57 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiOpenDeviceInfoA (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiOpenDeviceInfoA(HDEVINFO devinfo, PCSTR instance_id, HWND hwnd_parent, DWORD flags,
|
|
|
|
PSP_DEVINFO_DATA device_data)
|
|
|
|
{
|
|
|
|
WCHAR instance_idW[MAX_DEVICE_ID_LEN];
|
|
|
|
|
|
|
|
TRACE("%p %s %p 0x%08x %p\n", devinfo, debugstr_a(instance_id), hwnd_parent, flags, device_data);
|
|
|
|
|
|
|
|
if (!instance_id || strlen(instance_id) >= MAX_DEVICE_ID_LEN)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, instance_id, -1, instance_idW, ARRAY_SIZE(instance_idW));
|
|
|
|
return SetupDiOpenDeviceInfoW(devinfo, instance_idW, hwnd_parent, flags, device_data);
|
|
|
|
}
|
|
|
|
|
2019-03-15 04:41:14 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiOpenDeviceInfoW (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiOpenDeviceInfoW(HDEVINFO devinfo, PCWSTR instance_id, HWND hwnd_parent, DWORD flags,
|
|
|
|
PSP_DEVINFO_DATA device_data)
|
|
|
|
{
|
|
|
|
struct DeviceInfoSet *set;
|
2019-05-28 05:13:20 +02:00
|
|
|
struct device *device;
|
2019-03-15 04:41:14 +01:00
|
|
|
WCHAR classW[40];
|
|
|
|
GUID guid;
|
|
|
|
HKEY enumKey = NULL;
|
|
|
|
HKEY instanceKey = NULL;
|
|
|
|
DWORD phantom;
|
|
|
|
DWORD size;
|
|
|
|
DWORD error = ERROR_NO_SUCH_DEVINST;
|
|
|
|
|
|
|
|
TRACE("%p %s %p 0x%08x %p\n", devinfo, debugstr_w(instance_id), hwnd_parent, flags, device_data);
|
|
|
|
|
|
|
|
if (!(set = get_device_set(devinfo)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!instance_id)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hwnd_parent)
|
|
|
|
FIXME("hwnd_parent unsupported\n");
|
|
|
|
|
|
|
|
if (flags)
|
|
|
|
FIXME("flags unsupported: 0x%08x\n", flags);
|
|
|
|
|
|
|
|
RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &enumKey, NULL);
|
|
|
|
/* Instance needs to be already existent in registry, if not, report ERROR_NO_SUCH_DEVINST */
|
|
|
|
if (RegOpenKeyExW(enumKey, instance_id, 0, KEY_READ, &instanceKey))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* If it's an unregistered instance, aka phantom instance, report ERROR_NO_SUCH_DEVINST */
|
|
|
|
size = sizeof(phantom);
|
|
|
|
if (!RegQueryValueExW(instanceKey, Phantom, NULL, NULL, (BYTE *)&phantom, &size))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* Check class GUID */
|
|
|
|
size = sizeof(classW);
|
|
|
|
if (RegQueryValueExW(instanceKey, ClassGUID, NULL, NULL, (BYTE *)classW, &size))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
classW[37] = 0;
|
|
|
|
UuidFromStringW(&classW[1], &guid);
|
|
|
|
|
|
|
|
if (!IsEqualGUID(&set->ClassGuid, &GUID_NULL) && !IsEqualGUID(&guid, &set->ClassGuid))
|
|
|
|
{
|
|
|
|
error = ERROR_CLASS_MISMATCH;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2019-05-28 05:13:20 +02:00
|
|
|
if (!(device = create_device(set, &guid, instance_id, FALSE)))
|
2019-03-15 04:41:14 +01:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (!device_data || device_data->cbSize == sizeof(SP_DEVINFO_DATA))
|
|
|
|
{
|
|
|
|
if (device_data)
|
|
|
|
copy_device_data(device_data, device);
|
|
|
|
error = NO_ERROR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
error = ERROR_INVALID_USER_BUFFER;
|
|
|
|
|
|
|
|
done:
|
|
|
|
RegCloseKey(instanceKey);
|
|
|
|
RegCloseKey(enumKey);
|
|
|
|
SetLastError(error);
|
|
|
|
return !error;
|
|
|
|
}
|
|
|
|
|
2004-12-06 17:19:15 +01:00
|
|
|
/***********************************************************************
|
2005-02-03 14:34:50 +01:00
|
|
|
* SetupDiOpenDeviceInterfaceW (SETUPAPI.@)
|
2004-12-06 17:19:15 +01:00
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiOpenDeviceInterfaceW(
|
|
|
|
HDEVINFO DeviceInfoSet,
|
|
|
|
PCWSTR DevicePath,
|
|
|
|
DWORD OpenFlags,
|
|
|
|
PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
|
|
|
|
{
|
2006-10-13 23:32:50 +02:00
|
|
|
FIXME("%p %s %08x %p\n",
|
2004-12-06 17:19:15 +01:00
|
|
|
DeviceInfoSet, debugstr_w(DevicePath), OpenFlags, DeviceInterfaceData);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiOpenDeviceInterfaceA (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiOpenDeviceInterfaceA(
|
|
|
|
HDEVINFO DeviceInfoSet,
|
|
|
|
PCSTR DevicePath,
|
|
|
|
DWORD OpenFlags,
|
|
|
|
PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
|
|
|
|
{
|
2006-10-13 23:32:50 +02:00
|
|
|
FIXME("%p %s %08x %p\n", DeviceInfoSet,
|
2004-12-06 17:19:15 +01:00
|
|
|
debugstr_a(DevicePath), OpenFlags, DeviceInterfaceData);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-01-19 17:57:24 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiSetClassInstallParamsA (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiSetClassInstallParamsA(
|
|
|
|
HDEVINFO DeviceInfoSet,
|
|
|
|
PSP_DEVINFO_DATA DeviceInfoData,
|
|
|
|
PSP_CLASSINSTALL_HEADER ClassInstallParams,
|
|
|
|
DWORD ClassInstallParamsSize)
|
|
|
|
{
|
2006-10-13 23:32:50 +02:00
|
|
|
FIXME("%p %p %x %u\n",DeviceInfoSet, DeviceInfoData,
|
2005-01-19 17:57:24 +01:00
|
|
|
ClassInstallParams->InstallFunction, ClassInstallParamsSize);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-07-14 01:45:25 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiSetClassInstallParamsW (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiSetClassInstallParamsW(
|
|
|
|
HDEVINFO DeviceInfoSet,
|
|
|
|
PSP_DEVINFO_DATA DeviceInfoData,
|
|
|
|
PSP_CLASSINSTALL_HEADER ClassInstallParams,
|
|
|
|
DWORD ClassInstallParamsSize)
|
|
|
|
{
|
|
|
|
FIXME("%p %p %x %u\n",DeviceInfoSet, DeviceInfoData,
|
|
|
|
ClassInstallParams->InstallFunction, ClassInstallParamsSize);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-05-22 18:15:41 +02:00
|
|
|
static BOOL call_coinstallers(WCHAR *list, DI_FUNCTION function, HDEVINFO devinfo, SP_DEVINFO_DATA *device_data)
|
|
|
|
{
|
|
|
|
DWORD (CALLBACK *coinst_proc)(DI_FUNCTION, HDEVINFO, SP_DEVINFO_DATA *, COINSTALLER_CONTEXT_DATA *);
|
|
|
|
COINSTALLER_CONTEXT_DATA coinst_ctx;
|
|
|
|
WCHAR *p, *procnameW;
|
|
|
|
HMODULE module;
|
|
|
|
char *procname;
|
|
|
|
DWORD ret;
|
|
|
|
|
2019-07-04 15:41:03 +02:00
|
|
|
for (p = list; *p; p += lstrlenW(p) + 1)
|
2019-05-22 18:15:41 +02:00
|
|
|
{
|
|
|
|
TRACE("Found co-installer %s.\n", debugstr_w(p));
|
2019-07-04 15:41:03 +02:00
|
|
|
if ((procnameW = wcschr(p, ',')))
|
2019-05-22 18:15:41 +02:00
|
|
|
*procnameW = 0;
|
|
|
|
|
|
|
|
if ((module = LoadLibraryExW(p, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32)))
|
|
|
|
{
|
|
|
|
if (procnameW)
|
|
|
|
{
|
|
|
|
procname = strdupWtoA(procnameW + 1);
|
|
|
|
coinst_proc = (void *)GetProcAddress(module, procname);
|
|
|
|
heap_free(procname);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
coinst_proc = (void *)GetProcAddress(module, "CoDeviceInstall");
|
|
|
|
if (coinst_proc)
|
|
|
|
{
|
|
|
|
memset(&coinst_ctx, 0, sizeof(coinst_ctx));
|
|
|
|
TRACE("Calling co-installer %p.\n", coinst_proc);
|
|
|
|
ret = coinst_proc(function, devinfo, device_data, &coinst_ctx);
|
|
|
|
TRACE("Co-installer %p returned %#x.\n", coinst_proc, ret);
|
|
|
|
if (ret == ERROR_DI_POSTPROCESSING_REQUIRED)
|
|
|
|
FIXME("Co-installer postprocessing not implemented.\n");
|
|
|
|
else if (ret)
|
|
|
|
{
|
|
|
|
ERR("Co-installer returned error %#x.\n", ret);
|
|
|
|
FreeLibrary(module);
|
|
|
|
SetLastError(ret);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FreeLibrary(module);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-01-19 17:57:24 +01:00
|
|
|
/***********************************************************************
|
2019-05-22 18:15:38 +02:00
|
|
|
* SetupDiCallClassInstaller (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiCallClassInstaller(DI_FUNCTION function, HDEVINFO devinfo, SP_DEVINFO_DATA *device_data)
|
|
|
|
{
|
2019-05-22 18:15:41 +02:00
|
|
|
static const WCHAR class_coinst_pathW[] = {'S','y','s','t','e','m',
|
|
|
|
'\\','C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t',
|
|
|
|
'\\','C','o','n','t','r','o','l',
|
|
|
|
'\\','C','o','D','e','v','i','c','e','I','n','s','t','a','l','l','e','r','s',0};
|
2019-05-22 18:15:42 +02:00
|
|
|
static const WCHAR coinstallers32W[] = {'C','o','I','n','s','t','a','l','l','e','r','s','3','2',0};
|
2019-05-22 18:15:39 +02:00
|
|
|
static const WCHAR installer32W[] = {'I','n','s','t','a','l','l','e','r','3','2',0};
|
|
|
|
DWORD (CALLBACK *classinst_proc)(DI_FUNCTION, HDEVINFO, SP_DEVINFO_DATA *);
|
|
|
|
DWORD ret = ERROR_DI_DO_DEFAULT;
|
2019-05-22 18:15:41 +02:00
|
|
|
HKEY class_key, coinst_key;
|
2019-05-22 18:15:39 +02:00
|
|
|
WCHAR *path, *procnameW;
|
|
|
|
struct device *device;
|
2019-05-22 18:15:41 +02:00
|
|
|
WCHAR guidstr[39];
|
|
|
|
BOOL coret = TRUE;
|
2019-05-22 18:15:39 +02:00
|
|
|
HMODULE module;
|
|
|
|
char *procname;
|
|
|
|
DWORD size;
|
|
|
|
|
2019-05-22 18:15:38 +02:00
|
|
|
TRACE("function %#x, devinfo %p, device_data %p.\n", function, devinfo, device_data);
|
|
|
|
|
2019-05-22 18:15:39 +02:00
|
|
|
if (!(device = get_device(devinfo, device_data)))
|
2019-05-22 18:15:38 +02:00
|
|
|
return FALSE;
|
2019-05-22 18:15:39 +02:00
|
|
|
|
2019-05-22 18:15:41 +02:00
|
|
|
if (!RegOpenKeyExW(HKEY_LOCAL_MACHINE, class_coinst_pathW, 0, KEY_READ, &coinst_key))
|
|
|
|
{
|
|
|
|
SETUPDI_GuidToString(&device->class, guidstr);
|
|
|
|
if (!RegGetValueW(coinst_key, NULL, guidstr, RRF_RT_REG_MULTI_SZ, NULL, NULL, &size))
|
|
|
|
{
|
|
|
|
path = heap_alloc(size);
|
|
|
|
if (!RegGetValueW(coinst_key, NULL, guidstr, RRF_RT_REG_MULTI_SZ, NULL, path, &size))
|
|
|
|
coret = call_coinstallers(path, function, devinfo, device_data);
|
|
|
|
heap_free(path);
|
|
|
|
}
|
|
|
|
RegCloseKey(coinst_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!coret)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-05-22 18:15:42 +02:00
|
|
|
if (!open_driver_key(device, KEY_READ, &coinst_key))
|
|
|
|
{
|
|
|
|
if (!RegGetValueW(coinst_key, NULL, coinstallers32W, RRF_RT_REG_MULTI_SZ, NULL, NULL, &size))
|
|
|
|
{
|
|
|
|
path = heap_alloc(size);
|
|
|
|
if (!RegGetValueW(coinst_key, NULL, coinstallers32W, RRF_RT_REG_MULTI_SZ, NULL, path, &size))
|
|
|
|
coret = call_coinstallers(path, function, devinfo, device_data);
|
|
|
|
heap_free(path);
|
|
|
|
}
|
|
|
|
RegCloseKey(coinst_key);
|
|
|
|
}
|
|
|
|
|
2019-05-22 18:15:39 +02:00
|
|
|
if ((class_key = SetupDiOpenClassRegKey(&device->class, KEY_READ)) != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
if (!RegGetValueW(class_key, NULL, installer32W, RRF_RT_REG_SZ, NULL, NULL, &size))
|
|
|
|
{
|
|
|
|
path = heap_alloc(size);
|
|
|
|
if (!RegGetValueW(class_key, NULL, installer32W, RRF_RT_REG_SZ, NULL, path, &size))
|
|
|
|
{
|
|
|
|
TRACE("Found class installer %s.\n", debugstr_w(path));
|
2019-07-04 15:41:03 +02:00
|
|
|
if ((procnameW = wcschr(path, ',')))
|
2019-05-22 18:15:39 +02:00
|
|
|
*procnameW = 0;
|
|
|
|
|
|
|
|
if ((module = LoadLibraryExW(path, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32)))
|
|
|
|
{
|
|
|
|
if (procnameW)
|
|
|
|
{
|
|
|
|
procname = strdupWtoA(procnameW + 1);
|
|
|
|
classinst_proc = (void *)GetProcAddress(module, procname);
|
|
|
|
heap_free(procname);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
classinst_proc = (void *)GetProcAddress(module, "ClassInstall");
|
|
|
|
if (classinst_proc)
|
|
|
|
{
|
|
|
|
TRACE("Calling class installer %p.\n", classinst_proc);
|
|
|
|
ret = classinst_proc(function, devinfo, device_data);
|
|
|
|
TRACE("Class installer %p returned %#x.\n", classinst_proc, ret);
|
|
|
|
}
|
|
|
|
FreeLibrary(module);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
heap_free(path);
|
|
|
|
}
|
|
|
|
RegCloseKey(class_key);
|
2019-05-22 18:15:38 +02:00
|
|
|
}
|
2019-05-22 18:15:39 +02:00
|
|
|
|
|
|
|
if (ret == ERROR_DI_DO_DEFAULT)
|
|
|
|
{
|
|
|
|
switch (function)
|
|
|
|
{
|
|
|
|
case DIF_REGISTERDEVICE:
|
|
|
|
return SetupDiRegisterDeviceInfo(devinfo, device_data, 0, NULL, NULL, NULL);
|
|
|
|
case DIF_REMOVE:
|
|
|
|
return SetupDiRemoveDevice(devinfo, device_data);
|
|
|
|
case DIF_SELECTBESTCOMPATDRV:
|
|
|
|
return SetupDiSelectBestCompatDrv(devinfo, device_data);
|
|
|
|
case DIF_REGISTER_COINSTALLERS:
|
|
|
|
return SetupDiRegisterCoDeviceInstallers(devinfo, device_data);
|
2019-05-23 05:55:53 +02:00
|
|
|
case DIF_INSTALLDEVICEFILES:
|
|
|
|
return SetupDiInstallDriverFiles(devinfo, device_data);
|
2019-05-23 05:55:57 +02:00
|
|
|
case DIF_INSTALLINTERFACES:
|
|
|
|
return SetupDiInstallDeviceInterfaces(devinfo, device_data);
|
2019-05-22 18:15:39 +02:00
|
|
|
case DIF_INSTALLDEVICE:
|
2019-05-25 06:33:52 +02:00
|
|
|
return SetupDiInstallDevice(devinfo, device_data);
|
|
|
|
case DIF_FINISHINSTALL_ACTION:
|
2019-05-22 18:15:39 +02:00
|
|
|
case DIF_PROPERTYCHANGE:
|
|
|
|
case DIF_SELECTDEVICE:
|
|
|
|
case DIF_UNREMOVE:
|
|
|
|
FIXME("Unhandled function %#x.\n", function);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret) SetLastError(ret);
|
|
|
|
return !ret;
|
2005-01-19 17:57:24 +01:00
|
|
|
}
|
|
|
|
|
2012-07-07 15:19:53 +02:00
|
|
|
/***********************************************************************
|
2019-05-16 05:56:06 +02:00
|
|
|
* SetupDiGetDeviceInstallParamsW (SETUPAPI.@)
|
2012-07-07 15:19:53 +02:00
|
|
|
*/
|
2019-05-16 05:56:06 +02:00
|
|
|
BOOL WINAPI SetupDiGetDeviceInstallParamsW(HDEVINFO devinfo,
|
|
|
|
SP_DEVINFO_DATA *device_data, SP_DEVINSTALL_PARAMS_W *params)
|
2012-07-07 15:19:53 +02:00
|
|
|
{
|
2019-05-16 05:56:06 +02:00
|
|
|
struct device *device;
|
|
|
|
|
|
|
|
TRACE("devinfo %p, device_data %p, params %p.\n", devinfo, device_data, params);
|
|
|
|
|
|
|
|
if (params->cbSize != sizeof(SP_DEVINSTALL_PARAMS_W))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_USER_BUFFER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(device = get_device(devinfo, device_data)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*params = device->params;
|
|
|
|
|
|
|
|
return TRUE;
|
2012-07-07 15:19:53 +02:00
|
|
|
}
|
|
|
|
|
2005-01-19 17:57:24 +01:00
|
|
|
/***********************************************************************
|
2019-05-16 05:56:06 +02:00
|
|
|
* SetupDiGetDeviceInstallParamsA (SETUPAPI.@)
|
2005-01-19 17:57:24 +01:00
|
|
|
*/
|
2019-05-16 05:56:06 +02:00
|
|
|
BOOL WINAPI SetupDiGetDeviceInstallParamsA(HDEVINFO devinfo,
|
|
|
|
SP_DEVINFO_DATA *device_data, SP_DEVINSTALL_PARAMS_A *params)
|
2005-01-19 17:57:24 +01:00
|
|
|
{
|
2019-05-16 05:56:06 +02:00
|
|
|
SP_DEVINSTALL_PARAMS_W paramsW;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (params->cbSize != sizeof(SP_DEVINSTALL_PARAMS_A))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_USER_BUFFER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
paramsW.cbSize = sizeof(paramsW);
|
|
|
|
ret = SetupDiGetDeviceInstallParamsW(devinfo, device_data, ¶msW);
|
|
|
|
params->Flags = paramsW.Flags;
|
|
|
|
params->FlagsEx = paramsW.FlagsEx;
|
|
|
|
params->hwndParent = paramsW.hwndParent;
|
|
|
|
params->InstallMsgHandler = paramsW.InstallMsgHandler;
|
|
|
|
params->InstallMsgHandlerContext = paramsW.InstallMsgHandlerContext;
|
|
|
|
params->FileQueue = paramsW.FileQueue;
|
|
|
|
params->ClassInstallReserved = paramsW.ClassInstallReserved;
|
|
|
|
params->Reserved = paramsW.Reserved;
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, paramsW.DriverPath, -1, params->DriverPath, sizeof(params->DriverPath), NULL, NULL);
|
|
|
|
|
|
|
|
return ret;
|
2005-01-19 17:57:24 +01:00
|
|
|
}
|
|
|
|
|
2013-04-18 21:28:24 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiSetDeviceInstallParamsA (SETUPAPI.@)
|
|
|
|
*/
|
2019-05-16 05:56:07 +02:00
|
|
|
BOOL WINAPI SetupDiSetDeviceInstallParamsA(HDEVINFO devinfo,
|
|
|
|
SP_DEVINFO_DATA *device_data, SP_DEVINSTALL_PARAMS_A *params)
|
2013-04-18 21:28:24 +02:00
|
|
|
{
|
2019-05-16 05:56:07 +02:00
|
|
|
SP_DEVINSTALL_PARAMS_W paramsW;
|
2013-04-18 21:28:24 +02:00
|
|
|
|
2019-05-16 05:56:07 +02:00
|
|
|
if (params->cbSize != sizeof(SP_DEVINSTALL_PARAMS_A))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_USER_BUFFER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
paramsW.cbSize = sizeof(paramsW);
|
|
|
|
paramsW.Flags = params->Flags;
|
|
|
|
paramsW.FlagsEx = params->FlagsEx;
|
|
|
|
paramsW.hwndParent = params->hwndParent;
|
|
|
|
paramsW.InstallMsgHandler = params->InstallMsgHandler;
|
|
|
|
paramsW.InstallMsgHandlerContext = params->InstallMsgHandlerContext;
|
|
|
|
paramsW.FileQueue = params->FileQueue;
|
|
|
|
paramsW.ClassInstallReserved = params->ClassInstallReserved;
|
|
|
|
paramsW.Reserved = params->Reserved;
|
2019-05-17 09:40:08 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, params->DriverPath, -1, paramsW.DriverPath, ARRAY_SIZE(paramsW.DriverPath));
|
2019-05-16 05:56:07 +02:00
|
|
|
|
|
|
|
return SetupDiSetDeviceInstallParamsW(devinfo, device_data, ¶msW);
|
2013-04-18 21:28:24 +02:00
|
|
|
}
|
|
|
|
|
2015-12-16 04:32:38 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiSetDeviceInstallParamsW (SETUPAPI.@)
|
|
|
|
*/
|
2019-05-16 05:56:07 +02:00
|
|
|
BOOL WINAPI SetupDiSetDeviceInstallParamsW(HDEVINFO devinfo,
|
|
|
|
SP_DEVINFO_DATA *device_data, SP_DEVINSTALL_PARAMS_W *params)
|
2015-12-16 04:32:38 +01:00
|
|
|
{
|
2019-05-16 05:56:07 +02:00
|
|
|
struct device *device;
|
|
|
|
|
|
|
|
TRACE("devinfo %p, device_data %p, params %p.\n", devinfo, device_data, params);
|
|
|
|
|
|
|
|
if (params->cbSize != sizeof(SP_DEVINSTALL_PARAMS_W))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_USER_BUFFER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(device = get_device(devinfo, device_data)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
device->params = *params;
|
2015-12-16 04:32:38 +01:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-01-30 04:21:18 +01:00
|
|
|
BOOL WINAPI SetupDiSetDevicePropertyW(HDEVINFO devinfo, PSP_DEVINFO_DATA device_data, const DEVPROPKEY *key,
|
|
|
|
DEVPROPTYPE type, const BYTE *buffer, DWORD size, DWORD flags)
|
|
|
|
{
|
|
|
|
static const WCHAR propertiesW[] = {'P', 'r', 'o', 'p', 'e', 'r', 't', 'i', 'e', 's', 0};
|
|
|
|
static const WCHAR formatW[] = {'\\', '%', '0', '4', 'X', 0};
|
|
|
|
struct device *device;
|
|
|
|
HKEY properties_hkey, property_hkey;
|
|
|
|
WCHAR property_hkey_path[44];
|
|
|
|
LSTATUS ls;
|
|
|
|
|
|
|
|
TRACE("%p %p %p %#x %p %d %#x\n", devinfo, device_data, key, type, buffer, size, flags);
|
|
|
|
|
|
|
|
if (!(device = get_device(devinfo, device_data)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!key || !is_valid_property_type(type)
|
|
|
|
|| (buffer && !size && !(type == DEVPROP_TYPE_EMPTY || type == DEVPROP_TYPE_NULL))
|
|
|
|
|| (buffer && size && (type == DEVPROP_TYPE_EMPTY || type == DEVPROP_TYPE_NULL)))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_DATA);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size && !buffer)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_USER_BUFFER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_FLAGS);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ls = RegCreateKeyExW(device->key, propertiesW, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &properties_hkey, NULL);
|
|
|
|
if (ls)
|
|
|
|
{
|
|
|
|
SetLastError(ls);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
SETUPDI_GuidToString(&key->fmtid, property_hkey_path);
|
2019-07-04 15:41:03 +02:00
|
|
|
swprintf(property_hkey_path + 38, ARRAY_SIZE(property_hkey_path) - 38, formatW, key->pid);
|
2019-01-30 04:21:18 +01:00
|
|
|
|
|
|
|
if (type == DEVPROP_TYPE_EMPTY)
|
|
|
|
{
|
|
|
|
ls = RegDeleteKeyW(properties_hkey, property_hkey_path);
|
|
|
|
RegCloseKey(properties_hkey);
|
|
|
|
SetLastError(ls == ERROR_FILE_NOT_FOUND ? ERROR_NOT_FOUND : ls);
|
|
|
|
return !ls;
|
|
|
|
}
|
|
|
|
else if (type == DEVPROP_TYPE_NULL)
|
|
|
|
{
|
|
|
|
if (!(ls = RegOpenKeyW(properties_hkey, property_hkey_path, &property_hkey)))
|
|
|
|
{
|
|
|
|
ls = RegDeleteValueW(property_hkey, NULL);
|
|
|
|
RegCloseKey(property_hkey);
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(properties_hkey);
|
|
|
|
SetLastError(ls == ERROR_FILE_NOT_FOUND ? ERROR_NOT_FOUND : ls);
|
|
|
|
return !ls;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!(ls = RegCreateKeyExW(properties_hkey, property_hkey_path, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL,
|
|
|
|
&property_hkey, NULL)))
|
|
|
|
{
|
|
|
|
ls = RegSetValueExW(property_hkey, NULL, 0, 0xffff0000 | (0xffff & type), buffer, size);
|
|
|
|
RegCloseKey(property_hkey);
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(properties_hkey);
|
|
|
|
SetLastError(ls);
|
|
|
|
return !ls;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-19 17:57:24 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiOpenDevRegKey (SETUPAPI.@)
|
|
|
|
*/
|
2018-11-26 00:31:46 +01:00
|
|
|
HKEY WINAPI SetupDiOpenDevRegKey(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data,
|
|
|
|
DWORD Scope, DWORD HwProfile, DWORD KeyType, REGSAM samDesired)
|
2005-01-19 17:57:24 +01:00
|
|
|
{
|
2018-07-30 03:26:24 +02:00
|
|
|
struct device *device;
|
2007-10-12 17:25:24 +02:00
|
|
|
HKEY key = INVALID_HANDLE_VALUE;
|
2019-02-25 05:08:17 +01:00
|
|
|
LONG l;
|
2007-10-12 17:25:24 +02:00
|
|
|
|
2018-11-26 00:31:46 +01:00
|
|
|
TRACE("devinfo %p, device_data %p, scope %d, profile %d, type %d, access %#x.\n",
|
|
|
|
devinfo, device_data, Scope, HwProfile, KeyType, samDesired);
|
2007-10-12 17:25:24 +02:00
|
|
|
|
2018-11-26 00:31:46 +01:00
|
|
|
if (!(device = get_device(devinfo, device_data)))
|
2007-10-12 17:25:24 +02:00
|
|
|
return INVALID_HANDLE_VALUE;
|
2018-11-26 00:31:46 +01:00
|
|
|
|
2007-10-12 17:25:24 +02:00
|
|
|
if (Scope != DICS_FLAG_GLOBAL && Scope != DICS_FLAG_CONFIGSPECIFIC)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_FLAGS);
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
if (KeyType != DIREG_DEV && KeyType != DIREG_DRV)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_FLAGS);
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
2018-11-26 00:31:46 +01:00
|
|
|
|
2018-07-30 03:26:24 +02:00
|
|
|
if (device->phantom)
|
2007-10-12 17:25:24 +02:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_DEVINFO_NOT_REGISTERED);
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
if (Scope != DICS_FLAG_GLOBAL)
|
|
|
|
FIXME("unimplemented for scope %d\n", Scope);
|
|
|
|
switch (KeyType)
|
|
|
|
{
|
|
|
|
case DIREG_DEV:
|
2019-02-25 05:08:18 +01:00
|
|
|
l = RegOpenKeyExW(device->key, DeviceParameters, 0, samDesired, &key);
|
2007-10-12 17:25:24 +02:00
|
|
|
break;
|
|
|
|
case DIREG_DRV:
|
2019-02-25 05:08:18 +01:00
|
|
|
l = open_driver_key(device, samDesired, &key);
|
2007-10-12 17:25:24 +02:00
|
|
|
break;
|
|
|
|
default:
|
2019-02-25 05:08:18 +01:00
|
|
|
FIXME("Unhandled type %#x.\n", KeyType);
|
|
|
|
l = ERROR_CALL_NOT_IMPLEMENTED;
|
2007-10-12 17:25:24 +02:00
|
|
|
}
|
2019-02-25 05:08:18 +01:00
|
|
|
SetLastError(l == ERROR_FILE_NOT_FOUND ? ERROR_KEY_DOES_NOT_EXIST : l);
|
|
|
|
return l ? INVALID_HANDLE_VALUE : key;
|
2005-01-19 17:57:24 +01:00
|
|
|
}
|
2007-10-12 17:26:31 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
2009-12-17 00:01:47 +01:00
|
|
|
* SetupDiDeleteDevRegKey (SETUPAPI.@)
|
2007-10-12 17:26:31 +02:00
|
|
|
*/
|
2018-11-26 00:31:46 +01:00
|
|
|
BOOL WINAPI SetupDiDeleteDevRegKey(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data,
|
|
|
|
DWORD Scope, DWORD HwProfile, DWORD KeyType)
|
2007-10-12 17:26:31 +02:00
|
|
|
{
|
2018-07-30 03:26:24 +02:00
|
|
|
struct device *device;
|
2019-02-25 05:08:17 +01:00
|
|
|
LONG l;
|
2007-10-12 17:26:31 +02:00
|
|
|
|
2018-11-26 00:31:46 +01:00
|
|
|
TRACE("devinfo %p, device_data %p, scope %d, profile %d, type %d.\n",
|
|
|
|
devinfo, device_data, Scope, HwProfile, KeyType);
|
2007-10-12 17:26:31 +02:00
|
|
|
|
2018-11-26 00:31:46 +01:00
|
|
|
if (!(device = get_device(devinfo, device_data)))
|
2007-10-12 17:26:31 +02:00
|
|
|
return FALSE;
|
2018-11-26 00:31:46 +01:00
|
|
|
|
2007-10-12 17:26:31 +02:00
|
|
|
if (Scope != DICS_FLAG_GLOBAL && Scope != DICS_FLAG_CONFIGSPECIFIC)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_FLAGS);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-01-12 17:52:20 +01:00
|
|
|
if (KeyType != DIREG_DEV && KeyType != DIREG_DRV && KeyType != DIREG_BOTH)
|
2007-10-12 17:26:31 +02:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_FLAGS);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-11-26 00:31:46 +01:00
|
|
|
|
2018-07-30 03:26:24 +02:00
|
|
|
if (device->phantom)
|
2007-10-12 17:26:31 +02:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_DEVINFO_NOT_REGISTERED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (Scope != DICS_FLAG_GLOBAL)
|
|
|
|
FIXME("unimplemented for scope %d\n", Scope);
|
|
|
|
switch (KeyType)
|
|
|
|
{
|
|
|
|
case DIREG_DRV:
|
2019-02-25 05:08:19 +01:00
|
|
|
l = delete_driver_key(device);
|
2007-10-12 17:26:31 +02:00
|
|
|
break;
|
|
|
|
case DIREG_BOTH:
|
2019-02-25 05:08:19 +01:00
|
|
|
if ((l = delete_driver_key(device)))
|
2019-02-25 05:08:17 +01:00
|
|
|
break;
|
|
|
|
/* fall through */
|
|
|
|
case DIREG_DEV:
|
|
|
|
l = RegDeleteKeyW(device->key, DeviceParameters);
|
2007-10-12 17:26:31 +02:00
|
|
|
break;
|
|
|
|
default:
|
2019-02-25 05:08:19 +01:00
|
|
|
FIXME("Unhandled type %#x.\n", KeyType);
|
|
|
|
l = ERROR_CALL_NOT_IMPLEMENTED;
|
2007-10-12 17:26:31 +02:00
|
|
|
}
|
2019-02-25 05:08:19 +01:00
|
|
|
SetLastError(l);
|
|
|
|
return !l;
|
2007-10-12 17:26:31 +02:00
|
|
|
}
|
2008-03-01 02:46:58 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CM_Get_Device_IDA (SETUPAPI.@)
|
|
|
|
*/
|
2018-07-30 03:26:22 +02:00
|
|
|
CONFIGRET WINAPI CM_Get_Device_IDA(DEVINST devnode, char *buffer, ULONG len, ULONG flags)
|
2008-03-01 02:46:58 +01:00
|
|
|
{
|
2018-07-30 03:26:24 +02:00
|
|
|
struct device *device = get_devnode_device(devnode);
|
2008-03-01 02:46:58 +01:00
|
|
|
|
2018-07-30 03:26:22 +02:00
|
|
|
TRACE("%u, %p, %u, %#x\n", devnode, buffer, len, flags);
|
2008-03-01 02:46:58 +01:00
|
|
|
|
2018-07-30 03:26:22 +02:00
|
|
|
if (!device)
|
2008-03-01 02:46:58 +01:00
|
|
|
return CR_NO_SUCH_DEVINST;
|
|
|
|
|
2018-07-30 03:26:22 +02:00
|
|
|
WideCharToMultiByte(CP_ACP, 0, device->instanceId, -1, buffer, len, 0, 0);
|
|
|
|
TRACE("Returning %s\n", debugstr_a(buffer));
|
2008-03-01 02:46:58 +01:00
|
|
|
return CR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CM_Get_Device_IDW (SETUPAPI.@)
|
|
|
|
*/
|
2018-07-30 03:26:22 +02:00
|
|
|
CONFIGRET WINAPI CM_Get_Device_IDW(DEVINST devnode, WCHAR *buffer, ULONG len, ULONG flags)
|
2008-03-01 02:46:58 +01:00
|
|
|
{
|
2018-07-30 03:26:24 +02:00
|
|
|
struct device *device = get_devnode_device(devnode);
|
2008-03-01 02:46:58 +01:00
|
|
|
|
2018-07-30 03:26:22 +02:00
|
|
|
TRACE("%u, %p, %u, %#x\n", devnode, buffer, len, flags);
|
2008-03-01 02:46:58 +01:00
|
|
|
|
2018-07-30 03:26:22 +02:00
|
|
|
if (!device)
|
2008-03-01 02:46:58 +01:00
|
|
|
return CR_NO_SUCH_DEVINST;
|
|
|
|
|
2018-07-30 03:26:22 +02:00
|
|
|
lstrcpynW(buffer, device->instanceId, len);
|
|
|
|
TRACE("Returning %s\n", debugstr_w(buffer));
|
2008-03-01 02:46:58 +01:00
|
|
|
return CR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CM_Get_Device_ID_Size (SETUPAPI.@)
|
|
|
|
*/
|
2018-07-30 03:26:22 +02:00
|
|
|
CONFIGRET WINAPI CM_Get_Device_ID_Size(ULONG *len, DEVINST devnode, ULONG flags)
|
2008-03-01 02:46:58 +01:00
|
|
|
{
|
2018-07-30 03:26:24 +02:00
|
|
|
struct device *device = get_devnode_device(devnode);
|
2008-03-01 02:46:58 +01:00
|
|
|
|
2018-07-30 03:26:22 +02:00
|
|
|
TRACE("%p, %u, %#x\n", len, devnode, flags);
|
2008-03-01 02:46:58 +01:00
|
|
|
|
2018-07-30 03:26:22 +02:00
|
|
|
if (!device)
|
2008-03-01 02:46:58 +01:00
|
|
|
return CR_NO_SUCH_DEVINST;
|
|
|
|
|
2018-07-30 03:26:22 +02:00
|
|
|
*len = lstrlenW(device->instanceId);
|
2008-03-01 02:46:58 +01:00
|
|
|
return CR_SUCCESS;
|
|
|
|
}
|
2010-10-04 18:16:25 +02:00
|
|
|
|
2010-10-04 18:16:34 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiGetINFClassA (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiGetINFClassA(PCSTR inf, LPGUID class_guid, PSTR class_name,
|
|
|
|
DWORD size, PDWORD required_size)
|
|
|
|
{
|
|
|
|
BOOL retval;
|
|
|
|
DWORD required_sizeA, required_sizeW;
|
|
|
|
PWSTR class_nameW = NULL;
|
|
|
|
UNICODE_STRING infW;
|
|
|
|
|
2011-01-15 09:28:37 +01:00
|
|
|
if (inf)
|
|
|
|
{
|
|
|
|
if (!RtlCreateUnicodeStringFromAsciiz(&infW, inf))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
infW.Buffer = NULL;
|
|
|
|
|
2010-10-04 18:16:34 +02:00
|
|
|
if (class_name && size)
|
2011-01-15 09:28:37 +01:00
|
|
|
{
|
|
|
|
if (!(class_nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR))))
|
|
|
|
{
|
|
|
|
RtlFreeUnicodeString(&infW);
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2010-10-04 18:16:34 +02:00
|
|
|
|
|
|
|
retval = SetupDiGetINFClassW(infW.Buffer, class_guid, class_nameW, size, &required_sizeW);
|
|
|
|
|
|
|
|
if (retval)
|
|
|
|
{
|
|
|
|
required_sizeA = WideCharToMultiByte( CP_ACP, 0, class_nameW, required_sizeW,
|
|
|
|
class_name, size, NULL, NULL);
|
|
|
|
|
|
|
|
if(required_size) *required_size = required_sizeA;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if(required_size) *required_size = required_sizeW;
|
|
|
|
|
2011-01-15 09:28:37 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, class_nameW);
|
|
|
|
RtlFreeUnicodeString(&infW);
|
2010-10-04 18:16:34 +02:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-10-04 18:16:25 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiGetINFClassW (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiGetINFClassW(PCWSTR inf, LPGUID class_guid, PWSTR class_name,
|
|
|
|
DWORD size, PDWORD required_size)
|
|
|
|
{
|
|
|
|
BOOL have_guid, have_name;
|
|
|
|
DWORD dret;
|
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
|
|
|
if (!inf)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (INVALID_FILE_ATTRIBUTES == GetFileAttributesW(inf))
|
|
|
|
{
|
|
|
|
FIXME("%s not found. Searching via DevicePath not implemented\n", debugstr_w(inf));
|
|
|
|
SetLastError(ERROR_FILE_NOT_FOUND);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!class_guid || !class_name || !size)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!GetPrivateProfileStringW(Version, Signature, NULL, buffer, MAX_PATH, inf))
|
|
|
|
return FALSE;
|
|
|
|
|
2013-12-17 21:42:00 +01:00
|
|
|
if (lstrcmpiW(buffer, Chicago) && lstrcmpiW(buffer, WindowsNT))
|
2010-10-04 18:16:25 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
buffer[0] = '\0';
|
|
|
|
have_guid = 0 < GetPrivateProfileStringW(Version, ClassGUID, NULL, buffer, MAX_PATH, inf);
|
|
|
|
if (have_guid)
|
|
|
|
{
|
|
|
|
buffer[lstrlenW(buffer)-1] = 0;
|
|
|
|
if (RPC_S_OK != UuidFromStringW(buffer + 1, class_guid))
|
|
|
|
{
|
|
|
|
FIXME("failed to convert \"%s\" into a guid\n", debugstr_w(buffer));
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer[0] = '\0';
|
|
|
|
dret = GetPrivateProfileStringW(Version, Class, NULL, buffer, MAX_PATH, inf);
|
|
|
|
have_name = 0 < dret;
|
|
|
|
|
|
|
|
if (dret >= MAX_PATH -1) FIXME("buffer might be too small\n");
|
|
|
|
if (have_guid && !have_name) FIXME("class name lookup via guid not implemented\n");
|
|
|
|
|
|
|
|
if (have_name)
|
|
|
|
{
|
|
|
|
if (dret < size) lstrcpyW(class_name, buffer);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
have_name = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (required_size) *required_size = dret + ((dret) ? 1 : 0);
|
|
|
|
|
|
|
|
return (have_guid || have_name);
|
|
|
|
}
|
2016-11-04 07:55:22 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiGetDevicePropertyW (SETUPAPI.@)
|
|
|
|
*/
|
2019-01-30 04:21:38 +01:00
|
|
|
BOOL WINAPI SetupDiGetDevicePropertyW(HDEVINFO devinfo, PSP_DEVINFO_DATA device_data,
|
2016-11-04 07:55:22 +01:00
|
|
|
const DEVPROPKEY *prop_key, DEVPROPTYPE *prop_type, BYTE *prop_buff,
|
|
|
|
DWORD prop_buff_size, DWORD *required_size, DWORD flags)
|
|
|
|
{
|
2019-01-30 04:21:38 +01:00
|
|
|
static const WCHAR formatW[] = {'\\', '%', '0', '4', 'X', 0};
|
|
|
|
WCHAR key_path[55] = {'P', 'r', 'o', 'p', 'e', 'r', 't', 'i', 'e', 's', '\\'};
|
|
|
|
HKEY hkey;
|
|
|
|
DWORD value_type;
|
|
|
|
DWORD value_size = 0;
|
|
|
|
LSTATUS ls;
|
|
|
|
struct device *device;
|
2016-11-04 07:55:22 +01:00
|
|
|
|
2019-01-30 04:21:38 +01:00
|
|
|
TRACE("%p, %p, %p, %p, %p, %d, %p, %#x\n", devinfo, device_data, prop_key, prop_type, prop_buff, prop_buff_size,
|
|
|
|
required_size, flags);
|
|
|
|
|
|
|
|
if (!(device = get_device(devinfo, device_data)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!prop_key)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_DATA);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!prop_type || (!prop_buff && prop_buff_size))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_USER_BUFFER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_FLAGS);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
SETUPDI_GuidToString(&prop_key->fmtid, key_path + 11);
|
2019-07-04 15:41:03 +02:00
|
|
|
swprintf(key_path + 49, ARRAY_SIZE(key_path) - 49, formatW, prop_key->pid);
|
2019-01-30 04:21:38 +01:00
|
|
|
|
|
|
|
ls = RegOpenKeyExW(device->key, key_path, 0, KEY_QUERY_VALUE, &hkey);
|
|
|
|
if (!ls)
|
|
|
|
{
|
|
|
|
value_size = prop_buff_size;
|
|
|
|
ls = RegQueryValueExW(hkey, NULL, NULL, &value_type, prop_buff, &value_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (ls)
|
|
|
|
{
|
|
|
|
case NO_ERROR:
|
|
|
|
case ERROR_MORE_DATA:
|
|
|
|
*prop_type = 0xffff & value_type;
|
|
|
|
ls = (ls == ERROR_MORE_DATA || !prop_buff) ? ERROR_INSUFFICIENT_BUFFER : NO_ERROR;
|
|
|
|
break;
|
|
|
|
case ERROR_FILE_NOT_FOUND:
|
|
|
|
*prop_type = DEVPROP_TYPE_EMPTY;
|
|
|
|
value_size = 0;
|
|
|
|
ls = ERROR_NOT_FOUND;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*prop_type = DEVPROP_TYPE_EMPTY;
|
|
|
|
value_size = 0;
|
|
|
|
FIXME("Unhandled error %#x\n", ls);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (required_size)
|
|
|
|
*required_size = value_size;
|
|
|
|
|
|
|
|
SetLastError(ls);
|
|
|
|
return !ls;
|
2016-11-04 07:55:22 +01:00
|
|
|
}
|
2019-03-06 21:25:17 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiInstallDeviceInterfaces (SETUPAPI.@)
|
|
|
|
*/
|
2019-05-23 05:55:57 +02:00
|
|
|
BOOL WINAPI SetupDiInstallDeviceInterfaces(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data)
|
2019-03-06 21:25:17 +01:00
|
|
|
{
|
2019-05-23 05:55:57 +02:00
|
|
|
WCHAR section[LINE_LEN], section_ext[LINE_LEN], iface_section[LINE_LEN], refstr[LINE_LEN], guidstr[39];
|
|
|
|
UINT install_flags = SPINST_ALL;
|
|
|
|
struct device_iface *iface;
|
|
|
|
struct device *device;
|
|
|
|
struct driver *driver;
|
|
|
|
void *callback_ctx;
|
|
|
|
GUID iface_guid;
|
|
|
|
INFCONTEXT ctx;
|
|
|
|
HKEY iface_key;
|
|
|
|
HINF hinf;
|
|
|
|
LONG l;
|
2019-03-06 21:25:17 +01:00
|
|
|
|
2019-05-23 05:55:57 +02:00
|
|
|
TRACE("devinfo %p, device_data %p.\n", devinfo, device_data);
|
|
|
|
|
|
|
|
if (!(device = get_device(devinfo, device_data)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!(driver = device->selected_driver))
|
|
|
|
{
|
|
|
|
ERR("No driver selected for device %p.\n", devinfo);
|
|
|
|
SetLastError(ERROR_NO_DRIVER_SELECTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((hinf = SetupOpenInfFileW(driver->inf_path, NULL, INF_STYLE_WIN4, NULL)) == INVALID_HANDLE_VALUE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
SetupFindFirstLineW(hinf, driver->mfg_key, driver->description, &ctx);
|
|
|
|
SetupGetStringFieldW(&ctx, 1, section, ARRAY_SIZE(section), NULL);
|
|
|
|
SetupDiGetActualSectionToInstallW(hinf, section, section_ext, ARRAY_SIZE(section_ext), NULL, NULL);
|
|
|
|
|
|
|
|
if (device->params.Flags & DI_NOFILECOPY)
|
|
|
|
install_flags &= ~SPINST_FILES;
|
|
|
|
|
|
|
|
callback_ctx = SetupInitDefaultQueueCallback(NULL);
|
|
|
|
|
|
|
|
lstrcatW(section_ext, dotInterfaces);
|
|
|
|
if (SetupFindFirstLineW(hinf, section_ext, AddInterface, &ctx))
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
SetupGetStringFieldW(&ctx, 1, guidstr, ARRAY_SIZE(guidstr), NULL);
|
|
|
|
SetupGetStringFieldW(&ctx, 2, refstr, ARRAY_SIZE(refstr), NULL);
|
|
|
|
guidstr[37] = 0;
|
|
|
|
UuidFromStringW(&guidstr[1], &iface_guid);
|
|
|
|
|
|
|
|
if (!(iface = SETUPDI_CreateDeviceInterface(device, &iface_guid, refstr)))
|
|
|
|
{
|
|
|
|
ERR("Failed to create device interface, error %#x.\n", GetLastError());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((l = create_iface_key(iface, KEY_ALL_ACCESS, &iface_key)))
|
|
|
|
{
|
|
|
|
ERR("Failed to create interface key, error %u.\n", l);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetupGetStringFieldW(&ctx, 3, iface_section, ARRAY_SIZE(iface_section), NULL);
|
|
|
|
SetupInstallFromInfSectionW(NULL, hinf, iface_section, install_flags, iface_key,
|
|
|
|
NULL, SP_COPY_NEWER_ONLY, SetupDefaultQueueCallbackW, callback_ctx, NULL, NULL);
|
|
|
|
|
|
|
|
RegCloseKey(iface_key);
|
|
|
|
} while (SetupFindNextMatchLineW(&ctx, AddInterface, &ctx));
|
|
|
|
}
|
|
|
|
|
|
|
|
SetupTermDefaultQueueCallback(callback_ctx);
|
|
|
|
|
|
|
|
SetupCloseInfFile(hinf);
|
|
|
|
return TRUE;
|
2019-03-06 21:25:17 +01:00
|
|
|
}
|
2019-03-06 21:25:19 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiRegisterCoDeviceInstallers (SETUPAPI.@)
|
|
|
|
*/
|
2019-05-22 18:15:37 +02:00
|
|
|
BOOL WINAPI SetupDiRegisterCoDeviceInstallers(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data)
|
2019-03-06 21:25:19 +01:00
|
|
|
{
|
2019-05-22 18:15:37 +02:00
|
|
|
static const WCHAR coinstallersW[] = {'.','C','o','I','n','s','t','a','l','l','e','r','s',0};
|
|
|
|
WCHAR coinst_key[LINE_LEN], coinst_key_ext[LINE_LEN];
|
|
|
|
struct device *device;
|
|
|
|
struct driver *driver;
|
|
|
|
void *callback_ctx;
|
|
|
|
HKEY driver_key;
|
|
|
|
INFCONTEXT ctx;
|
|
|
|
HINF hinf;
|
|
|
|
LONG l;
|
2019-03-06 21:25:19 +01:00
|
|
|
|
2019-05-22 18:15:37 +02:00
|
|
|
TRACE("devinfo %p, device_data %p.\n", devinfo, device_data);
|
|
|
|
|
|
|
|
if (!(device = get_device(devinfo, device_data)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!(driver = device->selected_driver))
|
|
|
|
{
|
|
|
|
ERR("No driver selected for device %p.\n", devinfo);
|
|
|
|
SetLastError(ERROR_NO_DRIVER_SELECTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((hinf = SetupOpenInfFileW(driver->inf_path, NULL, INF_STYLE_WIN4, NULL)) == INVALID_HANDLE_VALUE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
SetupFindFirstLineW(hinf, driver->mfg_key, driver->description, &ctx);
|
|
|
|
SetupGetStringFieldW(&ctx, 1, coinst_key, ARRAY_SIZE(coinst_key), NULL);
|
|
|
|
SetupDiGetActualSectionToInstallW(hinf, coinst_key, coinst_key_ext, ARRAY_SIZE(coinst_key_ext), NULL, NULL);
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcatW(coinst_key_ext, coinstallersW);
|
2019-05-22 18:15:37 +02:00
|
|
|
|
|
|
|
if ((l = create_driver_key(device, &driver_key)))
|
|
|
|
{
|
|
|
|
SetLastError(l);
|
|
|
|
SetupCloseInfFile(hinf);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
callback_ctx = SetupInitDefaultQueueCallback(NULL);
|
|
|
|
SetupInstallFromInfSectionW(NULL, hinf, coinst_key_ext, SPINST_ALL, driver_key, NULL,
|
|
|
|
SP_COPY_NEWER_ONLY, SetupDefaultQueueCallbackW, callback_ctx, NULL, NULL);
|
|
|
|
SetupTermDefaultQueueCallback(callback_ctx);
|
|
|
|
|
|
|
|
RegCloseKey(driver_key);
|
|
|
|
SetupCloseInfFile(hinf);
|
|
|
|
return TRUE;
|
2019-03-06 21:25:19 +01:00
|
|
|
}
|
2019-05-21 06:55:43 +02:00
|
|
|
|
|
|
|
/* Check whether the given hardware or compatible ID matches any of the device's
|
|
|
|
* own hardware or compatible IDs. */
|
|
|
|
static BOOL device_matches_id(const struct device *device, const WCHAR *id_type, const WCHAR *id)
|
|
|
|
{
|
|
|
|
WCHAR *device_ids;
|
|
|
|
const WCHAR *p;
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
if (!RegGetValueW(device->key, NULL, id_type, RRF_RT_REG_MULTI_SZ, NULL, NULL, &size))
|
|
|
|
{
|
|
|
|
device_ids = heap_alloc(size);
|
|
|
|
if (!RegGetValueW(device->key, NULL, id_type, RRF_RT_REG_MULTI_SZ, NULL, device_ids, &size))
|
|
|
|
{
|
2019-07-04 15:41:03 +02:00
|
|
|
for (p = device_ids; *p; p += lstrlenW(p) + 1)
|
2019-05-21 06:55:43 +02:00
|
|
|
{
|
2019-07-04 15:41:03 +02:00
|
|
|
if (!wcsicmp(p, id))
|
2019-05-21 06:55:43 +02:00
|
|
|
{
|
|
|
|
heap_free(device_ids);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
heap_free(device_ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-05-21 06:55:44 +02:00
|
|
|
static BOOL version_is_compatible(const WCHAR *version)
|
|
|
|
{
|
|
|
|
const WCHAR *machine_ext = NtPlatformExtension + 1, *p;
|
2019-07-04 15:41:03 +02:00
|
|
|
size_t len = lstrlenW(version);
|
2019-05-21 06:55:44 +02:00
|
|
|
BOOL wow64;
|
|
|
|
|
|
|
|
/* We are only concerned with architecture. */
|
2019-07-04 15:41:03 +02:00
|
|
|
if ((p = wcschr(version, '.')))
|
2019-05-21 06:55:44 +02:00
|
|
|
len = p - version;
|
|
|
|
|
2019-07-04 15:41:03 +02:00
|
|
|
if (!wcsnicmp(version, NtExtension + 1, len))
|
2019-05-21 06:55:44 +02:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (IsWow64Process(GetCurrentProcess(), &wow64) && wow64)
|
|
|
|
{
|
|
|
|
#ifdef __i386__
|
|
|
|
static const WCHAR wow_ext[] = {'N','T','a','m','d','6','4',0};
|
|
|
|
machine_ext = wow_ext;
|
|
|
|
#elif defined(__arm__)
|
|
|
|
static const WCHAR wow_ext[] = {'N','T','a','r','m','6','4',0};
|
|
|
|
machine_ext = wow_ext;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-07-04 15:41:03 +02:00
|
|
|
return !wcsnicmp(version, machine_ext, len);
|
2019-05-21 06:55:44 +02:00
|
|
|
}
|
|
|
|
|
2019-05-21 06:55:43 +02:00
|
|
|
static void enum_compat_drivers_from_file(struct device *device, const WCHAR *path)
|
|
|
|
{
|
|
|
|
static const WCHAR manufacturerW[] = {'M','a','n','u','f','a','c','t','u','r','e','r',0};
|
2019-05-21 06:55:44 +02:00
|
|
|
WCHAR mfg_name[LINE_LEN], mfg_key[LINE_LEN], mfg_key_ext[LINE_LEN], id[MAX_DEVICE_ID_LEN], version[MAX_DEVICE_ID_LEN];
|
2019-05-21 06:55:43 +02:00
|
|
|
INFCONTEXT ctx;
|
|
|
|
DWORD i, j, k;
|
|
|
|
HINF hinf;
|
|
|
|
|
|
|
|
TRACE("Enumerating drivers from %s.\n", debugstr_w(path));
|
|
|
|
|
|
|
|
if ((hinf = SetupOpenInfFileW(path, NULL, INF_STYLE_WIN4, NULL)) == INVALID_HANDLE_VALUE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; SetupGetLineByIndexW(hinf, manufacturerW, i, &ctx); ++i)
|
|
|
|
{
|
|
|
|
SetupGetStringFieldW(&ctx, 0, mfg_name, ARRAY_SIZE(mfg_name), NULL);
|
|
|
|
if (!SetupGetStringFieldW(&ctx, 1, mfg_key, ARRAY_SIZE(mfg_key), NULL))
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcpyW(mfg_key, mfg_name);
|
2019-05-21 06:55:43 +02:00
|
|
|
|
2019-05-21 06:55:44 +02:00
|
|
|
if (SetupGetFieldCount(&ctx) >= 2)
|
|
|
|
{
|
|
|
|
BOOL compatible = FALSE;
|
|
|
|
for (j = 2; SetupGetStringFieldW(&ctx, j, version, ARRAY_SIZE(version), NULL); ++j)
|
|
|
|
{
|
|
|
|
if (version_is_compatible(version))
|
|
|
|
{
|
|
|
|
compatible = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!compatible)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-05-21 06:55:43 +02:00
|
|
|
if (!SetupDiGetActualSectionToInstallW(hinf, mfg_key, mfg_key_ext, ARRAY_SIZE(mfg_key_ext), NULL, NULL))
|
|
|
|
{
|
|
|
|
WARN("Failed to find section for %s, skipping.\n", debugstr_w(mfg_key));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; SetupGetLineByIndexW(hinf, mfg_key_ext, j, &ctx); ++j)
|
|
|
|
{
|
|
|
|
for (k = 2; SetupGetStringFieldW(&ctx, k, id, ARRAY_SIZE(id), NULL); ++k)
|
|
|
|
{
|
|
|
|
if (device_matches_id(device, HardwareId, id) || device_matches_id(device, CompatibleIDs, id))
|
|
|
|
{
|
|
|
|
unsigned int count = ++device->driver_count;
|
|
|
|
|
|
|
|
device->drivers = heap_realloc(device->drivers, count * sizeof(*device->drivers));
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcpyW(device->drivers[count - 1].inf_path, path);
|
|
|
|
lstrcpyW(device->drivers[count - 1].manufacturer, mfg_name);
|
|
|
|
lstrcpyW(device->drivers[count - 1].mfg_key, mfg_key_ext);
|
2019-05-21 06:55:43 +02:00
|
|
|
SetupGetStringFieldW(&ctx, 0, device->drivers[count - 1].description,
|
|
|
|
ARRAY_SIZE(device->drivers[count - 1].description), NULL);
|
|
|
|
|
|
|
|
TRACE("Found compatible driver: manufacturer %s, desc %s.\n",
|
|
|
|
debugstr_w(mfg_name), debugstr_w(device->drivers[count - 1].description));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SetupCloseInfFile(hinf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiBuildDriverInfoList (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiBuildDriverInfoList(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data, DWORD type)
|
|
|
|
{
|
|
|
|
struct device *device;
|
|
|
|
|
|
|
|
TRACE("devinfo %p, device_data %p, type %#x.\n", devinfo, device_data, type);
|
|
|
|
|
|
|
|
if (type != SPDIT_COMPATDRIVER)
|
|
|
|
{
|
|
|
|
FIXME("Unhandled type %#x.\n", type);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(device = get_device(devinfo, device_data)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (device->params.Flags & DI_ENUMSINGLEINF)
|
|
|
|
{
|
|
|
|
enum_compat_drivers_from_file(device, device->params.DriverPath);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-21 06:55:45 +02:00
|
|
|
static const WCHAR default_path[] = {'C',':','/','w','i','n','d','o','w','s','/','i','n','f',0};
|
|
|
|
static const WCHAR wildcardW[] = {'*',0};
|
|
|
|
WCHAR dir[MAX_PATH], file[MAX_PATH];
|
|
|
|
WIN32_FIND_DATAW find_data;
|
|
|
|
HANDLE find_handle;
|
|
|
|
|
|
|
|
if (device->params.DriverPath[0])
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcpyW(dir, device->params.DriverPath);
|
2019-05-21 06:55:45 +02:00
|
|
|
else
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcpyW(dir, default_path);
|
|
|
|
lstrcatW(dir, backslashW);
|
|
|
|
lstrcatW(dir, wildcardW);
|
2019-05-21 06:55:45 +02:00
|
|
|
|
|
|
|
TRACE("Searching for drivers in %s.\n", debugstr_w(dir));
|
|
|
|
|
|
|
|
if ((find_handle = FindFirstFileW(dir, &find_data)) != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcpyW(file, dir);
|
|
|
|
lstrcpyW(file + lstrlenW(file) - 1, find_data.cFileName);
|
2019-05-21 06:55:45 +02:00
|
|
|
enum_compat_drivers_from_file(device, file);
|
|
|
|
} while (FindNextFileW(find_handle, &find_data));
|
|
|
|
|
|
|
|
FindClose(find_handle);
|
|
|
|
}
|
2019-05-21 06:55:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2019-05-21 06:55:46 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiEnumDriverInfoW (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiEnumDriverInfoW(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data,
|
|
|
|
DWORD type, DWORD index, SP_DRVINFO_DATA_W *driver_data)
|
|
|
|
{
|
|
|
|
static const WCHAR providerW[] = {'P','r','o','v','i','d','e','r',0};
|
|
|
|
struct device *device;
|
|
|
|
INFCONTEXT ctx;
|
|
|
|
HINF hinf;
|
|
|
|
|
|
|
|
TRACE("devinfo %p, device_data %p, type %#x, index %u, driver_data %p.\n",
|
|
|
|
devinfo, device_data, type, index, driver_data);
|
|
|
|
|
|
|
|
if (type != SPDIT_COMPATDRIVER)
|
|
|
|
{
|
|
|
|
FIXME("Unhandled type %#x.\n", type);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(device = get_device(devinfo, device_data)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (index >= device->driver_count)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_NO_MORE_ITEMS);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((hinf = SetupOpenInfFileW(device->drivers[index].inf_path, NULL, INF_STYLE_WIN4, NULL)) == INVALID_HANDLE_VALUE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
driver_data->ProviderName[0] = 0;
|
|
|
|
if (SetupFindFirstLineW(hinf, Version, providerW, &ctx))
|
|
|
|
SetupGetStringFieldW(&ctx, 1, driver_data->ProviderName, ARRAY_SIZE(driver_data->ProviderName), NULL);
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcpyW(driver_data->Description, device->drivers[index].description);
|
|
|
|
lstrcpyW(driver_data->MfgName, device->drivers[index].manufacturer);
|
2019-05-21 06:55:46 +02:00
|
|
|
driver_data->DriverType = SPDIT_COMPATDRIVER;
|
|
|
|
|
|
|
|
SetupCloseInfFile(hinf);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiEnumDriverInfoA (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiEnumDriverInfoA(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data,
|
|
|
|
DWORD type, DWORD index, SP_DRVINFO_DATA_A *driver_data)
|
|
|
|
{
|
|
|
|
SP_DRVINFO_DATA_W driver_dataW;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
driver_dataW.cbSize = sizeof(driver_dataW);
|
|
|
|
ret = SetupDiEnumDriverInfoW(devinfo, device_data, type, index, &driver_dataW);
|
|
|
|
driver_data->DriverType = driver_dataW.DriverType;
|
|
|
|
driver_data->Reserved = driver_dataW.Reserved;
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, driver_dataW.Description, -1, driver_data->Description,
|
|
|
|
sizeof(driver_data->Description), NULL, NULL);
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, driver_dataW.MfgName, -1, driver_data->MfgName,
|
|
|
|
sizeof(driver_data->MfgName), NULL, NULL);
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, driver_dataW.ProviderName, -1, driver_data->ProviderName,
|
|
|
|
sizeof(driver_data->ProviderName), NULL, NULL);
|
|
|
|
return ret;
|
|
|
|
}
|
2019-05-21 06:55:49 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiSelectBestCompatDrv (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiSelectBestCompatDrv(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data)
|
|
|
|
{
|
|
|
|
struct device *device;
|
|
|
|
|
|
|
|
TRACE("devinfo %p, device_data %p.\n", devinfo, device_data);
|
|
|
|
|
|
|
|
if (!(device = get_device(devinfo, device_data)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!device->driver_count)
|
|
|
|
{
|
|
|
|
ERR("No compatible drivers were enumerated for device %s.\n", debugstr_w(device->instanceId));
|
|
|
|
SetLastError(ERROR_NO_COMPAT_DRIVERS);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Semi-stub, selecting the first available driver.\n");
|
|
|
|
|
|
|
|
device->selected_driver = &device->drivers[0];
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2019-05-23 05:55:53 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiInstallDriverFiles (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiInstallDriverFiles(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data)
|
|
|
|
{
|
2019-05-23 05:55:55 +02:00
|
|
|
WCHAR section[LINE_LEN], section_ext[LINE_LEN], iface_section[LINE_LEN];
|
2019-05-23 05:55:53 +02:00
|
|
|
struct device *device;
|
|
|
|
struct driver *driver;
|
|
|
|
void *callback_ctx;
|
|
|
|
INFCONTEXT ctx;
|
|
|
|
HINF hinf;
|
|
|
|
|
|
|
|
TRACE("devinfo %p, device_data %p.\n", devinfo, device_data);
|
|
|
|
|
|
|
|
if (!(device = get_device(devinfo, device_data)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!(driver = device->selected_driver))
|
|
|
|
{
|
|
|
|
ERR("No driver selected for device %p.\n", devinfo);
|
|
|
|
SetLastError(ERROR_NO_DRIVER_SELECTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((hinf = SetupOpenInfFileW(driver->inf_path, NULL, INF_STYLE_WIN4, NULL)) == INVALID_HANDLE_VALUE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
SetupFindFirstLineW(hinf, driver->mfg_key, driver->description, &ctx);
|
|
|
|
SetupGetStringFieldW(&ctx, 1, section, ARRAY_SIZE(section), NULL);
|
|
|
|
SetupDiGetActualSectionToInstallW(hinf, section, section_ext, ARRAY_SIZE(section_ext), NULL, NULL);
|
|
|
|
|
|
|
|
callback_ctx = SetupInitDefaultQueueCallback(NULL);
|
2019-05-23 05:55:55 +02:00
|
|
|
|
2019-05-23 05:55:53 +02:00
|
|
|
SetupInstallFromInfSectionW(NULL, hinf, section_ext, SPINST_FILES, NULL, NULL,
|
|
|
|
SP_COPY_NEWER_ONLY, SetupDefaultQueueCallbackW, callback_ctx, NULL, NULL);
|
2019-05-23 05:55:55 +02:00
|
|
|
|
|
|
|
lstrcatW(section_ext, dotInterfaces);
|
|
|
|
if (SetupFindFirstLineW(hinf, section_ext, AddInterface, &ctx))
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
SetupGetStringFieldW(&ctx, 3, iface_section, ARRAY_SIZE(iface_section), NULL);
|
|
|
|
SetupInstallFromInfSectionW(NULL, hinf, iface_section, SPINST_FILES, NULL, NULL,
|
|
|
|
SP_COPY_NEWER_ONLY, SetupDefaultQueueCallbackW, callback_ctx, NULL, NULL);
|
|
|
|
} while (SetupFindNextMatchLineW(&ctx, AddInterface, &ctx));
|
|
|
|
}
|
|
|
|
|
2019-05-23 05:55:53 +02:00
|
|
|
SetupTermDefaultQueueCallback(callback_ctx);
|
|
|
|
|
|
|
|
SetupCloseInfFile(hinf);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2019-05-25 06:33:52 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupDiInstallDevice (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupDiInstallDevice(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data)
|
|
|
|
{
|
2019-05-25 06:33:53 +02:00
|
|
|
static const WCHAR infpathW[] = {'I','n','f','P','a','t','h',0};
|
|
|
|
static const WCHAR infsectionW[] = {'I','n','f','S','e','c','t','i','o','n',0};
|
|
|
|
static const WCHAR infsectionextW[] = {'I','n','f','S','e','c','t','i','o','n','E','x','t',0};
|
2019-05-25 06:33:54 +02:00
|
|
|
static const WCHAR dothwW[] = {'.','H','W',0};
|
2019-05-25 06:33:55 +02:00
|
|
|
static const WCHAR dotservicesW[] = {'.','S','e','r','v','i','c','e','s',0};
|
|
|
|
static const WCHAR addserviceW[] = {'A','d','d','S','e','r','v','i','c','e',0};
|
2019-06-27 05:32:26 +02:00
|
|
|
static const WCHAR rootW[] = {'r','o','o','t','\\',0};
|
2019-05-25 06:33:54 +02:00
|
|
|
WCHAR section[LINE_LEN], section_ext[LINE_LEN], subsection[LINE_LEN], inf_path[MAX_PATH], *extptr, *filepart;
|
2019-06-27 05:32:26 +02:00
|
|
|
WCHAR svc_name[LINE_LEN];
|
2019-05-25 06:33:52 +02:00
|
|
|
UINT install_flags = SPINST_ALL;
|
2019-05-25 06:33:54 +02:00
|
|
|
HKEY driver_key, device_key;
|
2019-06-27 05:32:26 +02:00
|
|
|
SC_HANDLE manager, service;
|
2019-05-25 06:33:52 +02:00
|
|
|
struct device *device;
|
|
|
|
struct driver *driver;
|
|
|
|
void *callback_ctx;
|
|
|
|
INFCONTEXT ctx;
|
|
|
|
HINF hinf;
|
|
|
|
LONG l;
|
|
|
|
|
|
|
|
TRACE("devinfo %p, device_data %p.\n", devinfo, device_data);
|
|
|
|
|
|
|
|
if (!(device = get_device(devinfo, device_data)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!(driver = device->selected_driver))
|
|
|
|
{
|
|
|
|
ERR("No driver selected for device %p.\n", devinfo);
|
|
|
|
SetLastError(ERROR_NO_DRIVER_SELECTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((hinf = SetupOpenInfFileW(driver->inf_path, NULL, INF_STYLE_WIN4, NULL)) == INVALID_HANDLE_VALUE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
SetupFindFirstLineW(hinf, driver->mfg_key, driver->description, &ctx);
|
|
|
|
SetupGetStringFieldW(&ctx, 1, section, ARRAY_SIZE(section), NULL);
|
2019-05-25 06:33:53 +02:00
|
|
|
SetupDiGetActualSectionToInstallW(hinf, section, section_ext, ARRAY_SIZE(section_ext), NULL, &extptr);
|
2019-05-25 06:33:52 +02:00
|
|
|
|
|
|
|
if ((l = create_driver_key(device, &driver_key)))
|
|
|
|
{
|
|
|
|
SetLastError(l);
|
|
|
|
SetupCloseInfFile(hinf);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-05-25 06:33:54 +02:00
|
|
|
if ((l = RegCreateKeyExW(device->key, DeviceParameters, 0, NULL, 0,
|
|
|
|
KEY_READ | KEY_WRITE, NULL, &device_key, NULL)))
|
|
|
|
{
|
|
|
|
SetLastError(l);
|
|
|
|
RegCloseKey(driver_key);
|
|
|
|
SetupCloseInfFile(hinf);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-05-25 06:33:52 +02:00
|
|
|
if (device->params.Flags & DI_NOFILECOPY)
|
|
|
|
install_flags &= ~SPINST_FILES;
|
|
|
|
|
|
|
|
callback_ctx = SetupInitDefaultQueueCallback(NULL);
|
|
|
|
|
|
|
|
SetupInstallFromInfSectionW(NULL, hinf, section_ext, install_flags, driver_key, NULL,
|
|
|
|
SP_COPY_NEWER_ONLY, SetupDefaultQueueCallbackW, callback_ctx, NULL, NULL);
|
|
|
|
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcpyW(subsection, section_ext);
|
|
|
|
lstrcatW(subsection, dothwW);
|
2019-05-25 06:33:54 +02:00
|
|
|
|
|
|
|
SetupInstallFromInfSectionW(NULL, hinf, subsection, install_flags, device_key, NULL,
|
|
|
|
SP_COPY_NEWER_ONLY, SetupDefaultQueueCallbackW, callback_ctx, NULL, NULL);
|
|
|
|
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcpyW(subsection, section_ext);
|
|
|
|
lstrcatW(subsection, dotservicesW);
|
2019-05-25 06:33:55 +02:00
|
|
|
SetupInstallServicesFromInfSectionW(hinf, subsection, 0);
|
|
|
|
|
2019-06-27 05:32:26 +02:00
|
|
|
svc_name[0] = 0;
|
2019-05-25 06:33:55 +02:00
|
|
|
if (SetupFindFirstLineW(hinf, subsection, addserviceW, &ctx))
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
INT flags;
|
|
|
|
|
|
|
|
if (SetupGetIntField(&ctx, 2, &flags) && (flags & SPSVCINST_ASSOCSERVICE))
|
|
|
|
{
|
|
|
|
if (SetupGetStringFieldW(&ctx, 1, svc_name, ARRAY_SIZE(svc_name), NULL) && svc_name[0])
|
2019-07-04 15:41:03 +02:00
|
|
|
RegSetValueExW(device->key, Service, 0, REG_SZ, (BYTE *)svc_name, lstrlenW(svc_name) * sizeof(WCHAR));
|
2019-05-25 06:33:55 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (SetupFindNextMatchLineW(&ctx, addserviceW, &ctx));
|
|
|
|
}
|
|
|
|
|
2019-05-25 06:33:52 +02:00
|
|
|
SetupTermDefaultQueueCallback(callback_ctx);
|
|
|
|
SetupCloseInfFile(hinf);
|
2019-05-25 06:33:53 +02:00
|
|
|
|
|
|
|
SetupCopyOEMInfW(driver->inf_path, NULL, SPOST_NONE, 0, inf_path, ARRAY_SIZE(inf_path), NULL, &filepart);
|
|
|
|
TRACE("Copied INF file %s to %s.\n", debugstr_w(driver->inf_path), debugstr_w(inf_path));
|
|
|
|
|
2019-07-04 15:41:03 +02:00
|
|
|
RegSetValueExW(driver_key, infpathW, 0, REG_SZ, (BYTE *)filepart, lstrlenW(filepart) * sizeof(WCHAR));
|
|
|
|
RegSetValueExW(driver_key, infsectionW, 0, REG_SZ, (BYTE *)section, lstrlenW(section) * sizeof(WCHAR));
|
2019-05-25 06:33:53 +02:00
|
|
|
if (extptr)
|
2019-07-04 15:41:03 +02:00
|
|
|
RegSetValueExW(driver_key, infsectionextW, 0, REG_SZ, (BYTE *)extptr, lstrlenW(extptr) * sizeof(WCHAR));
|
2019-05-25 06:33:53 +02:00
|
|
|
|
2019-05-25 06:33:54 +02:00
|
|
|
RegCloseKey(device_key);
|
2019-05-25 06:33:52 +02:00
|
|
|
RegCloseKey(driver_key);
|
2019-06-27 05:32:26 +02:00
|
|
|
|
2019-07-04 15:41:03 +02:00
|
|
|
if (!wcsnicmp(device->instanceId, rootW, lstrlenW(rootW)) && svc_name[0]
|
2019-06-27 05:32:26 +02:00
|
|
|
&& (manager = OpenSCManagerW(NULL, NULL, SC_MANAGER_CONNECT)))
|
|
|
|
{
|
|
|
|
if ((service = OpenServiceW(manager, svc_name, SERVICE_START)))
|
|
|
|
{
|
|
|
|
if (!StartServiceW(service, 0, NULL) && GetLastError() != ERROR_SERVICE_ALREADY_RUNNING)
|
|
|
|
{
|
|
|
|
ERR("Failed to start service %s for device %s, error %u.\n",
|
|
|
|
debugstr_w(svc_name), debugstr_w(device->instanceId), GetLastError());
|
|
|
|
}
|
|
|
|
CloseServiceHandle(service);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ERR("Failed to open service %s for device %s.\n", debugstr_w(svc_name), debugstr_w(device->instanceId));
|
|
|
|
CloseServiceHandle(manager);
|
|
|
|
}
|
|
|
|
|
2019-05-25 06:33:52 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|