Win32 API 日本語リファレンス
ホームUI.Input.KeyboardAndMouse › GetKeyboardLayoutList

GetKeyboardLayoutList

関数
システム内のキーボードレイアウトハンドルの一覧を取得する。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

INT GetKeyboardLayoutList(
    INT nBuff,
    HKL* lpList   // optional
);

パラメーター

名前方向
nBuffINTin
lpListHKL*outoptional

戻り値の型: INT

各言語での呼び出し定義

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

INT GetKeyboardLayoutList(
    INT nBuff,
    HKL* lpList   // optional
);
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern int GetKeyboardLayoutList(
    int nBuff,   // INT
    IntPtr lpList   // HKL* optional, out
);
<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetKeyboardLayoutList(
    nBuff As Integer,   ' INT
    lpList As IntPtr   ' HKL* optional, out
) As Integer
End Function
' nBuff : INT
' lpList : HKL* optional, out
Declare PtrSafe Function GetKeyboardLayoutList Lib "user32" ( _
    ByVal nBuff As Long, _
    ByVal lpList As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetKeyboardLayoutList = ctypes.windll.user32.GetKeyboardLayoutList
GetKeyboardLayoutList.restype = ctypes.c_int
GetKeyboardLayoutList.argtypes = [
    ctypes.c_int,  # nBuff : INT
    ctypes.c_void_p,  # lpList : HKL* optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
GetKeyboardLayoutList = Fiddle::Function.new(
  lib['GetKeyboardLayoutList'],
  [
    Fiddle::TYPE_INT,  # nBuff : INT
    Fiddle::TYPE_VOIDP,  # lpList : HKL* optional, out
  ],
  Fiddle::TYPE_INT)
#[link(name = "user32")]
extern "system" {
    fn GetKeyboardLayoutList(
        nBuff: i32,  // INT
        lpList: *mut *mut core::ffi::c_void  // HKL* optional, out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USER32.dll", SetLastError = true)]
public static extern int GetKeyboardLayoutList(int nBuff, IntPtr lpList);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_GetKeyboardLayoutList' -Namespace Win32 -PassThru
# $api::GetKeyboardLayoutList(nBuff, lpList)
#uselib "USER32.dll"
#func global GetKeyboardLayoutList "GetKeyboardLayoutList" sptr, sptr
; GetKeyboardLayoutList nBuff, lpList   ; 戻り値は stat
; nBuff : INT -> "sptr"
; lpList : HKL* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global GetKeyboardLayoutList "GetKeyboardLayoutList" int, sptr
; res = GetKeyboardLayoutList(nBuff, lpList)
; nBuff : INT -> "int"
; lpList : HKL* optional, out -> "sptr"
; INT GetKeyboardLayoutList(INT nBuff, HKL* lpList)
#uselib "USER32.dll"
#cfunc global GetKeyboardLayoutList "GetKeyboardLayoutList" int, intptr
; res = GetKeyboardLayoutList(nBuff, lpList)
; nBuff : INT -> "int"
; lpList : HKL* optional, out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procGetKeyboardLayoutList = user32.NewProc("GetKeyboardLayoutList")
)

// nBuff (INT), lpList (HKL* optional, out)
r1, _, err := procGetKeyboardLayoutList.Call(
	uintptr(nBuff),
	uintptr(lpList),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function GetKeyboardLayoutList(
  nBuff: Integer;   // INT
  lpList: Pointer   // HKL* optional, out
): Integer; stdcall;
  external 'USER32.dll' name 'GetKeyboardLayoutList';
result := DllCall("USER32\GetKeyboardLayoutList"
    , "Int", nBuff   ; INT
    , "Ptr", lpList   ; HKL* optional, out
    , "Int")   ; return: INT
●GetKeyboardLayoutList(nBuff, lpList) = DLL("USER32.dll", "int GetKeyboardLayoutList(int, void*)")
# 呼び出し: GetKeyboardLayoutList(nBuff, lpList)
# nBuff : INT -> "int"
# lpList : HKL* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。