Export (0) Print
Expand All
Expand Minimize

SetupDiCreateDeviceInfo function

The SetupDiCreateDeviceInfo function creates a new device information element and adds it as a new member to the specified device information set.

Syntax


BOOL SetupDiCreateDeviceInfo(
  _In_       HDEVINFO         DeviceInfoSet,
  _In_       PCTSTR           DeviceName,
  _In_       const GUID             *ClassGuid,
  _In_opt_   PCTSTR           DeviceDescription,
  _In_opt_   HWND             hwndParent,
  _In_       DWORD            CreationFlags,
  _Out_opt_  PSP_DEVINFO_DATA DeviceInfoData
);

Parameters

DeviceInfoSet [in]

A handle to the device information set for the local computer.

DeviceName [in]

A pointer to a NULL-terminated string that supplies either a full device instance ID (for example, "Root\*PNP0500\0000") or a root-enumerated device ID without the enumerator prefix and instance identifier suffix (for example, "*PNP0500"). The root-enumerated device identifier can be used only if the DICD_GENERATE_ID flag is specified in the CreationFlags parameter.

ClassGuid [in]

A pointer to the device setup class GUID for the device. If the device setup class of the device is not known, set *ClassGuid to a GUID_NULL structure.

DeviceDescription [in, optional]

A pointer to a NULL-terminated string that supplies the text description of the device. This pointer is optional and can be NULL.

hwndParent [in, optional]

A handle to the top-level window to use for any user interface that is related to installing the device. This handle is optional and can be NULL.

CreationFlags [in]

A variable of type DWORD that controls how the device information element is created. Can be a combination of the following values:

DICD_GENERATE_ID

If this flag is specified, DeviceName contains only a Root-enumerated device ID and the system creates a unique device instance key for it. This unique device instance key is generated as:


Enum\Root\DeviceName\InstanceID

Where InstanceID is a four-digit, base-10 number that is unique among all subkeys under Enum\Root\DeviceName.

Call SetupDiGetDeviceInstanceId to discover the ID that was generated for this device information element.

DICD_INHERIT_CLASSDRVS

If this flag is specified, the resulting device information element inherits the class driver list, if any, associated with the device information set. In addition, if there is a selected driver for the device information set, that same driver is selected for the new device information element.

DeviceInfoData [out, optional]

A pointer to a SP_DEVINFO_DATA structure that receives the new device information element. This pointer is optional and can be NULL. If the structure is supplied, the caller must set the cbSize member of this structure to sizeof(SP_DEVINFO_DATA) before calling the function. For more information, see the following Remarks section.

Return value

The function returns TRUE if it is successful. Otherwise, it returns FALSE and the logged error can be retrieved by making a call to GetLastError.

Remarks

The caller of this function must be a member of the Administrators group.

If this device instance is being added to a set that has an associated class, the device class must be the same or the call fails. In this case, a call to GetLastError returns ERROR_CLASS_MISMATCH.

If the specified device instance is the same as an existing device instance key in the registry, the call fails. In this case, a call to GetLastError returns ERROR_DEVINST_ALREADY_EXISTS. This occurs only if the DICD_GENERATE_ID flag is not set.

If the new device information element was successfully created but the caller-supplied DeviceInfoData buffer is invalid, the function returns FALSE. In this case, a call to GetLastError returns ERROR_INVALID_USER_BUFFER. However, the device information element will have been added as a new member of the set already.

The DeviceInfoSet must only contain elements on the local computer.

Requirements

Target platform

Desktop

Version

Available in Microsoft Windows 2000 and later versions of Windows.

Header

Setupapi.h (include Setupapi.h)

Library

Setupapi.lib

See also

SetupDiDeleteDeviceInfo
SetupDiEnumDeviceInfo
SetupDiOpenDeviceInfo
SP_DEVINFO_DATA

 

 

Send comments about this topic to Microsoft

Show:
© 2015 Microsoft