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

GetCurrencyFormatW

関数
指定ロケールに従い通貨を文字列へ整形する。Unicode版。
DLLKERNEL32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// KERNEL32.dll  (Unicode / -W)
#include <windows.h>

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

パラメーター

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

戻り値の型: INT

各言語での呼び出し定義

// KERNEL32.dll  (Unicode / -W)
#include <windows.h>

INT GetCurrencyFormatW(
    DWORD Locale,
    DWORD dwFlags,
    LPCWSTR lpValue,
    const CURRENCYFMTW* lpFormat,   // optional
    LPWSTR lpCurrencyStr,   // optional
    INT cchCurrency
);
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern int GetCurrencyFormatW(
    uint Locale,   // DWORD
    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", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetCurrencyFormatW(
    Locale As UInteger,   ' DWORD
    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
' Locale : DWORD
' dwFlags : DWORD
' lpValue : LPCWSTR
' lpFormat : CURRENCYFMTW* optional
' lpCurrencyStr : LPWSTR optional, out
' cchCurrency : INT
Declare PtrSafe Function GetCurrencyFormatW Lib "kernel32" ( _
    ByVal Locale As Long, _
    ByVal dwFlags As Long, _
    ByVal lpValue As LongPtr, _
    ByVal lpFormat As LongPtr, _
    ByVal lpCurrencyStr As LongPtr, _
    ByVal cchCurrency As Long) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetCurrencyFormatW = ctypes.windll.kernel32.GetCurrencyFormatW
GetCurrencyFormatW.restype = ctypes.c_int
GetCurrencyFormatW.argtypes = [
    wintypes.DWORD,  # Locale : DWORD
    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')
GetCurrencyFormatW = Fiddle::Function.new(
  lib['GetCurrencyFormatW'],
  [
    -Fiddle::TYPE_INT,  # Locale : DWORD
    -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)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "kernel32")]
extern "system" {
    fn GetCurrencyFormatW(
        Locale: u32,  // DWORD
        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", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int GetCurrencyFormatW(uint Locale, 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_GetCurrencyFormatW' -Namespace Win32 -PassThru
# $api::GetCurrencyFormatW(Locale, dwFlags, lpValue, lpFormat, lpCurrencyStr, cchCurrency)
#uselib "KERNEL32.dll"
#func global GetCurrencyFormatW "GetCurrencyFormatW" wptr, wptr, wptr, wptr, wptr, wptr
; GetCurrencyFormatW Locale, dwFlags, lpValue, varptr(lpFormat), varptr(lpCurrencyStr), cchCurrency   ; 戻り値は stat
; Locale : DWORD -> "wptr"
; dwFlags : DWORD -> "wptr"
; lpValue : LPCWSTR -> "wptr"
; lpFormat : CURRENCYFMTW* optional -> "wptr"
; lpCurrencyStr : LPWSTR optional, out -> "wptr"
; cchCurrency : INT -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global GetCurrencyFormatW "GetCurrencyFormatW" int, int, wstr, var, var, int
; res = GetCurrencyFormatW(Locale, dwFlags, lpValue, lpFormat, lpCurrencyStr, cchCurrency)
; Locale : DWORD -> "int"
; dwFlags : DWORD -> "int"
; lpValue : LPCWSTR -> "wstr"
; lpFormat : CURRENCYFMTW* optional -> "var"
; lpCurrencyStr : LPWSTR optional, out -> "var"
; cchCurrency : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT GetCurrencyFormatW(DWORD Locale, DWORD dwFlags, LPCWSTR lpValue, CURRENCYFMTW* lpFormat, LPWSTR lpCurrencyStr, INT cchCurrency)
#uselib "KERNEL32.dll"
#cfunc global GetCurrencyFormatW "GetCurrencyFormatW" int, int, wstr, var, var, int
; res = GetCurrencyFormatW(Locale, dwFlags, lpValue, lpFormat, lpCurrencyStr, cchCurrency)
; Locale : DWORD -> "int"
; 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")
	procGetCurrencyFormatW = kernel32.NewProc("GetCurrencyFormatW")
)

// Locale (DWORD), dwFlags (DWORD), lpValue (LPCWSTR), lpFormat (CURRENCYFMTW* optional), lpCurrencyStr (LPWSTR optional, out), cchCurrency (INT)
r1, _, err := procGetCurrencyFormatW.Call(
	uintptr(Locale),
	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 GetCurrencyFormatW(
  Locale: DWORD;   // DWORD
  dwFlags: DWORD;   // DWORD
  lpValue: PWideChar;   // LPCWSTR
  lpFormat: Pointer;   // CURRENCYFMTW* optional
  lpCurrencyStr: PWideChar;   // LPWSTR optional, out
  cchCurrency: Integer   // INT
): Integer; stdcall;
  external 'KERNEL32.dll' name 'GetCurrencyFormatW';
result := DllCall("KERNEL32\GetCurrencyFormatW"
    , "UInt", Locale   ; DWORD
    , "UInt", dwFlags   ; DWORD
    , "WStr", lpValue   ; LPCWSTR
    , "Ptr", lpFormat   ; CURRENCYFMTW* optional
    , "Ptr", lpCurrencyStr   ; LPWSTR optional, out
    , "Int", cchCurrency   ; INT
    , "Int")   ; return: INT
●GetCurrencyFormatW(Locale, dwFlags, lpValue, lpFormat, lpCurrencyStr, cchCurrency) = DLL("KERNEL32.dll", "int GetCurrencyFormatW(dword, dword, char*, void*, char*, int)")
# 呼び出し: GetCurrencyFormatW(Locale, dwFlags, lpValue, lpFormat, lpCurrencyStr, cchCurrency)
# Locale : DWORD -> "dword"
# 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)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。