ホーム › UI.Controls.Dialogs › GetFileTitleW
GetFileTitleW
関数パスからファイルタイトル部分を取り出す(Unicode版)。
シグネチャ
// COMDLG32.dll (Unicode / -W)
#include <windows.h>
SHORT GetFileTitleW(
LPCWSTR param0,
LPWSTR Buf,
WORD cchSize
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| param0 | LPCWSTR | in |
| Buf | LPWSTR | out |
| cchSize | WORD | in |
戻り値の型: SHORT
各言語での呼び出し定義
// COMDLG32.dll (Unicode / -W)
#include <windows.h>
SHORT GetFileTitleW(
LPCWSTR param0,
LPWSTR Buf,
WORD cchSize
);[DllImport("COMDLG32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern short GetFileTitleW(
[MarshalAs(UnmanagedType.LPWStr)] string param0, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder Buf, // LPWSTR out
ushort cchSize // WORD
);<DllImport("COMDLG32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function GetFileTitleW(
<MarshalAs(UnmanagedType.LPWStr)> param0 As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> Buf As System.Text.StringBuilder, ' LPWSTR out
cchSize As UShort ' WORD
) As Short
End Function' param0 : LPCWSTR
' Buf : LPWSTR out
' cchSize : WORD
Declare PtrSafe Function GetFileTitleW Lib "comdlg32" ( _
ByVal param0 As LongPtr, _
ByVal Buf As LongPtr, _
ByVal cchSize As Integer) As Integer
' 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
GetFileTitleW = ctypes.windll.comdlg32.GetFileTitleW
GetFileTitleW.restype = ctypes.c_short
GetFileTitleW.argtypes = [
wintypes.LPCWSTR, # param0 : LPCWSTR
wintypes.LPWSTR, # Buf : LPWSTR out
ctypes.c_ushort, # cchSize : WORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('COMDLG32.dll')
GetFileTitleW = Fiddle::Function.new(
lib['GetFileTitleW'],
[
Fiddle::TYPE_VOIDP, # param0 : LPCWSTR
Fiddle::TYPE_VOIDP, # Buf : LPWSTR out
-Fiddle::TYPE_SHORT, # cchSize : WORD
],
Fiddle::TYPE_SHORT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "comdlg32")]
extern "system" {
fn GetFileTitleW(
param0: *const u16, // LPCWSTR
Buf: *mut u16, // LPWSTR out
cchSize: u16 // WORD
) -> i16;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("COMDLG32.dll", CharSet = CharSet.Unicode)]
public static extern short GetFileTitleW([MarshalAs(UnmanagedType.LPWStr)] string param0, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder Buf, ushort cchSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'COMDLG32_GetFileTitleW' -Namespace Win32 -PassThru
# $api::GetFileTitleW(param0, Buf, cchSize)#uselib "COMDLG32.dll"
#func global GetFileTitleW "GetFileTitleW" wptr, wptr, wptr
; GetFileTitleW param0, varptr(Buf), cchSize ; 戻り値は stat
; param0 : LPCWSTR -> "wptr"
; Buf : LPWSTR out -> "wptr"
; cchSize : WORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "COMDLG32.dll" #cfunc global GetFileTitleW "GetFileTitleW" wstr, var, int ; res = GetFileTitleW(param0, Buf, cchSize) ; param0 : LPCWSTR -> "wstr" ; Buf : LPWSTR out -> "var" ; cchSize : WORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "COMDLG32.dll" #cfunc global GetFileTitleW "GetFileTitleW" wstr, sptr, int ; res = GetFileTitleW(param0, varptr(Buf), cchSize) ; param0 : LPCWSTR -> "wstr" ; Buf : LPWSTR out -> "sptr" ; cchSize : WORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; SHORT GetFileTitleW(LPCWSTR param0, LPWSTR Buf, WORD cchSize) #uselib "COMDLG32.dll" #cfunc global GetFileTitleW "GetFileTitleW" wstr, var, int ; res = GetFileTitleW(param0, Buf, cchSize) ; param0 : LPCWSTR -> "wstr" ; Buf : LPWSTR out -> "var" ; cchSize : WORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; SHORT GetFileTitleW(LPCWSTR param0, LPWSTR Buf, WORD cchSize) #uselib "COMDLG32.dll" #cfunc global GetFileTitleW "GetFileTitleW" wstr, intptr, int ; res = GetFileTitleW(param0, varptr(Buf), cchSize) ; param0 : LPCWSTR -> "wstr" ; Buf : LPWSTR out -> "intptr" ; cchSize : WORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
comdlg32 = windows.NewLazySystemDLL("COMDLG32.dll")
procGetFileTitleW = comdlg32.NewProc("GetFileTitleW")
)
// param0 (LPCWSTR), Buf (LPWSTR out), cchSize (WORD)
r1, _, err := procGetFileTitleW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(param0))),
uintptr(Buf),
uintptr(cchSize),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // SHORTfunction GetFileTitleW(
param0: PWideChar; // LPCWSTR
Buf: PWideChar; // LPWSTR out
cchSize: Word // WORD
): Smallint; stdcall;
external 'COMDLG32.dll' name 'GetFileTitleW';result := DllCall("COMDLG32\GetFileTitleW"
, "WStr", param0 ; LPCWSTR
, "Ptr", Buf ; LPWSTR out
, "UShort", cchSize ; WORD
, "Short") ; return: SHORT●GetFileTitleW(param0, Buf, cchSize) = DLL("COMDLG32.dll", "int GetFileTitleW(char*, char*, int)")
# 呼び出し: GetFileTitleW(param0, Buf, cchSize)
# param0 : LPCWSTR -> "char*"
# Buf : LPWSTR out -> "char*"
# cchSize : WORD -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。