ホーム › Globalization › GetDistanceOfClosestLanguageInList
GetDistanceOfClosestLanguageInList
関数一覧内で最も近い言語との距離を取得する。
シグネチャ
// bcp47mrm.dll
#include <windows.h>
HRESULT GetDistanceOfClosestLanguageInList(
LPCWSTR pszLanguage,
LPCWSTR pszLanguagesList,
WCHAR wchListDelimiter,
DOUBLE* pClosestDistance
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pszLanguage | LPCWSTR | in | 候補となる言語を表す BCP-47 言語タグです。 |
| pszLanguagesList | LPCWSTR | in | 候補言語と比較する BCP-47 言語タグの、文字区切りリストです。通常はユーザー言語のリストになります。 wchListDelimiter パラメーターが |
| wchListDelimiter | WCHAR | in | 言語リスト内で区切り文字として使用される文字、または言語リストが二重 null 終端のリストであることを示す L'\0' です。
このパラメーターが L'\0' の場合、関数はわずかに効率的に動作します。 |
| pClosestDistance | DOUBLE* | out | 候補言語と、リスト内で最も一致する言語との間の距離を受け取ります。 値は 0.0 から 1.0 の範囲で、1.0 は完全一致を表します。 |
戻り値の型: HRESULT
公式ドキュメント
指定された言語コードと、言語リスト内で最も一致する言語との間の距離を求めます。
戻り値
型: HRESULT
リスト内のいずれの言語とも一致しない場合、関数は HRESULT_FROM_WIN32(ERROR_NO_MATCH) と距離 0.0 を返します。
解説(Remarks)
この関数はローカライズに利用でき、ユーザー言語のリストの中から候補言語に最も近い一致を見つけることができます。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// bcp47mrm.dll
#include <windows.h>
HRESULT GetDistanceOfClosestLanguageInList(
LPCWSTR pszLanguage,
LPCWSTR pszLanguagesList,
WCHAR wchListDelimiter,
DOUBLE* pClosestDistance
);[DllImport("bcp47mrm.dll", ExactSpelling = true)]
static extern int GetDistanceOfClosestLanguageInList(
[MarshalAs(UnmanagedType.LPWStr)] string pszLanguage, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string pszLanguagesList, // LPCWSTR
char wchListDelimiter, // WCHAR
out double pClosestDistance // DOUBLE* out
);<DllImport("bcp47mrm.dll", ExactSpelling:=True)>
Public Shared Function GetDistanceOfClosestLanguageInList(
<MarshalAs(UnmanagedType.LPWStr)> pszLanguage As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> pszLanguagesList As String, ' LPCWSTR
wchListDelimiter As Char, ' WCHAR
<Out> ByRef pClosestDistance As Double ' DOUBLE* out
) As Integer
End Function' pszLanguage : LPCWSTR
' pszLanguagesList : LPCWSTR
' wchListDelimiter : WCHAR
' pClosestDistance : DOUBLE* out
Declare PtrSafe Function GetDistanceOfClosestLanguageInList Lib "bcp47mrm" ( _
ByVal pszLanguage As LongPtr, _
ByVal pszLanguagesList As LongPtr, _
ByVal wchListDelimiter As Integer, _
ByRef pClosestDistance As Double) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetDistanceOfClosestLanguageInList = ctypes.windll.bcp47mrm.GetDistanceOfClosestLanguageInList
GetDistanceOfClosestLanguageInList.restype = ctypes.c_int
GetDistanceOfClosestLanguageInList.argtypes = [
wintypes.LPCWSTR, # pszLanguage : LPCWSTR
wintypes.LPCWSTR, # pszLanguagesList : LPCWSTR
ctypes.c_wchar, # wchListDelimiter : WCHAR
ctypes.POINTER(ctypes.c_double), # pClosestDistance : DOUBLE* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('bcp47mrm.dll')
GetDistanceOfClosestLanguageInList = Fiddle::Function.new(
lib['GetDistanceOfClosestLanguageInList'],
[
Fiddle::TYPE_VOIDP, # pszLanguage : LPCWSTR
Fiddle::TYPE_VOIDP, # pszLanguagesList : LPCWSTR
Fiddle::TYPE_SHORT, # wchListDelimiter : WCHAR
Fiddle::TYPE_VOIDP, # pClosestDistance : DOUBLE* out
],
Fiddle::TYPE_INT)#[link(name = "bcp47mrm")]
extern "system" {
fn GetDistanceOfClosestLanguageInList(
pszLanguage: *const u16, // LPCWSTR
pszLanguagesList: *const u16, // LPCWSTR
wchListDelimiter: u16, // WCHAR
pClosestDistance: *mut f64 // DOUBLE* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("bcp47mrm.dll")]
public static extern int GetDistanceOfClosestLanguageInList([MarshalAs(UnmanagedType.LPWStr)] string pszLanguage, [MarshalAs(UnmanagedType.LPWStr)] string pszLanguagesList, char wchListDelimiter, out double pClosestDistance);
"@
$api = Add-Type -MemberDefinition $sig -Name 'bcp47mrm_GetDistanceOfClosestLanguageInList' -Namespace Win32 -PassThru
# $api::GetDistanceOfClosestLanguageInList(pszLanguage, pszLanguagesList, wchListDelimiter, pClosestDistance)#uselib "bcp47mrm.dll"
#func global GetDistanceOfClosestLanguageInList "GetDistanceOfClosestLanguageInList" sptr, sptr, sptr, sptr
; GetDistanceOfClosestLanguageInList pszLanguage, pszLanguagesList, wchListDelimiter, varptr(pClosestDistance) ; 戻り値は stat
; pszLanguage : LPCWSTR -> "sptr"
; pszLanguagesList : LPCWSTR -> "sptr"
; wchListDelimiter : WCHAR -> "sptr"
; pClosestDistance : DOUBLE* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "bcp47mrm.dll" #cfunc global GetDistanceOfClosestLanguageInList "GetDistanceOfClosestLanguageInList" wstr, wstr, int, var ; res = GetDistanceOfClosestLanguageInList(pszLanguage, pszLanguagesList, wchListDelimiter, pClosestDistance) ; pszLanguage : LPCWSTR -> "wstr" ; pszLanguagesList : LPCWSTR -> "wstr" ; wchListDelimiter : WCHAR -> "int" ; pClosestDistance : DOUBLE* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "bcp47mrm.dll" #cfunc global GetDistanceOfClosestLanguageInList "GetDistanceOfClosestLanguageInList" wstr, wstr, int, sptr ; res = GetDistanceOfClosestLanguageInList(pszLanguage, pszLanguagesList, wchListDelimiter, varptr(pClosestDistance)) ; pszLanguage : LPCWSTR -> "wstr" ; pszLanguagesList : LPCWSTR -> "wstr" ; wchListDelimiter : WCHAR -> "int" ; pClosestDistance : DOUBLE* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT GetDistanceOfClosestLanguageInList(LPCWSTR pszLanguage, LPCWSTR pszLanguagesList, WCHAR wchListDelimiter, DOUBLE* pClosestDistance) #uselib "bcp47mrm.dll" #cfunc global GetDistanceOfClosestLanguageInList "GetDistanceOfClosestLanguageInList" wstr, wstr, int, var ; res = GetDistanceOfClosestLanguageInList(pszLanguage, pszLanguagesList, wchListDelimiter, pClosestDistance) ; pszLanguage : LPCWSTR -> "wstr" ; pszLanguagesList : LPCWSTR -> "wstr" ; wchListDelimiter : WCHAR -> "int" ; pClosestDistance : DOUBLE* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT GetDistanceOfClosestLanguageInList(LPCWSTR pszLanguage, LPCWSTR pszLanguagesList, WCHAR wchListDelimiter, DOUBLE* pClosestDistance) #uselib "bcp47mrm.dll" #cfunc global GetDistanceOfClosestLanguageInList "GetDistanceOfClosestLanguageInList" wstr, wstr, int, intptr ; res = GetDistanceOfClosestLanguageInList(pszLanguage, pszLanguagesList, wchListDelimiter, varptr(pClosestDistance)) ; pszLanguage : LPCWSTR -> "wstr" ; pszLanguagesList : LPCWSTR -> "wstr" ; wchListDelimiter : WCHAR -> "int" ; pClosestDistance : DOUBLE* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
bcp47mrm = windows.NewLazySystemDLL("bcp47mrm.dll")
procGetDistanceOfClosestLanguageInList = bcp47mrm.NewProc("GetDistanceOfClosestLanguageInList")
)
// pszLanguage (LPCWSTR), pszLanguagesList (LPCWSTR), wchListDelimiter (WCHAR), pClosestDistance (DOUBLE* out)
r1, _, err := procGetDistanceOfClosestLanguageInList.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszLanguage))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszLanguagesList))),
uintptr(wchListDelimiter),
uintptr(pClosestDistance),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction GetDistanceOfClosestLanguageInList(
pszLanguage: PWideChar; // LPCWSTR
pszLanguagesList: PWideChar; // LPCWSTR
wchListDelimiter: WideChar; // WCHAR
pClosestDistance: Pointer // DOUBLE* out
): Integer; stdcall;
external 'bcp47mrm.dll' name 'GetDistanceOfClosestLanguageInList';result := DllCall("bcp47mrm\GetDistanceOfClosestLanguageInList"
, "WStr", pszLanguage ; LPCWSTR
, "WStr", pszLanguagesList ; LPCWSTR
, "Short", wchListDelimiter ; WCHAR
, "Ptr", pClosestDistance ; DOUBLE* out
, "Int") ; return: HRESULT●GetDistanceOfClosestLanguageInList(pszLanguage, pszLanguagesList, wchListDelimiter, pClosestDistance) = DLL("bcp47mrm.dll", "int GetDistanceOfClosestLanguageInList(char*, char*, int, void*)")
# 呼び出し: GetDistanceOfClosestLanguageInList(pszLanguage, pszLanguagesList, wchListDelimiter, pClosestDistance)
# pszLanguage : LPCWSTR -> "char*"
# pszLanguagesList : LPCWSTR -> "char*"
# wchListDelimiter : WCHAR -> "int"
# pClosestDistance : DOUBLE* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "bcp47mrm" fn GetDistanceOfClosestLanguageInList(
pszLanguage: [*c]const u16, // LPCWSTR
pszLanguagesList: [*c]const u16, // LPCWSTR
wchListDelimiter: u16, // WCHAR
pClosestDistance: [*c]f64 // DOUBLE* out
) callconv(std.os.windows.WINAPI) i32;proc GetDistanceOfClosestLanguageInList(
pszLanguage: WideCString, # LPCWSTR
pszLanguagesList: WideCString, # LPCWSTR
wchListDelimiter: uint16, # WCHAR
pClosestDistance: ptr float64 # DOUBLE* out
): int32 {.importc: "GetDistanceOfClosestLanguageInList", stdcall, dynlib: "bcp47mrm.dll".}pragma(lib, "bcp47mrm");
extern(Windows)
int GetDistanceOfClosestLanguageInList(
const(wchar)* pszLanguage, // LPCWSTR
const(wchar)* pszLanguagesList, // LPCWSTR
wchar wchListDelimiter, // WCHAR
double* pClosestDistance // DOUBLE* out
);ccall((:GetDistanceOfClosestLanguageInList, "bcp47mrm.dll"), stdcall, Int32,
(Cwstring, Cwstring, UInt16, Ptr{Float64}),
pszLanguage, pszLanguagesList, wchListDelimiter, pClosestDistance)
# pszLanguage : LPCWSTR -> Cwstring
# pszLanguagesList : LPCWSTR -> Cwstring
# wchListDelimiter : WCHAR -> UInt16
# pClosestDistance : DOUBLE* out -> Ptr{Float64}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GetDistanceOfClosestLanguageInList(
const uint16_t* pszLanguage,
const uint16_t* pszLanguagesList,
uint16_t wchListDelimiter,
double* pClosestDistance);
]]
local bcp47mrm = ffi.load("bcp47mrm")
-- bcp47mrm.GetDistanceOfClosestLanguageInList(pszLanguage, pszLanguagesList, wchListDelimiter, pClosestDistance)
-- pszLanguage : LPCWSTR
-- pszLanguagesList : LPCWSTR
-- wchListDelimiter : WCHAR
-- pClosestDistance : DOUBLE* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('bcp47mrm.dll');
const GetDistanceOfClosestLanguageInList = lib.func('__stdcall', 'GetDistanceOfClosestLanguageInList', 'int32_t', ['str16', 'str16', 'uint16_t', 'double *']);
// GetDistanceOfClosestLanguageInList(pszLanguage, pszLanguagesList, wchListDelimiter, pClosestDistance)
// pszLanguage : LPCWSTR -> 'str16'
// pszLanguagesList : LPCWSTR -> 'str16'
// wchListDelimiter : WCHAR -> 'uint16_t'
// pClosestDistance : DOUBLE* out -> 'double *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("bcp47mrm.dll", {
GetDistanceOfClosestLanguageInList: { parameters: ["buffer", "buffer", "u16", "pointer"], result: "i32" },
});
// lib.symbols.GetDistanceOfClosestLanguageInList(pszLanguage, pszLanguagesList, wchListDelimiter, pClosestDistance)
// pszLanguage : LPCWSTR -> "buffer"
// pszLanguagesList : LPCWSTR -> "buffer"
// wchListDelimiter : WCHAR -> "u16"
// pClosestDistance : DOUBLE* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetDistanceOfClosestLanguageInList(
const uint16_t* pszLanguage,
const uint16_t* pszLanguagesList,
uint16_t wchListDelimiter,
double* pClosestDistance);
C, "bcp47mrm.dll");
// $ffi->GetDistanceOfClosestLanguageInList(pszLanguage, pszLanguagesList, wchListDelimiter, pClosestDistance);
// pszLanguage : LPCWSTR
// pszLanguagesList : LPCWSTR
// wchListDelimiter : WCHAR
// pClosestDistance : DOUBLE* out
// 構造体/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 Bcp47mrm extends StdCallLibrary {
Bcp47mrm INSTANCE = Native.load("bcp47mrm", Bcp47mrm.class);
int GetDistanceOfClosestLanguageInList(
WString pszLanguage, // LPCWSTR
WString pszLanguagesList, // LPCWSTR
char wchListDelimiter, // WCHAR
DoubleByReference pClosestDistance // DOUBLE* out
);
}@[Link("bcp47mrm")]
lib Libbcp47mrm
fun GetDistanceOfClosestLanguageInList = GetDistanceOfClosestLanguageInList(
pszLanguage : UInt16*, # LPCWSTR
pszLanguagesList : UInt16*, # LPCWSTR
wchListDelimiter : UInt16, # WCHAR
pClosestDistance : Float64* # DOUBLE* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetDistanceOfClosestLanguageInListNative = Int32 Function(Pointer<Utf16>, Pointer<Utf16>, Uint16, Pointer<Double>);
typedef GetDistanceOfClosestLanguageInListDart = int Function(Pointer<Utf16>, Pointer<Utf16>, int, Pointer<Double>);
final GetDistanceOfClosestLanguageInList = DynamicLibrary.open('bcp47mrm.dll')
.lookupFunction<GetDistanceOfClosestLanguageInListNative, GetDistanceOfClosestLanguageInListDart>('GetDistanceOfClosestLanguageInList');
// pszLanguage : LPCWSTR -> Pointer<Utf16>
// pszLanguagesList : LPCWSTR -> Pointer<Utf16>
// wchListDelimiter : WCHAR -> Uint16
// pClosestDistance : DOUBLE* out -> Pointer<Double>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetDistanceOfClosestLanguageInList(
pszLanguage: PWideChar; // LPCWSTR
pszLanguagesList: PWideChar; // LPCWSTR
wchListDelimiter: WideChar; // WCHAR
pClosestDistance: Pointer // DOUBLE* out
): Integer; stdcall;
external 'bcp47mrm.dll' name 'GetDistanceOfClosestLanguageInList';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetDistanceOfClosestLanguageInList"
c_GetDistanceOfClosestLanguageInList :: CWString -> CWString -> Word16 -> Ptr CDouble -> IO Int32
-- pszLanguage : LPCWSTR -> CWString
-- pszLanguagesList : LPCWSTR -> CWString
-- wchListDelimiter : WCHAR -> Word16
-- pClosestDistance : DOUBLE* out -> Ptr CDouble
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getdistanceofclosestlanguageinlist =
foreign "GetDistanceOfClosestLanguageInList"
((ptr uint16_t) @-> (ptr uint16_t) @-> uint16_t @-> (ptr double) @-> returning int32_t)
(* pszLanguage : LPCWSTR -> (ptr uint16_t) *)
(* pszLanguagesList : LPCWSTR -> (ptr uint16_t) *)
(* wchListDelimiter : WCHAR -> uint16_t *)
(* pClosestDistance : DOUBLE* out -> (ptr double) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library bcp47mrm (t "bcp47mrm.dll"))
(cffi:use-foreign-library bcp47mrm)
(cffi:defcfun ("GetDistanceOfClosestLanguageInList" get-distance-of-closest-language-in-list :convention :stdcall) :int32
(psz-language (:string :encoding :utf-16le)) ; LPCWSTR
(psz-languages-list (:string :encoding :utf-16le)) ; LPCWSTR
(wch-list-delimiter :uint16) ; WCHAR
(p-closest-distance :pointer)) ; DOUBLE* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetDistanceOfClosestLanguageInList = Win32::API::More->new('bcp47mrm',
'int GetDistanceOfClosestLanguageInList(LPCWSTR pszLanguage, LPCWSTR pszLanguagesList, WORD wchListDelimiter, LPVOID pClosestDistance)');
# my $ret = $GetDistanceOfClosestLanguageInList->Call($pszLanguage, $pszLanguagesList, $wchListDelimiter, $pClosestDistance);
# pszLanguage : LPCWSTR -> LPCWSTR
# pszLanguagesList : LPCWSTR -> LPCWSTR
# wchListDelimiter : WCHAR -> WORD
# pClosestDistance : DOUBLE* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。