ホーム › System.WindowsProgramming › SetFirmwareEnvironmentVariableExW
SetFirmwareEnvironmentVariableExW
関数属性付きでファームウェア環境変数の値をUnicodeで設定する。
シグネチャ
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
BOOL SetFirmwareEnvironmentVariableExW(
LPCWSTR lpName,
LPCWSTR lpGuid,
void* pValue, // optional
DWORD nSize,
DWORD dwAttributes
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpName | LPCWSTR | in |
| lpGuid | LPCWSTR | in |
| pValue | void* | inoptional |
| nSize | DWORD | in |
| dwAttributes | DWORD | in |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
BOOL SetFirmwareEnvironmentVariableExW(
LPCWSTR lpName,
LPCWSTR lpGuid,
void* pValue, // optional
DWORD nSize,
DWORD dwAttributes
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetFirmwareEnvironmentVariableExW(
[MarshalAs(UnmanagedType.LPWStr)] string lpName, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string lpGuid, // LPCWSTR
IntPtr pValue, // void* optional
uint nSize, // DWORD
uint dwAttributes // DWORD
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetFirmwareEnvironmentVariableExW(
<MarshalAs(UnmanagedType.LPWStr)> lpName As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> lpGuid As String, ' LPCWSTR
pValue As IntPtr, ' void* optional
nSize As UInteger, ' DWORD
dwAttributes As UInteger ' DWORD
) As Boolean
End Function' lpName : LPCWSTR
' lpGuid : LPCWSTR
' pValue : void* optional
' nSize : DWORD
' dwAttributes : DWORD
Declare PtrSafe Function SetFirmwareEnvironmentVariableExW Lib "kernel32" ( _
ByVal lpName As LongPtr, _
ByVal lpGuid As LongPtr, _
ByVal pValue As LongPtr, _
ByVal nSize As Long, _
ByVal dwAttributes As Long) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetFirmwareEnvironmentVariableExW = ctypes.windll.kernel32.SetFirmwareEnvironmentVariableExW
SetFirmwareEnvironmentVariableExW.restype = wintypes.BOOL
SetFirmwareEnvironmentVariableExW.argtypes = [
wintypes.LPCWSTR, # lpName : LPCWSTR
wintypes.LPCWSTR, # lpGuid : LPCWSTR
ctypes.POINTER(None), # pValue : void* optional
wintypes.DWORD, # nSize : DWORD
wintypes.DWORD, # dwAttributes : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
SetFirmwareEnvironmentVariableExW = Fiddle::Function.new(
lib['SetFirmwareEnvironmentVariableExW'],
[
Fiddle::TYPE_VOIDP, # lpName : LPCWSTR
Fiddle::TYPE_VOIDP, # lpGuid : LPCWSTR
Fiddle::TYPE_VOIDP, # pValue : void* optional
-Fiddle::TYPE_INT, # nSize : DWORD
-Fiddle::TYPE_INT, # dwAttributes : DWORD
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "kernel32")]
extern "system" {
fn SetFirmwareEnvironmentVariableExW(
lpName: *const u16, // LPCWSTR
lpGuid: *const u16, // LPCWSTR
pValue: *mut (), // void* optional
nSize: u32, // DWORD
dwAttributes: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool SetFirmwareEnvironmentVariableExW([MarshalAs(UnmanagedType.LPWStr)] string lpName, [MarshalAs(UnmanagedType.LPWStr)] string lpGuid, IntPtr pValue, uint nSize, uint dwAttributes);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SetFirmwareEnvironmentVariableExW' -Namespace Win32 -PassThru
# $api::SetFirmwareEnvironmentVariableExW(lpName, lpGuid, pValue, nSize, dwAttributes)#uselib "KERNEL32.dll"
#func global SetFirmwareEnvironmentVariableExW "SetFirmwareEnvironmentVariableExW" wptr, wptr, wptr, wptr, wptr
; SetFirmwareEnvironmentVariableExW lpName, lpGuid, pValue, nSize, dwAttributes ; 戻り値は stat
; lpName : LPCWSTR -> "wptr"
; lpGuid : LPCWSTR -> "wptr"
; pValue : void* optional -> "wptr"
; nSize : DWORD -> "wptr"
; dwAttributes : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global SetFirmwareEnvironmentVariableExW "SetFirmwareEnvironmentVariableExW" wstr, wstr, sptr, int, int
; res = SetFirmwareEnvironmentVariableExW(lpName, lpGuid, pValue, nSize, dwAttributes)
; lpName : LPCWSTR -> "wstr"
; lpGuid : LPCWSTR -> "wstr"
; pValue : void* optional -> "sptr"
; nSize : DWORD -> "int"
; dwAttributes : DWORD -> "int"; BOOL SetFirmwareEnvironmentVariableExW(LPCWSTR lpName, LPCWSTR lpGuid, void* pValue, DWORD nSize, DWORD dwAttributes)
#uselib "KERNEL32.dll"
#cfunc global SetFirmwareEnvironmentVariableExW "SetFirmwareEnvironmentVariableExW" wstr, wstr, intptr, int, int
; res = SetFirmwareEnvironmentVariableExW(lpName, lpGuid, pValue, nSize, dwAttributes)
; lpName : LPCWSTR -> "wstr"
; lpGuid : LPCWSTR -> "wstr"
; pValue : void* optional -> "intptr"
; nSize : DWORD -> "int"
; dwAttributes : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procSetFirmwareEnvironmentVariableExW = kernel32.NewProc("SetFirmwareEnvironmentVariableExW")
)
// lpName (LPCWSTR), lpGuid (LPCWSTR), pValue (void* optional), nSize (DWORD), dwAttributes (DWORD)
r1, _, err := procSetFirmwareEnvironmentVariableExW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpGuid))),
uintptr(pValue),
uintptr(nSize),
uintptr(dwAttributes),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetFirmwareEnvironmentVariableExW(
lpName: PWideChar; // LPCWSTR
lpGuid: PWideChar; // LPCWSTR
pValue: Pointer; // void* optional
nSize: DWORD; // DWORD
dwAttributes: DWORD // DWORD
): BOOL; stdcall;
external 'KERNEL32.dll' name 'SetFirmwareEnvironmentVariableExW';result := DllCall("KERNEL32\SetFirmwareEnvironmentVariableExW"
, "WStr", lpName ; LPCWSTR
, "WStr", lpGuid ; LPCWSTR
, "Ptr", pValue ; void* optional
, "UInt", nSize ; DWORD
, "UInt", dwAttributes ; DWORD
, "Int") ; return: BOOL●SetFirmwareEnvironmentVariableExW(lpName, lpGuid, pValue, nSize, dwAttributes) = DLL("KERNEL32.dll", "bool SetFirmwareEnvironmentVariableExW(char*, char*, void*, dword, dword)")
# 呼び出し: SetFirmwareEnvironmentVariableExW(lpName, lpGuid, pValue, nSize, dwAttributes)
# lpName : LPCWSTR -> "char*"
# lpGuid : LPCWSTR -> "char*"
# pValue : void* optional -> "void*"
# nSize : DWORD -> "dword"
# dwAttributes : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。