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

UnloadKeyboardLayout

関数
読み込み済みのキーボードレイアウトを解放する。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL UnloadKeyboardLayout(
    HKL hkl
);

パラメーター

名前方向説明
hklHKLinアンロードする入力ロケール識別子。

戻り値の型: BOOL

公式ドキュメント

入力ロケール識別子(以前はキーボードレイアウトと呼ばれていたもの)をアンロードします。

戻り値

型: BOOL

関数が成功した場合、戻り値はゼロ以外の値です。

関数が失敗した場合、戻り値はゼロです。次の理由により、この関数は失敗することがあります。

拡張エラー情報を取得するには、GetLastError を呼び出します。

解説(Remarks)

入力ロケール識別子は、音声テキスト変換器、Input Method Editor (IME)、その他あらゆる形式の入力も包含できるため、キーボードレイアウトよりも広い概念です。

UnloadKeyboardLayout は、システム既定の入力ロケール識別子が唯一読み込まれているキーボードレイアウトである場合、それをアンロードできません。既定の入力ロケール識別子をアンロードする前に、まず別の入力ロケール識別子を読み込む必要があります。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

BOOL UnloadKeyboardLayout(
    HKL hkl
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool UnloadKeyboardLayout(
    IntPtr hkl   // HKL
);
<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function UnloadKeyboardLayout(
    hkl As IntPtr   ' HKL
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' hkl : HKL
Declare PtrSafe Function UnloadKeyboardLayout Lib "user32" ( _
    ByVal hkl As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

UnloadKeyboardLayout = ctypes.windll.user32.UnloadKeyboardLayout
UnloadKeyboardLayout.restype = wintypes.BOOL
UnloadKeyboardLayout.argtypes = [
    wintypes.HANDLE,  # hkl : HKL
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procUnloadKeyboardLayout = user32.NewProc("UnloadKeyboardLayout")
)

// hkl (HKL)
r1, _, err := procUnloadKeyboardLayout.Call(
	uintptr(hkl),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function UnloadKeyboardLayout(
  hkl: THandle   // HKL
): BOOL; stdcall;
  external 'USER32.dll' name 'UnloadKeyboardLayout';
result := DllCall("USER32\UnloadKeyboardLayout"
    , "Ptr", hkl   ; HKL
    , "Int")   ; return: BOOL
●UnloadKeyboardLayout(hkl) = DLL("USER32.dll", "bool UnloadKeyboardLayout(void*)")
# 呼び出し: UnloadKeyboardLayout(hkl)
# hkl : HKL -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "user32" fn UnloadKeyboardLayout(
    hkl: ?*anyopaque // HKL
) callconv(std.os.windows.WINAPI) i32;
proc UnloadKeyboardLayout(
    hkl: pointer  # HKL
): int32 {.importc: "UnloadKeyboardLayout", stdcall, dynlib: "USER32.dll".}
pragma(lib, "user32");
extern(Windows)
int UnloadKeyboardLayout(
    void* hkl   // HKL
);
ccall((:UnloadKeyboardLayout, "USER32.dll"), stdcall, Int32,
      (Ptr{Cvoid},),
      hkl)
# hkl : HKL -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t UnloadKeyboardLayout(
    void* hkl);
]]
local user32 = ffi.load("user32")
-- user32.UnloadKeyboardLayout(hkl)
-- hkl : HKL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const UnloadKeyboardLayout = lib.func('__stdcall', 'UnloadKeyboardLayout', 'int32_t', ['void *']);
// UnloadKeyboardLayout(hkl)
// hkl : HKL -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("USER32.dll", {
  UnloadKeyboardLayout: { parameters: ["pointer"], result: "i32" },
});
// lib.symbols.UnloadKeyboardLayout(hkl)
// hkl : HKL -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t UnloadKeyboardLayout(
    void* hkl);
C, "USER32.dll");
// $ffi->UnloadKeyboardLayout(hkl);
// hkl : HKL
// 構造体/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 User32 extends StdCallLibrary {
    User32 INSTANCE = Native.load("user32", User32.class);
    boolean UnloadKeyboardLayout(
        Pointer hkl   // HKL
    );
}
@[Link("user32")]
lib LibUSER32
  fun UnloadKeyboardLayout = UnloadKeyboardLayout(
    hkl : Void*   # HKL
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef UnloadKeyboardLayoutNative = Int32 Function(Pointer<Void>);
typedef UnloadKeyboardLayoutDart = int Function(Pointer<Void>);
final UnloadKeyboardLayout = DynamicLibrary.open('USER32.dll')
    .lookupFunction<UnloadKeyboardLayoutNative, UnloadKeyboardLayoutDart>('UnloadKeyboardLayout');
// hkl : HKL -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function UnloadKeyboardLayout(
  hkl: THandle   // HKL
): BOOL; stdcall;
  external 'USER32.dll' name 'UnloadKeyboardLayout';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "UnloadKeyboardLayout"
  c_UnloadKeyboardLayout :: Ptr () -> IO CInt
-- hkl : HKL -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let unloadkeyboardlayout =
  foreign "UnloadKeyboardLayout"
    ((ptr void) @-> returning int32_t)
(* hkl : HKL -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)

(cffi:defcfun ("UnloadKeyboardLayout" unload-keyboard-layout :convention :stdcall) :int32
  (hkl :pointer))   ; HKL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $UnloadKeyboardLayout = Win32::API::More->new('USER32',
    'BOOL UnloadKeyboardLayout(HANDLE hkl)');
# my $ret = $UnloadKeyboardLayout->Call($hkl);
# hkl : HKL -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目