Share via


SetDevicePower (Compact 2013)

3/26/2014

This function sets the device power state for a device.

Syntax

DWORD SetDevicePower(
  PVOID pvDevice,
  DWORD dwDeviceFlags,
  CEDEVICE_POWER_STATE DeviceState
);

Parameters

  • pvDevice
    [in] Specifies the device. Must be a valid LPWSTR device name, for example, "COM1:". This parameter is interpreted according to dwDeviceFlags.
  • dwDeviceFlags
    [in] Set to POWER_NAME to specify the name of the device that is requesting the power request.
  • DeviceState
    [in] Specifies the desired device power state.

Return Value

  • ERROR_ACCESS_DENIED
    Indicates that the caller is not trusted.
  • ERROR_FILE_NOT_FOUND
    Indicates that the device was not found.
  • ERROR_INVALID_PARAMETER
    Indicates an invalid device ID, flag, or dwState value.
  • ERROR_SUCCESS
    Indicates that the device was found and device power state updated correctly.
  • ERROR_WRITE_FAULT
    Indicates that the attempt to update the device power failed.

Remarks

When SetDevicePower is called, qualify the name of your device with an associated class. For example, {8DD679CE-8AB4-43c8-A14A-EA4963FAA715}\DSK1: refers to a power-managed block device called DSK1. If no class qualification is present, the generic power-manageable class {A32942B7-920C-486b-B0E6-92A702A99B35} is assumed.

If a device is requested to go into a power state that the device does not support, Power Manager sets the device power state to the next highest supported power level, where D0 (full power) is the highest level.

For example, if the D4 state is requested and the device does not support D4, then D4 is mapped to D3. If D3 is not supported, then D3 is mapped to D2 and so on. All devices must at least support D0. For more information about the power states, see CEDEVICE_POWER_STATE. The Power Manager code is located in the public\common\oak\drivers\pm directory.

Applications should avoid using this function because it greatly restricts device power self-management. They should use the SetPowerRequirement call instead. Set the device power state to PwrDeviceUnspecified to allow normal power management to resume.

Requirements

Header

pm.h

Library

coredll.lib

See Also

Reference

Power Management Functions