ホーム › System.Power › PowerSetUserConfiguredDCPowerMode
PowerSetUserConfiguredDCPowerMode
関数ユーザー構成のDC電源時の電源モードを設定する。
シグネチャ
// POWRPROF.dll
#include <windows.h>
DWORD PowerSetUserConfiguredDCPowerMode(
const GUID* PowerModeGuid
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| PowerModeGuid | GUID* | in | DC(バッテリー駆動時)に設定する電源モードのGUIDへのポインタを指定する。 |
戻り値の型: DWORD
各言語での呼び出し定義
// POWRPROF.dll
#include <windows.h>
DWORD PowerSetUserConfiguredDCPowerMode(
const GUID* PowerModeGuid
);[DllImport("POWRPROF.dll", ExactSpelling = true)]
static extern uint PowerSetUserConfiguredDCPowerMode(
ref Guid PowerModeGuid // GUID*
);<DllImport("POWRPROF.dll", ExactSpelling:=True)>
Public Shared Function PowerSetUserConfiguredDCPowerMode(
ByRef PowerModeGuid As Guid ' GUID*
) As UInteger
End Function' PowerModeGuid : GUID*
Declare PtrSafe Function PowerSetUserConfiguredDCPowerMode Lib "powrprof" ( _
ByVal PowerModeGuid As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
PowerSetUserConfiguredDCPowerMode = ctypes.windll.powrprof.PowerSetUserConfiguredDCPowerMode
PowerSetUserConfiguredDCPowerMode.restype = wintypes.DWORD
PowerSetUserConfiguredDCPowerMode.argtypes = [
ctypes.c_void_p, # PowerModeGuid : GUID*
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('POWRPROF.dll')
PowerSetUserConfiguredDCPowerMode = Fiddle::Function.new(
lib['PowerSetUserConfiguredDCPowerMode'],
[
Fiddle::TYPE_VOIDP, # PowerModeGuid : GUID*
],
-Fiddle::TYPE_INT)#[link(name = "powrprof")]
extern "system" {
fn PowerSetUserConfiguredDCPowerMode(
PowerModeGuid: *const GUID // GUID*
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("POWRPROF.dll")]
public static extern uint PowerSetUserConfiguredDCPowerMode(ref Guid PowerModeGuid);
"@
$api = Add-Type -MemberDefinition $sig -Name 'POWRPROF_PowerSetUserConfiguredDCPowerMode' -Namespace Win32 -PassThru
# $api::PowerSetUserConfiguredDCPowerMode(PowerModeGuid)#uselib "POWRPROF.dll"
#func global PowerSetUserConfiguredDCPowerMode "PowerSetUserConfiguredDCPowerMode" sptr
; PowerSetUserConfiguredDCPowerMode varptr(PowerModeGuid) ; 戻り値は stat
; PowerModeGuid : GUID* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "POWRPROF.dll" #cfunc global PowerSetUserConfiguredDCPowerMode "PowerSetUserConfiguredDCPowerMode" var ; res = PowerSetUserConfiguredDCPowerMode(PowerModeGuid) ; PowerModeGuid : GUID* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "POWRPROF.dll" #cfunc global PowerSetUserConfiguredDCPowerMode "PowerSetUserConfiguredDCPowerMode" sptr ; res = PowerSetUserConfiguredDCPowerMode(varptr(PowerModeGuid)) ; PowerModeGuid : GUID* -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD PowerSetUserConfiguredDCPowerMode(GUID* PowerModeGuid) #uselib "POWRPROF.dll" #cfunc global PowerSetUserConfiguredDCPowerMode "PowerSetUserConfiguredDCPowerMode" var ; res = PowerSetUserConfiguredDCPowerMode(PowerModeGuid) ; PowerModeGuid : GUID* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD PowerSetUserConfiguredDCPowerMode(GUID* PowerModeGuid) #uselib "POWRPROF.dll" #cfunc global PowerSetUserConfiguredDCPowerMode "PowerSetUserConfiguredDCPowerMode" intptr ; res = PowerSetUserConfiguredDCPowerMode(varptr(PowerModeGuid)) ; PowerModeGuid : GUID* -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
powrprof = windows.NewLazySystemDLL("POWRPROF.dll")
procPowerSetUserConfiguredDCPowerMode = powrprof.NewProc("PowerSetUserConfiguredDCPowerMode")
)
// PowerModeGuid (GUID*)
r1, _, err := procPowerSetUserConfiguredDCPowerMode.Call(
uintptr(PowerModeGuid),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction PowerSetUserConfiguredDCPowerMode(
PowerModeGuid: PGUID // GUID*
): DWORD; stdcall;
external 'POWRPROF.dll' name 'PowerSetUserConfiguredDCPowerMode';result := DllCall("POWRPROF\PowerSetUserConfiguredDCPowerMode"
, "Ptr", PowerModeGuid ; GUID*
, "UInt") ; return: DWORD●PowerSetUserConfiguredDCPowerMode(PowerModeGuid) = DLL("POWRPROF.dll", "dword PowerSetUserConfiguredDCPowerMode(void*)")
# 呼び出し: PowerSetUserConfiguredDCPowerMode(PowerModeGuid)
# PowerModeGuid : GUID* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "powrprof" fn PowerSetUserConfiguredDCPowerMode(
PowerModeGuid: [*c]GUID // GUID*
) callconv(std.os.windows.WINAPI) u32;proc PowerSetUserConfiguredDCPowerMode(
PowerModeGuid: ptr GUID # GUID*
): uint32 {.importc: "PowerSetUserConfiguredDCPowerMode", stdcall, dynlib: "POWRPROF.dll".}pragma(lib, "powrprof");
extern(Windows)
uint PowerSetUserConfiguredDCPowerMode(
GUID* PowerModeGuid // GUID*
);ccall((:PowerSetUserConfiguredDCPowerMode, "POWRPROF.dll"), stdcall, UInt32,
(Ptr{GUID},),
PowerModeGuid)
# PowerModeGuid : GUID* -> Ptr{GUID}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t PowerSetUserConfiguredDCPowerMode(
void* PowerModeGuid);
]]
local powrprof = ffi.load("powrprof")
-- powrprof.PowerSetUserConfiguredDCPowerMode(PowerModeGuid)
-- PowerModeGuid : GUID*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('POWRPROF.dll');
const PowerSetUserConfiguredDCPowerMode = lib.func('__stdcall', 'PowerSetUserConfiguredDCPowerMode', 'uint32_t', ['void *']);
// PowerSetUserConfiguredDCPowerMode(PowerModeGuid)
// PowerModeGuid : GUID* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("POWRPROF.dll", {
PowerSetUserConfiguredDCPowerMode: { parameters: ["pointer"], result: "u32" },
});
// lib.symbols.PowerSetUserConfiguredDCPowerMode(PowerModeGuid)
// PowerModeGuid : GUID* -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t PowerSetUserConfiguredDCPowerMode(
void* PowerModeGuid);
C, "POWRPROF.dll");
// $ffi->PowerSetUserConfiguredDCPowerMode(PowerModeGuid);
// PowerModeGuid : GUID*
// 構造体/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 PowerSetUserConfiguredDCPowerMode(
Pointer PowerModeGuid // GUID*
);
}@[Link("powrprof")]
lib LibPOWRPROF
fun PowerSetUserConfiguredDCPowerMode = PowerSetUserConfiguredDCPowerMode(
PowerModeGuid : GUID* # GUID*
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef PowerSetUserConfiguredDCPowerModeNative = Uint32 Function(Pointer<Void>);
typedef PowerSetUserConfiguredDCPowerModeDart = int Function(Pointer<Void>);
final PowerSetUserConfiguredDCPowerMode = DynamicLibrary.open('POWRPROF.dll')
.lookupFunction<PowerSetUserConfiguredDCPowerModeNative, PowerSetUserConfiguredDCPowerModeDart>('PowerSetUserConfiguredDCPowerMode');
// PowerModeGuid : GUID* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function PowerSetUserConfiguredDCPowerMode(
PowerModeGuid: PGUID // GUID*
): DWORD; stdcall;
external 'POWRPROF.dll' name 'PowerSetUserConfiguredDCPowerMode';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PowerSetUserConfiguredDCPowerMode"
c_PowerSetUserConfiguredDCPowerMode :: Ptr () -> IO Word32
-- PowerModeGuid : GUID* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let powersetuserconfigureddcpowermode =
foreign "PowerSetUserConfiguredDCPowerMode"
((ptr void) @-> returning uint32_t)
(* PowerModeGuid : GUID* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library powrprof (t "POWRPROF.dll"))
(cffi:use-foreign-library powrprof)
(cffi:defcfun ("PowerSetUserConfiguredDCPowerMode" power-set-user-configured-dcpower-mode :convention :stdcall) :uint32
(power-mode-guid :pointer)) ; GUID*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $PowerSetUserConfiguredDCPowerMode = Win32::API::More->new('POWRPROF',
'DWORD PowerSetUserConfiguredDCPowerMode(LPVOID PowerModeGuid)');
# my $ret = $PowerSetUserConfiguredDCPowerMode->Call($PowerModeGuid);
# PowerModeGuid : GUID* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。