StrToIntExW
関数進数指定に応じて文字列を整数に変換する。
シグネチャ
// SHLWAPI.dll (Unicode / -W)
#include <windows.h>
BOOL StrToIntExW(
LPCWSTR pszString,
INT dwFlags,
INT* piRet
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pszString | LPCWSTR | in |
| dwFlags | INT | in |
| piRet | INT* | out |
戻り値の型: BOOL
各言語での呼び出し定義
// SHLWAPI.dll (Unicode / -W)
#include <windows.h>
BOOL StrToIntExW(
LPCWSTR pszString,
INT dwFlags,
INT* piRet
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool StrToIntExW(
[MarshalAs(UnmanagedType.LPWStr)] string pszString, // LPCWSTR
int dwFlags, // INT
out int piRet // INT* out
);<DllImport("SHLWAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function StrToIntExW(
<MarshalAs(UnmanagedType.LPWStr)> pszString As String, ' LPCWSTR
dwFlags As Integer, ' INT
<Out> ByRef piRet As Integer ' INT* out
) As Boolean
End Function' pszString : LPCWSTR
' dwFlags : INT
' piRet : INT* out
Declare PtrSafe Function StrToIntExW Lib "shlwapi" ( _
ByVal pszString As LongPtr, _
ByVal dwFlags As Long, _
ByRef piRet 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
StrToIntExW = ctypes.windll.shlwapi.StrToIntExW
StrToIntExW.restype = wintypes.BOOL
StrToIntExW.argtypes = [
wintypes.LPCWSTR, # pszString : LPCWSTR
ctypes.c_int, # dwFlags : INT
ctypes.POINTER(ctypes.c_int), # piRet : INT* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHLWAPI.dll')
StrToIntExW = Fiddle::Function.new(
lib['StrToIntExW'],
[
Fiddle::TYPE_VOIDP, # pszString : LPCWSTR
Fiddle::TYPE_INT, # dwFlags : INT
Fiddle::TYPE_VOIDP, # piRet : INT* out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "shlwapi")]
extern "system" {
fn StrToIntExW(
pszString: *const u16, // LPCWSTR
dwFlags: i32, // INT
piRet: *mut i32 // INT* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode)]
public static extern bool StrToIntExW([MarshalAs(UnmanagedType.LPWStr)] string pszString, int dwFlags, out int piRet);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_StrToIntExW' -Namespace Win32 -PassThru
# $api::StrToIntExW(pszString, dwFlags, piRet)#uselib "SHLWAPI.dll"
#func global StrToIntExW "StrToIntExW" wptr, wptr, wptr
; StrToIntExW pszString, dwFlags, varptr(piRet) ; 戻り値は stat
; pszString : LPCWSTR -> "wptr"
; dwFlags : INT -> "wptr"
; piRet : INT* out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SHLWAPI.dll" #cfunc global StrToIntExW "StrToIntExW" wstr, int, var ; res = StrToIntExW(pszString, dwFlags, piRet) ; pszString : LPCWSTR -> "wstr" ; dwFlags : INT -> "int" ; piRet : INT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHLWAPI.dll" #cfunc global StrToIntExW "StrToIntExW" wstr, int, sptr ; res = StrToIntExW(pszString, dwFlags, varptr(piRet)) ; pszString : LPCWSTR -> "wstr" ; dwFlags : INT -> "int" ; piRet : INT* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL StrToIntExW(LPCWSTR pszString, INT dwFlags, INT* piRet) #uselib "SHLWAPI.dll" #cfunc global StrToIntExW "StrToIntExW" wstr, int, var ; res = StrToIntExW(pszString, dwFlags, piRet) ; pszString : LPCWSTR -> "wstr" ; dwFlags : INT -> "int" ; piRet : INT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL StrToIntExW(LPCWSTR pszString, INT dwFlags, INT* piRet) #uselib "SHLWAPI.dll" #cfunc global StrToIntExW "StrToIntExW" wstr, int, intptr ; res = StrToIntExW(pszString, dwFlags, varptr(piRet)) ; pszString : LPCWSTR -> "wstr" ; dwFlags : INT -> "int" ; piRet : INT* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
procStrToIntExW = shlwapi.NewProc("StrToIntExW")
)
// pszString (LPCWSTR), dwFlags (INT), piRet (INT* out)
r1, _, err := procStrToIntExW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszString))),
uintptr(dwFlags),
uintptr(piRet),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction StrToIntExW(
pszString: PWideChar; // LPCWSTR
dwFlags: Integer; // INT
piRet: Pointer // INT* out
): BOOL; stdcall;
external 'SHLWAPI.dll' name 'StrToIntExW';result := DllCall("SHLWAPI\StrToIntExW"
, "WStr", pszString ; LPCWSTR
, "Int", dwFlags ; INT
, "Ptr", piRet ; INT* out
, "Int") ; return: BOOL●StrToIntExW(pszString, dwFlags, piRet) = DLL("SHLWAPI.dll", "bool StrToIntExW(char*, int, void*)")
# 呼び出し: StrToIntExW(pszString, dwFlags, piRet)
# pszString : LPCWSTR -> "char*"
# dwFlags : INT -> "int"
# piRet : INT* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。