Win32 API 日本語リファレンス
ホームSystem.Power › PowerSetActiveScheme

PowerSetActiveScheme

関数
指定した電源プランをアクティブに設定する。
DLLPOWRPROF.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// POWRPROF.dll
#include <windows.h>

WIN32_ERROR PowerSetActiveScheme(
    HKEY UserRootPowerKey,   // optional
    const GUID* SchemeGuid   // optional
);

パラメーター

名前方向
UserRootPowerKeyHKEYinoptional
SchemeGuidGUID*inoptional

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

// POWRPROF.dll
#include <windows.h>

WIN32_ERROR PowerSetActiveScheme(
    HKEY UserRootPowerKey,   // optional
    const GUID* SchemeGuid   // optional
);
[DllImport("POWRPROF.dll", ExactSpelling = true)]
static extern uint PowerSetActiveScheme(
    IntPtr UserRootPowerKey,   // HKEY optional
    IntPtr SchemeGuid   // GUID* optional
);
<DllImport("POWRPROF.dll", ExactSpelling:=True)>
Public Shared Function PowerSetActiveScheme(
    UserRootPowerKey As IntPtr,   ' HKEY optional
    SchemeGuid As IntPtr   ' GUID* optional
) As UInteger
End Function
' UserRootPowerKey : HKEY optional
' SchemeGuid : GUID* optional
Declare PtrSafe Function PowerSetActiveScheme Lib "powrprof" ( _
    ByVal UserRootPowerKey As LongPtr, _
    ByVal SchemeGuid As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

PowerSetActiveScheme = ctypes.windll.powrprof.PowerSetActiveScheme
PowerSetActiveScheme.restype = wintypes.DWORD
PowerSetActiveScheme.argtypes = [
    wintypes.HANDLE,  # UserRootPowerKey : HKEY optional
    ctypes.c_void_p,  # SchemeGuid : GUID* optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('POWRPROF.dll')
PowerSetActiveScheme = Fiddle::Function.new(
  lib['PowerSetActiveScheme'],
  [
    Fiddle::TYPE_VOIDP,  # UserRootPowerKey : HKEY optional
    Fiddle::TYPE_VOIDP,  # SchemeGuid : GUID* optional
  ],
  -Fiddle::TYPE_INT)
#[link(name = "powrprof")]
extern "system" {
    fn PowerSetActiveScheme(
        UserRootPowerKey: *mut core::ffi::c_void,  // HKEY optional
        SchemeGuid: *const GUID  // GUID* optional
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("POWRPROF.dll")]
public static extern uint PowerSetActiveScheme(IntPtr UserRootPowerKey, IntPtr SchemeGuid);
"@
$api = Add-Type -MemberDefinition $sig -Name 'POWRPROF_PowerSetActiveScheme' -Namespace Win32 -PassThru
# $api::PowerSetActiveScheme(UserRootPowerKey, SchemeGuid)
#uselib "POWRPROF.dll"
#func global PowerSetActiveScheme "PowerSetActiveScheme" sptr, sptr
; PowerSetActiveScheme UserRootPowerKey, varptr(SchemeGuid)   ; 戻り値は stat
; UserRootPowerKey : HKEY optional -> "sptr"
; SchemeGuid : GUID* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "POWRPROF.dll"
#cfunc global PowerSetActiveScheme "PowerSetActiveScheme" sptr, var
; res = PowerSetActiveScheme(UserRootPowerKey, SchemeGuid)
; UserRootPowerKey : HKEY optional -> "sptr"
; SchemeGuid : GUID* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; WIN32_ERROR PowerSetActiveScheme(HKEY UserRootPowerKey, GUID* SchemeGuid)
#uselib "POWRPROF.dll"
#cfunc global PowerSetActiveScheme "PowerSetActiveScheme" intptr, var
; res = PowerSetActiveScheme(UserRootPowerKey, SchemeGuid)
; UserRootPowerKey : HKEY optional -> "intptr"
; SchemeGuid : GUID* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	powrprof = windows.NewLazySystemDLL("POWRPROF.dll")
	procPowerSetActiveScheme = powrprof.NewProc("PowerSetActiveScheme")
)

// UserRootPowerKey (HKEY optional), SchemeGuid (GUID* optional)
r1, _, err := procPowerSetActiveScheme.Call(
	uintptr(UserRootPowerKey),
	uintptr(SchemeGuid),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function PowerSetActiveScheme(
  UserRootPowerKey: THandle;   // HKEY optional
  SchemeGuid: PGUID   // GUID* optional
): DWORD; stdcall;
  external 'POWRPROF.dll' name 'PowerSetActiveScheme';
result := DllCall("POWRPROF\PowerSetActiveScheme"
    , "Ptr", UserRootPowerKey   ; HKEY optional
    , "Ptr", SchemeGuid   ; GUID* optional
    , "UInt")   ; return: WIN32_ERROR
●PowerSetActiveScheme(UserRootPowerKey, SchemeGuid) = DLL("POWRPROF.dll", "dword PowerSetActiveScheme(void*, void*)")
# 呼び出し: PowerSetActiveScheme(UserRootPowerKey, SchemeGuid)
# UserRootPowerKey : HKEY optional -> "void*"
# SchemeGuid : GUID* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。