GetCurrencyFormatEx
関数シグネチャ
// KERNEL32.dll
#include <windows.h>
INT GetCurrencyFormatEx(
LPCWSTR lpLocaleName, // optional
DWORD dwFlags,
LPCWSTR lpValue,
const CURRENCYFMTW* lpFormat, // optional
LPWSTR lpCurrencyStr, // optional
INT cchCurrency
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lpLocaleName | LPCWSTR | inoptional | ロケール名、または以下の定義済みの値のいずれかへのポインターです。 |
| dwFlags | DWORD | in | 関数の動作を制御するフラグです。lpFormat が NULL に設定されていない場合、アプリケーションはこのパラメーターを 0 に設定する必要があります。この場合、関数はロケールの既定の通貨フォーマットに対するユーザーのオーバーライドを使用して文字列をフォーマットします。lpFormat が NULL に設定されている場合、アプリケーションは LOCALE_NOUSEROVERRIDE を指定して、指定したロケールのシステム既定の通貨フォーマットを使用して文字列をフォーマットできます。 注意 LOCALE_NOUSEROVERRIDE はユーザー設定を無効にするため、使用は強く推奨されません。
|
| lpValue | LPCWSTR | in | フォーマットする数値文字列を格納した、null で終わる文字列へのポインターです。この文字列には以下の文字のみを含めることができます。それ以外の文字はすべて無効です。文字列がこれらの規則から外れている場合、関数はエラーを返します。
|
| lpFormat | CURRENCYFMTW* | inoptional | 通貨フォーマット情報を格納した CURRENCYFMT 構造体へのポインターです。構造体のすべてのメンバーに適切な値が格納されている必要があります。指定したロケールの通貨フォーマットを使用する場合、アプリケーションはこのパラメーターを NULL に設定できます。このパラメーターが NULL に設定されていない場合、関数は CURRENCYFMT 構造体で指定されていないフォーマット情報(たとえば、ロケールで使用される負符号の文字列値)に対してのみ、指定したロケールを使用します。 |
| lpCurrencyStr | LPWSTR | outoptional | この関数がフォーマット済みの通貨文字列を取得するバッファーへのポインターです。 |
| cchCurrency | INT | in | lpCurrencyStr バッファーのサイズ(文字数)です。アプリケーションはこのパラメーターを 0 に設定して、フォーマット済みの通貨文字列を格納するために必要なバッファーのサイズを返すことができます。この場合、lpCurrencyStr で示されるバッファーは使用されません。 |
戻り値の型: INT
公式ドキュメント
名前で指定されたロケールに対して、数値文字列を通貨文字列としてフォーマットします。注意 Windows Vista 以降でのみ動作するように設計されている場合、アプリケーションは GetCurrencyFormat ではなくこの関数を優先して呼び出してください。 注意 この関数は、カスタムロケールなどによってリリース間で変化するデータをフォーマットすることがあります。アプリケーションがデータを永続化または送信する必要がある場合は、「Using Persistent Locale Data」を参照してください。
戻り値
成功した場合、lpCurrencyStr で示されるバッファーに取得された文字数を返します。cchCurrency パラメーターが 0 の場合、関数は終端の null 文字を含む、フォーマット済みの通貨文字列を格納するために必要なバッファーのサイズを返します。
成功しなかった場合、関数は 0 を返します。拡張エラー情報を取得するために、アプリケーションは GetLastError を呼び出すことができます。これは以下のいずれかのエラーコードを返すことがあります。
- ERROR_INSUFFICIENT_BUFFER。指定されたバッファーサイズが十分な大きさではなかったか、誤って NULL に設定されていました。
- ERROR_INVALID_FLAGS。フラグに指定された値が無効でした。
- ERROR_INVALID_PARAMETER。いずれかのパラメーター値が無効でした。
解説(Remarks)
Windows 8 以降: アプリが Windows.Globalization 名前空間からこの関数に言語タグを渡す場合は、まず ResolveLocaleName を呼び出してタグを変換する必要があります。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global GetCurrencyFormatEx "GetCurrencyFormatEx" wstr, int, wstr, sptr, sptr, int ; res = GetCurrencyFormatEx(lpLocaleName, dwFlags, lpValue, varptr(lpFormat), varptr(lpCurrencyStr), cchCurrency) ; lpLocaleName : LPCWSTR optional -> "wstr" ; dwFlags : DWORD -> "int" ; lpValue : LPCWSTR -> "wstr" ; lpFormat : CURRENCYFMTW* optional -> "sptr" ; lpCurrencyStr : LPWSTR optional, out -> "sptr" ; cchCurrency : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; INT GetCurrencyFormatEx(LPCWSTR lpLocaleName, DWORD dwFlags, LPCWSTR lpValue, CURRENCYFMTW* lpFormat, LPWSTR lpCurrencyStr, INT cchCurrency) #uselib "KERNEL32.dll" #cfunc global GetCurrencyFormatEx "GetCurrencyFormatEx" wstr, int, wstr, intptr, intptr, int ; res = GetCurrencyFormatEx(lpLocaleName, dwFlags, lpValue, varptr(lpFormat), varptr(lpCurrencyStr), cchCurrency) ; lpLocaleName : LPCWSTR optional -> "wstr" ; dwFlags : DWORD -> "int" ; lpValue : LPCWSTR -> "wstr" ; lpFormat : CURRENCYFMTW* optional -> "intptr" ; lpCurrencyStr : LPWSTR optional, out -> "intptr" ; cchCurrency : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // INTfunction 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)。const std = @import("std");
extern "kernel32" fn GetCurrencyFormatEx(
lpLocaleName: [*c]const u16, // LPCWSTR optional
dwFlags: u32, // DWORD
lpValue: [*c]const u16, // LPCWSTR
lpFormat: [*c]CURRENCYFMTW, // CURRENCYFMTW* optional
lpCurrencyStr: [*c]u16, // LPWSTR optional, out
cchCurrency: i32 // INT
) callconv(std.os.windows.WINAPI) i32;proc GetCurrencyFormatEx(
lpLocaleName: WideCString, # LPCWSTR optional
dwFlags: uint32, # DWORD
lpValue: WideCString, # LPCWSTR
lpFormat: ptr CURRENCYFMTW, # CURRENCYFMTW* optional
lpCurrencyStr: ptr uint16, # LPWSTR optional, out
cchCurrency: int32 # INT
): int32 {.importc: "GetCurrencyFormatEx", stdcall, dynlib: "KERNEL32.dll".}pragma(lib, "kernel32");
extern(Windows)
int GetCurrencyFormatEx(
const(wchar)* lpLocaleName, // LPCWSTR optional
uint dwFlags, // DWORD
const(wchar)* lpValue, // LPCWSTR
CURRENCYFMTW* lpFormat, // CURRENCYFMTW* optional
wchar* lpCurrencyStr, // LPWSTR optional, out
int cchCurrency // INT
);ccall((:GetCurrencyFormatEx, "KERNEL32.dll"), stdcall, Int32,
(Cwstring, UInt32, Cwstring, Ptr{CURRENCYFMTW}, Ptr{UInt16}, Int32),
lpLocaleName, dwFlags, lpValue, lpFormat, lpCurrencyStr, cchCurrency)
# lpLocaleName : LPCWSTR optional -> Cwstring
# dwFlags : DWORD -> UInt32
# lpValue : LPCWSTR -> Cwstring
# lpFormat : CURRENCYFMTW* optional -> Ptr{CURRENCYFMTW}
# lpCurrencyStr : LPWSTR optional, out -> Ptr{UInt16}
# cchCurrency : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GetCurrencyFormatEx(
const uint16_t* lpLocaleName,
uint32_t dwFlags,
const uint16_t* lpValue,
void* lpFormat,
uint16_t* lpCurrencyStr,
int32_t cchCurrency);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.GetCurrencyFormatEx(lpLocaleName, dwFlags, lpValue, lpFormat, lpCurrencyStr, cchCurrency)
-- lpLocaleName : LPCWSTR optional
-- dwFlags : DWORD
-- lpValue : LPCWSTR
-- lpFormat : CURRENCYFMTW* optional
-- lpCurrencyStr : LPWSTR optional, out
-- cchCurrency : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const GetCurrencyFormatEx = lib.func('__stdcall', 'GetCurrencyFormatEx', 'int32_t', ['str16', 'uint32_t', 'str16', 'void *', 'uint16_t *', 'int32_t']);
// GetCurrencyFormatEx(lpLocaleName, dwFlags, lpValue, lpFormat, lpCurrencyStr, cchCurrency)
// lpLocaleName : LPCWSTR optional -> 'str16'
// dwFlags : DWORD -> 'uint32_t'
// lpValue : LPCWSTR -> 'str16'
// lpFormat : CURRENCYFMTW* optional -> 'void *'
// lpCurrencyStr : LPWSTR optional, out -> 'uint16_t *'
// cchCurrency : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
GetCurrencyFormatEx: { parameters: ["buffer", "u32", "buffer", "pointer", "buffer", "i32"], result: "i32" },
});
// lib.symbols.GetCurrencyFormatEx(lpLocaleName, dwFlags, lpValue, lpFormat, lpCurrencyStr, cchCurrency)
// lpLocaleName : LPCWSTR optional -> "buffer"
// dwFlags : DWORD -> "u32"
// lpValue : LPCWSTR -> "buffer"
// lpFormat : CURRENCYFMTW* optional -> "pointer"
// lpCurrencyStr : LPWSTR optional, out -> "buffer"
// cchCurrency : INT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetCurrencyFormatEx(
const uint16_t* lpLocaleName,
uint32_t dwFlags,
const uint16_t* lpValue,
void* lpFormat,
uint16_t* lpCurrencyStr,
int32_t cchCurrency);
C, "KERNEL32.dll");
// $ffi->GetCurrencyFormatEx(lpLocaleName, dwFlags, lpValue, lpFormat, lpCurrencyStr, cchCurrency);
// lpLocaleName : LPCWSTR optional
// dwFlags : DWORD
// lpValue : LPCWSTR
// lpFormat : CURRENCYFMTW* optional
// lpCurrencyStr : LPWSTR optional, out
// cchCurrency : INT
// 構造体/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 Kernel32 extends StdCallLibrary {
Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class);
int GetCurrencyFormatEx(
WString lpLocaleName, // LPCWSTR optional
int dwFlags, // DWORD
WString lpValue, // LPCWSTR
Pointer lpFormat, // CURRENCYFMTW* optional
char[] lpCurrencyStr, // LPWSTR optional, out
int cchCurrency // INT
);
}@[Link("kernel32")]
lib LibKERNEL32
fun GetCurrencyFormatEx = GetCurrencyFormatEx(
lpLocaleName : UInt16*, # LPCWSTR optional
dwFlags : UInt32, # DWORD
lpValue : UInt16*, # LPCWSTR
lpFormat : CURRENCYFMTW*, # CURRENCYFMTW* optional
lpCurrencyStr : UInt16*, # LPWSTR optional, out
cchCurrency : Int32 # INT
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetCurrencyFormatExNative = Int32 Function(Pointer<Utf16>, Uint32, Pointer<Utf16>, Pointer<Void>, Pointer<Utf16>, Int32);
typedef GetCurrencyFormatExDart = int Function(Pointer<Utf16>, int, Pointer<Utf16>, Pointer<Void>, Pointer<Utf16>, int);
final GetCurrencyFormatEx = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<GetCurrencyFormatExNative, GetCurrencyFormatExDart>('GetCurrencyFormatEx');
// lpLocaleName : LPCWSTR optional -> Pointer<Utf16>
// dwFlags : DWORD -> Uint32
// lpValue : LPCWSTR -> Pointer<Utf16>
// lpFormat : CURRENCYFMTW* optional -> Pointer<Void>
// lpCurrencyStr : LPWSTR optional, out -> Pointer<Utf16>
// cchCurrency : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetCurrencyFormatEx"
c_GetCurrencyFormatEx :: CWString -> Word32 -> CWString -> Ptr () -> CWString -> Int32 -> IO Int32
-- lpLocaleName : LPCWSTR optional -> CWString
-- dwFlags : DWORD -> Word32
-- lpValue : LPCWSTR -> CWString
-- lpFormat : CURRENCYFMTW* optional -> Ptr ()
-- lpCurrencyStr : LPWSTR optional, out -> CWString
-- cchCurrency : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getcurrencyformatex =
foreign "GetCurrencyFormatEx"
((ptr uint16_t) @-> uint32_t @-> (ptr uint16_t) @-> (ptr void) @-> (ptr uint16_t) @-> int32_t @-> returning int32_t)
(* lpLocaleName : LPCWSTR optional -> (ptr uint16_t) *)
(* dwFlags : DWORD -> uint32_t *)
(* lpValue : LPCWSTR -> (ptr uint16_t) *)
(* lpFormat : CURRENCYFMTW* optional -> (ptr void) *)
(* lpCurrencyStr : LPWSTR optional, out -> (ptr uint16_t) *)
(* cchCurrency : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("GetCurrencyFormatEx" get-currency-format-ex :convention :stdcall) :int32
(lp-locale-name (:string :encoding :utf-16le)) ; LPCWSTR optional
(dw-flags :uint32) ; DWORD
(lp-value (:string :encoding :utf-16le)) ; LPCWSTR
(lp-format :pointer) ; CURRENCYFMTW* optional
(lp-currency-str :pointer) ; LPWSTR optional, out
(cch-currency :int32)) ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetCurrencyFormatEx = Win32::API::More->new('KERNEL32',
'int GetCurrencyFormatEx(LPCWSTR lpLocaleName, DWORD dwFlags, LPCWSTR lpValue, LPVOID lpFormat, LPWSTR lpCurrencyStr, int cchCurrency)');
# my $ret = $GetCurrencyFormatEx->Call($lpLocaleName, $dwFlags, $lpValue, $lpFormat, $lpCurrencyStr, $cchCurrency);
# lpLocaleName : LPCWSTR optional -> LPCWSTR
# dwFlags : DWORD -> DWORD
# lpValue : LPCWSTR -> LPCWSTR
# lpFormat : CURRENCYFMTW* optional -> LPVOID
# lpCurrencyStr : LPWSTR optional, out -> LPWSTR
# cchCurrency : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f GetCurrencyFormatW — 指定ロケールに従い通貨を文字列へ整形する。Unicode版。
- f GetNumberFormatEx — ロケール名に従って数値を書式付き文字列に整形する。