⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setd.c

📁 此代码为WCE5.0下电源管理的源代码
💻 C
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++


Module Name:

    setd.c

Abstract:

    Power Manager util to set device power state.

Notes:

Revision History:

--*/

#include <windows.h>
#include <msgqueue.h>
#include <pm.h>

extern int	CreateArgvArgc(TCHAR *pProgName, TCHAR *argv[20], TCHAR *pCmdLine);

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR lpCmdLine, int nCmShow)
{
    WCHAR  device[1024] = {0};
    TCHAR  *argv[20];
    int     argc;
    DWORD  dwErr=0;
    DWORD  dwFlags = 0;
    
    CEDEVICE_POWER_STATE dwState=PwrDeviceUnspecified;
    
    UNREFERENCED_PARAMETER(hInst);
    UNREFERENCED_PARAMETER(hPrevInst);
    UNREFERENCED_PARAMETER(nCmShow);
    
    //
    // parse command line
    //
    argc = CreateArgvArgc(TEXT( "PMSETD" ), argv, lpCmdLine);

    switch (argc) {
        case 4:
            if (!swscanf(argv[1], TEXT("%s"), &device))
                dwErr = 1;
            if (!swscanf(argv[2], TEXT("%x"), &dwState))
                dwErr = 1;
            if (!swscanf(argv[3], TEXT("%x"), &dwFlags))
                dwErr = 1;
            break;

        default:
            dwErr=1;
            break;
    }

    if (dwErr) {    
        RETAILMSG(1, (TEXT("PMSETD <Device> <DeviceState> <HexDeviceFlags>\n")));
        RETAILMSG(1, (TEXT("  where <Device> describes the device, e.g. DDI1:\n")));
        RETAILMSG(1, (TEXT("  where <DeviceState> specifies the device power level (Dx), e.g. 4 (D4)\n")));
        RETAILMSG(1, (TEXT("  where <DeviceFlags> specify device flags, in hex, e.g. 1 (POWER_NAME)\n")));
        RETAILMSG(1, (TEXT("Device names may be qualified with the device's class GUID.  This is\n")));
        RETAILMSG(1, (TEXT("required for devices that are not members of the default power-manageable\n")));
        RETAILMSG(1, (TEXT("device class\n")));
        RETAILMSG(1, (TEXT("  Example: PMSETD DDI1: 4 1 (sets DDI1: to device state D4)\n")));        
        RETAILMSG(1, (TEXT("           PMSETD DDI1: -1 1 (clears set value from device DDI1:)\n")));
        RETAILMSG(1, (TEXT("           PMSETD {A32942B7-920C-486b-B0E6-92A702A99B35}\\DDI1: 4 1 (sets DDI1: to D4)\n")));
        RETAILMSG(1, (TEXT("           PMSETD {98C5250D-C29A-4985-AE5F-AFE5367E5006}\\NE20001 4 1 (sets the NDIS miniport NE20001 to D4)\n")));
        RETAILMSG(1, (TEXT("Each device can have at most one SET operation in effect on it.\n")));
        exit(1);
    }
    
    dwErr = SetDevicePower(device, dwFlags, dwState);
    if(dwErr != ERROR_SUCCESS) {
        RETAILMSG(TRUE, (TEXT("PMSETD!SetDevicePower('%s', 0x%x, %d) ERROR:%d\n"), device, dwFlags, dwState, dwErr));
    }

    return 0;
}

// EOF

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -