ホーム › Globalization › GetCurrencyFormatA
GetCurrencyFormatA
関数指定ロケールに従い通貨を文字列へ整形する。ANSI版。
シグネチャ
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
INT GetCurrencyFormatA(
DWORD Locale,
DWORD dwFlags,
LPCSTR lpValue,
const CURRENCYFMTA* lpFormat, // optional
LPSTR lpCurrencyStr, // optional
INT cchCurrency
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| Locale | DWORD | in |
| dwFlags | DWORD | in |
| lpValue | LPCSTR | in |
| lpFormat | CURRENCYFMTA* | inoptional |
| lpCurrencyStr | LPSTR | outoptional |
| cchCurrency | INT | in |
戻り値の型: INT
各言語での呼び出し定義
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
INT GetCurrencyFormatA(
DWORD Locale,
DWORD dwFlags,
LPCSTR lpValue,
const CURRENCYFMTA* lpFormat, // optional
LPSTR lpCurrencyStr, // optional
INT cchCurrency
);[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern int GetCurrencyFormatA(
uint Locale, // DWORD
uint dwFlags, // DWORD
[MarshalAs(UnmanagedType.LPStr)] string lpValue, // LPCSTR
IntPtr lpFormat, // CURRENCYFMTA* optional
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpCurrencyStr, // LPSTR optional, out
int cchCurrency // INT
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetCurrencyFormatA(
Locale As UInteger, ' DWORD
dwFlags As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPStr)> lpValue As String, ' LPCSTR
lpFormat As IntPtr, ' CURRENCYFMTA* optional
<MarshalAs(UnmanagedType.LPStr)> lpCurrencyStr As System.Text.StringBuilder, ' LPSTR optional, out
cchCurrency As Integer ' INT
) As Integer
End Function' Locale : DWORD
' dwFlags : DWORD
' lpValue : LPCSTR
' lpFormat : CURRENCYFMTA* optional
' lpCurrencyStr : LPSTR optional, out
' cchCurrency : INT
Declare PtrSafe Function GetCurrencyFormatA Lib "kernel32" ( _
ByVal Locale As Long, _
ByVal dwFlags As Long, _
ByVal lpValue As String, _
ByVal lpFormat As LongPtr, _
ByVal lpCurrencyStr As String, _
ByVal cchCurrency As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetCurrencyFormatA = ctypes.windll.kernel32.GetCurrencyFormatA
GetCurrencyFormatA.restype = ctypes.c_int
GetCurrencyFormatA.argtypes = [
wintypes.DWORD, # Locale : DWORD
wintypes.DWORD, # dwFlags : DWORD
wintypes.LPCSTR, # lpValue : LPCSTR
ctypes.c_void_p, # lpFormat : CURRENCYFMTA* optional
wintypes.LPSTR, # lpCurrencyStr : LPSTR 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')
GetCurrencyFormatA = Fiddle::Function.new(
lib['GetCurrencyFormatA'],
[
-Fiddle::TYPE_INT, # Locale : DWORD
-Fiddle::TYPE_INT, # dwFlags : DWORD
Fiddle::TYPE_VOIDP, # lpValue : LPCSTR
Fiddle::TYPE_VOIDP, # lpFormat : CURRENCYFMTA* optional
Fiddle::TYPE_VOIDP, # lpCurrencyStr : LPSTR optional, out
Fiddle::TYPE_INT, # cchCurrency : INT
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn GetCurrencyFormatA(
Locale: u32, // DWORD
dwFlags: u32, // DWORD
lpValue: *const u8, // LPCSTR
lpFormat: *const CURRENCYFMTA, // CURRENCYFMTA* optional
lpCurrencyStr: *mut u8, // LPSTR optional, out
cchCurrency: i32 // INT
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern int GetCurrencyFormatA(uint Locale, uint dwFlags, [MarshalAs(UnmanagedType.LPStr)] string lpValue, IntPtr lpFormat, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpCurrencyStr, int cchCurrency);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetCurrencyFormatA' -Namespace Win32 -PassThru
# $api::GetCurrencyFormatA(Locale, dwFlags, lpValue, lpFormat, lpCurrencyStr, cchCurrency)#uselib "KERNEL32.dll"
#func global GetCurrencyFormatA "GetCurrencyFormatA" sptr, sptr, sptr, sptr, sptr, sptr
; GetCurrencyFormatA Locale, dwFlags, lpValue, varptr(lpFormat), varptr(lpCurrencyStr), cchCurrency ; 戻り値は stat
; Locale : DWORD -> "sptr"
; dwFlags : DWORD -> "sptr"
; lpValue : LPCSTR -> "sptr"
; lpFormat : CURRENCYFMTA* optional -> "sptr"
; lpCurrencyStr : LPSTR optional, out -> "sptr"
; cchCurrency : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global GetCurrencyFormatA "GetCurrencyFormatA" int, int, str, var, var, int ; res = GetCurrencyFormatA(Locale, dwFlags, lpValue, lpFormat, lpCurrencyStr, cchCurrency) ; Locale : DWORD -> "int" ; dwFlags : DWORD -> "int" ; lpValue : LPCSTR -> "str" ; lpFormat : CURRENCYFMTA* optional -> "var" ; lpCurrencyStr : LPSTR optional, out -> "var" ; cchCurrency : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global GetCurrencyFormatA "GetCurrencyFormatA" int, int, str, sptr, sptr, int ; res = GetCurrencyFormatA(Locale, dwFlags, lpValue, varptr(lpFormat), varptr(lpCurrencyStr), cchCurrency) ; Locale : DWORD -> "int" ; dwFlags : DWORD -> "int" ; lpValue : LPCSTR -> "str" ; lpFormat : CURRENCYFMTA* optional -> "sptr" ; lpCurrencyStr : LPSTR optional, out -> "sptr" ; cchCurrency : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT GetCurrencyFormatA(DWORD Locale, DWORD dwFlags, LPCSTR lpValue, CURRENCYFMTA* lpFormat, LPSTR lpCurrencyStr, INT cchCurrency) #uselib "KERNEL32.dll" #cfunc global GetCurrencyFormatA "GetCurrencyFormatA" int, int, str, var, var, int ; res = GetCurrencyFormatA(Locale, dwFlags, lpValue, lpFormat, lpCurrencyStr, cchCurrency) ; Locale : DWORD -> "int" ; dwFlags : DWORD -> "int" ; lpValue : LPCSTR -> "str" ; lpFormat : CURRENCYFMTA* optional -> "var" ; lpCurrencyStr : LPSTR optional, out -> "var" ; cchCurrency : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT GetCurrencyFormatA(DWORD Locale, DWORD dwFlags, LPCSTR lpValue, CURRENCYFMTA* lpFormat, LPSTR lpCurrencyStr, INT cchCurrency) #uselib "KERNEL32.dll" #cfunc global GetCurrencyFormatA "GetCurrencyFormatA" int, int, str, intptr, intptr, int ; res = GetCurrencyFormatA(Locale, dwFlags, lpValue, varptr(lpFormat), varptr(lpCurrencyStr), cchCurrency) ; Locale : DWORD -> "int" ; dwFlags : DWORD -> "int" ; lpValue : LPCSTR -> "str" ; lpFormat : CURRENCYFMTA* optional -> "intptr" ; lpCurrencyStr : LPSTR optional, out -> "intptr" ; cchCurrency : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procGetCurrencyFormatA = kernel32.NewProc("GetCurrencyFormatA")
)
// Locale (DWORD), dwFlags (DWORD), lpValue (LPCSTR), lpFormat (CURRENCYFMTA* optional), lpCurrencyStr (LPSTR optional, out), cchCurrency (INT)
r1, _, err := procGetCurrencyFormatA.Call(
uintptr(Locale),
uintptr(dwFlags),
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpValue))),
uintptr(lpFormat),
uintptr(lpCurrencyStr),
uintptr(cchCurrency),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction GetCurrencyFormatA(
Locale: DWORD; // DWORD
dwFlags: DWORD; // DWORD
lpValue: PAnsiChar; // LPCSTR
lpFormat: Pointer; // CURRENCYFMTA* optional
lpCurrencyStr: PAnsiChar; // LPSTR optional, out
cchCurrency: Integer // INT
): Integer; stdcall;
external 'KERNEL32.dll' name 'GetCurrencyFormatA';result := DllCall("KERNEL32\GetCurrencyFormatA"
, "UInt", Locale ; DWORD
, "UInt", dwFlags ; DWORD
, "AStr", lpValue ; LPCSTR
, "Ptr", lpFormat ; CURRENCYFMTA* optional
, "Ptr", lpCurrencyStr ; LPSTR optional, out
, "Int", cchCurrency ; INT
, "Int") ; return: INT●GetCurrencyFormatA(Locale, dwFlags, lpValue, lpFormat, lpCurrencyStr, cchCurrency) = DLL("KERNEL32.dll", "int GetCurrencyFormatA(dword, dword, char*, void*, char*, int)")
# 呼び出し: GetCurrencyFormatA(Locale, dwFlags, lpValue, lpFormat, lpCurrencyStr, cchCurrency)
# Locale : DWORD -> "dword"
# dwFlags : DWORD -> "dword"
# lpValue : LPCSTR -> "char*"
# lpFormat : CURRENCYFMTA* optional -> "void*"
# lpCurrencyStr : LPSTR optional, out -> "char*"
# cchCurrency : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。