ホーム › System.Power › PowerSetActiveScheme
PowerSetActiveScheme
関数指定した電源プランをアクティブに設定する。
シグネチャ
// POWRPROF.dll
#include <windows.h>
WIN32_ERROR PowerSetActiveScheme(
HKEY UserRootPowerKey, // optional
const GUID* SchemeGuid // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| UserRootPowerKey | HKEY | inoptional | このパラメーターは将来の使用のために予約されており、NULL を設定する必要があります。 |
| SchemeGuid | GUID* | inoptional | 電源スキームの識別子です。 |
戻り値の型: WIN32_ERROR
公式ドキュメント
現在のユーザーのアクティブな電源スキームを設定します。
戻り値
呼び出しが成功した場合は ERROR_SUCCESS(ゼロ)を返し、呼び出しが失敗した場合は非ゼロの値を返します。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 方式にも切替可。#uselib "POWRPROF.dll" #cfunc global PowerSetActiveScheme "PowerSetActiveScheme" sptr, sptr ; res = PowerSetActiveScheme(UserRootPowerKey, varptr(SchemeGuid)) ; UserRootPowerKey : HKEY optional -> "sptr" ; SchemeGuid : GUID* optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; WIN32_ERROR PowerSetActiveScheme(HKEY UserRootPowerKey, GUID* SchemeGuid) #uselib "POWRPROF.dll" #cfunc global PowerSetActiveScheme "PowerSetActiveScheme" intptr, intptr ; res = PowerSetActiveScheme(UserRootPowerKey, varptr(SchemeGuid)) ; UserRootPowerKey : HKEY optional -> "intptr" ; SchemeGuid : GUID* optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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_ERRORfunction 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)。const std = @import("std");
extern "powrprof" fn PowerSetActiveScheme(
UserRootPowerKey: ?*anyopaque, // HKEY optional
SchemeGuid: [*c]GUID // GUID* optional
) callconv(std.os.windows.WINAPI) u32;proc PowerSetActiveScheme(
UserRootPowerKey: pointer, # HKEY optional
SchemeGuid: ptr GUID # GUID* optional
): uint32 {.importc: "PowerSetActiveScheme", stdcall, dynlib: "POWRPROF.dll".}pragma(lib, "powrprof");
extern(Windows)
uint PowerSetActiveScheme(
void* UserRootPowerKey, // HKEY optional
GUID* SchemeGuid // GUID* optional
);ccall((:PowerSetActiveScheme, "POWRPROF.dll"), stdcall, UInt32,
(Ptr{Cvoid}, Ptr{GUID}),
UserRootPowerKey, SchemeGuid)
# UserRootPowerKey : HKEY optional -> Ptr{Cvoid}
# SchemeGuid : GUID* optional -> Ptr{GUID}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t PowerSetActiveScheme(
void* UserRootPowerKey,
void* SchemeGuid);
]]
local powrprof = ffi.load("powrprof")
-- powrprof.PowerSetActiveScheme(UserRootPowerKey, SchemeGuid)
-- UserRootPowerKey : HKEY optional
-- SchemeGuid : GUID* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('POWRPROF.dll');
const PowerSetActiveScheme = lib.func('__stdcall', 'PowerSetActiveScheme', 'uint32_t', ['void *', 'void *']);
// PowerSetActiveScheme(UserRootPowerKey, SchemeGuid)
// UserRootPowerKey : HKEY optional -> 'void *'
// SchemeGuid : GUID* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("POWRPROF.dll", {
PowerSetActiveScheme: { parameters: ["pointer", "pointer"], result: "u32" },
});
// lib.symbols.PowerSetActiveScheme(UserRootPowerKey, SchemeGuid)
// UserRootPowerKey : HKEY optional -> "pointer"
// SchemeGuid : GUID* optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t PowerSetActiveScheme(
void* UserRootPowerKey,
void* SchemeGuid);
C, "POWRPROF.dll");
// $ffi->PowerSetActiveScheme(UserRootPowerKey, SchemeGuid);
// UserRootPowerKey : HKEY optional
// SchemeGuid : GUID* optional
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Powrprof extends StdCallLibrary {
Powrprof INSTANCE = Native.load("powrprof", Powrprof.class);
int PowerSetActiveScheme(
Pointer UserRootPowerKey, // HKEY optional
Pointer SchemeGuid // GUID* optional
);
}@[Link("powrprof")]
lib LibPOWRPROF
fun PowerSetActiveScheme = PowerSetActiveScheme(
UserRootPowerKey : Void*, # HKEY optional
SchemeGuid : GUID* # GUID* optional
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef PowerSetActiveSchemeNative = Uint32 Function(Pointer<Void>, Pointer<Void>);
typedef PowerSetActiveSchemeDart = int Function(Pointer<Void>, Pointer<Void>);
final PowerSetActiveScheme = DynamicLibrary.open('POWRPROF.dll')
.lookupFunction<PowerSetActiveSchemeNative, PowerSetActiveSchemeDart>('PowerSetActiveScheme');
// UserRootPowerKey : HKEY optional -> Pointer<Void>
// SchemeGuid : GUID* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function PowerSetActiveScheme(
UserRootPowerKey: THandle; // HKEY optional
SchemeGuid: PGUID // GUID* optional
): DWORD; stdcall;
external 'POWRPROF.dll' name 'PowerSetActiveScheme';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PowerSetActiveScheme"
c_PowerSetActiveScheme :: Ptr () -> Ptr () -> IO Word32
-- UserRootPowerKey : HKEY optional -> Ptr ()
-- SchemeGuid : GUID* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let powersetactivescheme =
foreign "PowerSetActiveScheme"
((ptr void) @-> (ptr void) @-> returning uint32_t)
(* UserRootPowerKey : HKEY optional -> (ptr void) *)
(* SchemeGuid : GUID* optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library powrprof (t "POWRPROF.dll"))
(cffi:use-foreign-library powrprof)
(cffi:defcfun ("PowerSetActiveScheme" power-set-active-scheme :convention :stdcall) :uint32
(user-root-power-key :pointer) ; HKEY optional
(scheme-guid :pointer)) ; GUID* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $PowerSetActiveScheme = Win32::API::More->new('POWRPROF',
'DWORD PowerSetActiveScheme(HANDLE UserRootPowerKey, LPVOID SchemeGuid)');
# my $ret = $PowerSetActiveScheme->Call($UserRootPowerKey, $SchemeGuid);
# UserRootPowerKey : HKEY optional -> HANDLE
# SchemeGuid : GUID* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型