Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

PowerReadFriendlyName (powrprof)
 
.
Summary
Retreives friendly name for power scheme with given GUID

C# Signature:

     [DllImport("powrprof.dll")]
    public static extern UInt32 PowerReadFriendlyName(
        IntPtr RootPowerKey,
        IntPtr SchemeGuid,
        IntPtr SubGroupOfPowerSettingGuid,
        IntPtr PowerSettingGuid,
        IntPtr Buffer,
        ref UInt32 BufferSize);

    [DllImport("powrprof.dll")]
    public static extern UInt32 PowerReadFriendlyName(
        IntPtr RootPowerKey,
        ref Guid SchemeGuid,
        IntPtr SubGroupOfPowerSettingGuid,
        IntPtr PowerSettingGuid,
        IntPtr Buffer,
        ref UInt32 BufferSize);

VB Signature:

Private Declare Function PowerReadFriendlyName Lib "powrprof.dll" Alias _
    "PowerReadFriendlyName" (RootPowerKey As IntPtr, ByRef SchemeGuid As Guid, _
                SubGroupOfPowerSettingGuid As IntPtr, PowerSettingGuid As IntPtr, _
                Buffer As IntPtr, ByRef BufferSize As UInteger) As UInteger
Declare Function PowerReadFriendlyName Lib "powrprof.dll" (TODO) As TODO

User-Defined Types:

None.

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

None.

Tips & Tricks:

    ''' <summary>
    ''' Retrieves the friendly name for the specified power setting, subgroup, or scheme, in Unicode (Each Char is 2 bytes).
    ''' </summary>
    ''' <param name="RootPowerKey">This parameter is reserved for future use and must be set to NULL</param>
    ''' <param name="SchemeGuid">The identifier of the power scheme.</param>
    ''' <param name="SubGroupOfPowerSettingGuid">The subgroup of power settings. Use NO_SUBGROUP_GUID to refer to the default power scheme.</param>
    ''' <param name="PowerSettingGuid">The identifier of the power setting that is being used.</param>
    ''' <param name="Buffer">A pointer to a buffer that receives the friendly name. If this parameter is NULL, the BufferSize parameter receives the required buffer size</param>
    ''' <param name="BufferSize">Size of the buffer.</param>
    ''' <returns>Returns ERROR_SUCCESS (zero) if the call was successful, and a non-zero value if the call failed.
    ''' If the buffer size passed in the BufferSize parameter is too small, or if the Buffer parameter is NULL,
    ''' ERROR_MORE_DATA will be returned and the DWORD pointed to by the BufferSize parameter will be filled in with
    ''' the required buffer size.</returns>

Please add some!

Sample Code:

    private string GetCurrentPowerSchemeVistaAPI()
    {
        IntPtr ptrActiveGuid = IntPtr.Zero;
        uint res = PowerGetActiveScheme(IntPtr.Zero, ref ptrActiveGuid);
        if (res == 0)
        {
        uint buffSize = 0;
        res = PowerReadFriendlyName(IntPtr.Zero, ptrActiveGuid, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, ref buffSize);
        if (res == 0)
        {
            if (buffSize == 0u) return "";
            IntPtr ptrName = Marshal.AllocHGlobal((int)buffSize);
            res = PowerReadFriendlyName(IntPtr.Zero, ptrActiveGuid, IntPtr.Zero, IntPtr.Zero, ptrName, ref buffSize);
            if (res == 0)
            {
            string ret = Marshal.PtrToStringUni(ptrName);
            Marshal.FreeHGlobal(ptrName);
            return ret;
            }
            Marshal.FreeHGlobal(ptrName);
        }
        }
        throw new Exception("Error reading current power scheme. Native Win32 error code = " + res);
    }

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions