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

GetCurrencyFormatEx

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

シグネチャ

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

INT GetCurrencyFormatEx(
    LPCWSTR lpLocaleName,   // optional
    DWORD dwFlags,
    LPCWSTR lpValue,
    const CURRENCYFMTW* lpFormat,   // optional
    LPWSTR lpCurrencyStr,   // optional
    INT cchCurrency
);

パラメーター

名前方向
lpLocaleNameLPCWSTRinoptional
dwFlagsDWORDin
lpValueLPCWSTRin
lpFormatCURRENCYFMTW*inoptional
lpCurrencyStrLPWSTRoutoptional
cchCurrencyINTin

戻り値の型: INT

各言語での呼び出し定義

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

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

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

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetCurrencyFormatEx = kernel32.NewProc("GetCurrencyFormatEx")
)

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