Win32 API 日本語リファレンス
ホームGlobalization › GetNumberFormatEx

GetNumberFormatEx

関数
ロケール名に従って数値を書式付き文字列に整形する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

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

INT GetNumberFormatEx(
    LPCWSTR lpLocaleName,   // optional
    DWORD dwFlags,
    LPCWSTR lpValue,
    const NUMBERFMTW* lpFormat,   // optional
    LPWSTR lpNumberStr,   // optional
    INT cchNumber
);

パラメーター

名前方向
lpLocaleNameLPCWSTRinoptional
dwFlagsDWORDin
lpValueLPCWSTRin
lpFormatNUMBERFMTW*inoptional
lpNumberStrLPWSTRoutoptional
cchNumberINTin

戻り値の型: INT

各言語での呼び出し定義

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

INT GetNumberFormatEx(
    LPCWSTR lpLocaleName,   // optional
    DWORD dwFlags,
    LPCWSTR lpValue,
    const NUMBERFMTW* lpFormat,   // optional
    LPWSTR lpNumberStr,   // optional
    INT cchNumber
);
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern int GetNumberFormatEx(
    [MarshalAs(UnmanagedType.LPWStr)] string lpLocaleName,   // LPCWSTR optional
    uint dwFlags,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string lpValue,   // LPCWSTR
    IntPtr lpFormat,   // NUMBERFMTW* optional
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpNumberStr,   // LPWSTR optional, out
    int cchNumber   // INT
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetNumberFormatEx(
    <MarshalAs(UnmanagedType.LPWStr)> lpLocaleName As String,   ' LPCWSTR optional
    dwFlags As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> lpValue As String,   ' LPCWSTR
    lpFormat As IntPtr,   ' NUMBERFMTW* optional
    <MarshalAs(UnmanagedType.LPWStr)> lpNumberStr As System.Text.StringBuilder,   ' LPWSTR optional, out
    cchNumber As Integer   ' INT
) As Integer
End Function
' lpLocaleName : LPCWSTR optional
' dwFlags : DWORD
' lpValue : LPCWSTR
' lpFormat : NUMBERFMTW* optional
' lpNumberStr : LPWSTR optional, out
' cchNumber : INT
Declare PtrSafe Function GetNumberFormatEx Lib "kernel32" ( _
    ByVal lpLocaleName As LongPtr, _
    ByVal dwFlags As Long, _
    ByVal lpValue As LongPtr, _
    ByVal lpFormat As LongPtr, _
    ByVal lpNumberStr As LongPtr, _
    ByVal cchNumber As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetNumberFormatEx = ctypes.windll.kernel32.GetNumberFormatEx
GetNumberFormatEx.restype = ctypes.c_int
GetNumberFormatEx.argtypes = [
    wintypes.LPCWSTR,  # lpLocaleName : LPCWSTR optional
    wintypes.DWORD,  # dwFlags : DWORD
    wintypes.LPCWSTR,  # lpValue : LPCWSTR
    ctypes.c_void_p,  # lpFormat : NUMBERFMTW* optional
    wintypes.LPWSTR,  # lpNumberStr : LPWSTR optional, out
    ctypes.c_int,  # cchNumber : INT
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
GetNumberFormatEx = Fiddle::Function.new(
  lib['GetNumberFormatEx'],
  [
    Fiddle::TYPE_VOIDP,  # lpLocaleName : LPCWSTR optional
    -Fiddle::TYPE_INT,  # dwFlags : DWORD
    Fiddle::TYPE_VOIDP,  # lpValue : LPCWSTR
    Fiddle::TYPE_VOIDP,  # lpFormat : NUMBERFMTW* optional
    Fiddle::TYPE_VOIDP,  # lpNumberStr : LPWSTR optional, out
    Fiddle::TYPE_INT,  # cchNumber : INT
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn GetNumberFormatEx(
        lpLocaleName: *const u16,  // LPCWSTR optional
        dwFlags: u32,  // DWORD
        lpValue: *const u16,  // LPCWSTR
        lpFormat: *const NUMBERFMTW,  // NUMBERFMTW* optional
        lpNumberStr: *mut u16,  // LPWSTR optional, out
        cchNumber: i32  // INT
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern int GetNumberFormatEx([MarshalAs(UnmanagedType.LPWStr)] string lpLocaleName, uint dwFlags, [MarshalAs(UnmanagedType.LPWStr)] string lpValue, IntPtr lpFormat, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpNumberStr, int cchNumber);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetNumberFormatEx' -Namespace Win32 -PassThru
# $api::GetNumberFormatEx(lpLocaleName, dwFlags, lpValue, lpFormat, lpNumberStr, cchNumber)
#uselib "KERNEL32.dll"
#func global GetNumberFormatEx "GetNumberFormatEx" sptr, sptr, sptr, sptr, sptr, sptr
; GetNumberFormatEx lpLocaleName, dwFlags, lpValue, varptr(lpFormat), varptr(lpNumberStr), cchNumber   ; 戻り値は stat
; lpLocaleName : LPCWSTR optional -> "sptr"
; dwFlags : DWORD -> "sptr"
; lpValue : LPCWSTR -> "sptr"
; lpFormat : NUMBERFMTW* optional -> "sptr"
; lpNumberStr : LPWSTR optional, out -> "sptr"
; cchNumber : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global GetNumberFormatEx "GetNumberFormatEx" wstr, int, wstr, var, var, int
; res = GetNumberFormatEx(lpLocaleName, dwFlags, lpValue, lpFormat, lpNumberStr, cchNumber)
; lpLocaleName : LPCWSTR optional -> "wstr"
; dwFlags : DWORD -> "int"
; lpValue : LPCWSTR -> "wstr"
; lpFormat : NUMBERFMTW* optional -> "var"
; lpNumberStr : LPWSTR optional, out -> "var"
; cchNumber : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT GetNumberFormatEx(LPCWSTR lpLocaleName, DWORD dwFlags, LPCWSTR lpValue, NUMBERFMTW* lpFormat, LPWSTR lpNumberStr, INT cchNumber)
#uselib "KERNEL32.dll"
#cfunc global GetNumberFormatEx "GetNumberFormatEx" wstr, int, wstr, var, var, int
; res = GetNumberFormatEx(lpLocaleName, dwFlags, lpValue, lpFormat, lpNumberStr, cchNumber)
; lpLocaleName : LPCWSTR optional -> "wstr"
; dwFlags : DWORD -> "int"
; lpValue : LPCWSTR -> "wstr"
; lpFormat : NUMBERFMTW* optional -> "var"
; lpNumberStr : LPWSTR optional, out -> "var"
; cchNumber : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetNumberFormatEx = kernel32.NewProc("GetNumberFormatEx")
)

// lpLocaleName (LPCWSTR optional), dwFlags (DWORD), lpValue (LPCWSTR), lpFormat (NUMBERFMTW* optional), lpNumberStr (LPWSTR optional, out), cchNumber (INT)
r1, _, err := procGetNumberFormatEx.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpLocaleName))),
	uintptr(dwFlags),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpValue))),
	uintptr(lpFormat),
	uintptr(lpNumberStr),
	uintptr(cchNumber),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function GetNumberFormatEx(
  lpLocaleName: PWideChar;   // LPCWSTR optional
  dwFlags: DWORD;   // DWORD
  lpValue: PWideChar;   // LPCWSTR
  lpFormat: Pointer;   // NUMBERFMTW* optional
  lpNumberStr: PWideChar;   // LPWSTR optional, out
  cchNumber: Integer   // INT
): Integer; stdcall;
  external 'KERNEL32.dll' name 'GetNumberFormatEx';
result := DllCall("KERNEL32\GetNumberFormatEx"
    , "WStr", lpLocaleName   ; LPCWSTR optional
    , "UInt", dwFlags   ; DWORD
    , "WStr", lpValue   ; LPCWSTR
    , "Ptr", lpFormat   ; NUMBERFMTW* optional
    , "Ptr", lpNumberStr   ; LPWSTR optional, out
    , "Int", cchNumber   ; INT
    , "Int")   ; return: INT
●GetNumberFormatEx(lpLocaleName, dwFlags, lpValue, lpFormat, lpNumberStr, cchNumber) = DLL("KERNEL32.dll", "int GetNumberFormatEx(char*, dword, char*, void*, char*, int)")
# 呼び出し: GetNumberFormatEx(lpLocaleName, dwFlags, lpValue, lpFormat, lpNumberStr, cchNumber)
# lpLocaleName : LPCWSTR optional -> "char*"
# dwFlags : DWORD -> "dword"
# lpValue : LPCWSTR -> "char*"
# lpFormat : NUMBERFMTW* optional -> "void*"
# lpNumberStr : LPWSTR optional, out -> "char*"
# cchNumber : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。