Win32 API 日本語リファレンス
ホームUI.Controls.Dialogs › GetFileTitleA

GetFileTitleA

関数
パスからファイルタイトル部分を取り出す(ANSI版)。
DLLCOMDLG32.dll文字セットANSI (-A)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// COMDLG32.dll  (ANSI / -A)
#include <windows.h>

SHORT GetFileTitleA(
    LPCSTR param0,
    LPSTR Buf,
    WORD cchSize
);

パラメーター

名前方向
param0LPCSTRin
BufLPSTRout
cchSizeWORDin

戻り値の型: SHORT

各言語での呼び出し定義

// COMDLG32.dll  (ANSI / -A)
#include <windows.h>

SHORT GetFileTitleA(
    LPCSTR param0,
    LPSTR Buf,
    WORD cchSize
);
[DllImport("COMDLG32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern short GetFileTitleA(
    [MarshalAs(UnmanagedType.LPStr)] string param0,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder Buf,   // LPSTR out
    ushort cchSize   // WORD
);
<DllImport("COMDLG32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function GetFileTitleA(
    <MarshalAs(UnmanagedType.LPStr)> param0 As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> Buf As System.Text.StringBuilder,   ' LPSTR out
    cchSize As UShort   ' WORD
) As Short
End Function
' param0 : LPCSTR
' Buf : LPSTR out
' cchSize : WORD
Declare PtrSafe Function GetFileTitleA Lib "comdlg32" ( _
    ByVal param0 As String, _
    ByVal Buf As String, _
    ByVal cchSize As Integer) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetFileTitleA = ctypes.windll.comdlg32.GetFileTitleA
GetFileTitleA.restype = ctypes.c_short
GetFileTitleA.argtypes = [
    wintypes.LPCSTR,  # param0 : LPCSTR
    wintypes.LPSTR,  # Buf : LPSTR out
    ctypes.c_ushort,  # cchSize : WORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('COMDLG32.dll')
GetFileTitleA = Fiddle::Function.new(
  lib['GetFileTitleA'],
  [
    Fiddle::TYPE_VOIDP,  # param0 : LPCSTR
    Fiddle::TYPE_VOIDP,  # Buf : LPSTR out
    -Fiddle::TYPE_SHORT,  # cchSize : WORD
  ],
  Fiddle::TYPE_SHORT)
#[link(name = "comdlg32")]
extern "system" {
    fn GetFileTitleA(
        param0: *const u8,  // LPCSTR
        Buf: *mut u8,  // LPSTR out
        cchSize: u16  // WORD
    ) -> i16;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("COMDLG32.dll", CharSet = CharSet.Ansi)]
public static extern short GetFileTitleA([MarshalAs(UnmanagedType.LPStr)] string param0, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder Buf, ushort cchSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'COMDLG32_GetFileTitleA' -Namespace Win32 -PassThru
# $api::GetFileTitleA(param0, Buf, cchSize)
#uselib "COMDLG32.dll"
#func global GetFileTitleA "GetFileTitleA" sptr, sptr, sptr
; GetFileTitleA param0, varptr(Buf), cchSize   ; 戻り値は stat
; param0 : LPCSTR -> "sptr"
; Buf : LPSTR out -> "sptr"
; cchSize : WORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "COMDLG32.dll"
#cfunc global GetFileTitleA "GetFileTitleA" str, var, int
; res = GetFileTitleA(param0, Buf, cchSize)
; param0 : LPCSTR -> "str"
; Buf : LPSTR out -> "var"
; cchSize : WORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; SHORT GetFileTitleA(LPCSTR param0, LPSTR Buf, WORD cchSize)
#uselib "COMDLG32.dll"
#cfunc global GetFileTitleA "GetFileTitleA" str, var, int
; res = GetFileTitleA(param0, Buf, cchSize)
; param0 : LPCSTR -> "str"
; Buf : LPSTR out -> "var"
; cchSize : WORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	comdlg32 = windows.NewLazySystemDLL("COMDLG32.dll")
	procGetFileTitleA = comdlg32.NewProc("GetFileTitleA")
)

// param0 (LPCSTR), Buf (LPSTR out), cchSize (WORD)
r1, _, err := procGetFileTitleA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(param0))),
	uintptr(Buf),
	uintptr(cchSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // SHORT
function GetFileTitleA(
  param0: PAnsiChar;   // LPCSTR
  Buf: PAnsiChar;   // LPSTR out
  cchSize: Word   // WORD
): Smallint; stdcall;
  external 'COMDLG32.dll' name 'GetFileTitleA';
result := DllCall("COMDLG32\GetFileTitleA"
    , "AStr", param0   ; LPCSTR
    , "Ptr", Buf   ; LPSTR out
    , "UShort", cchSize   ; WORD
    , "Short")   ; return: SHORT
●GetFileTitleA(param0, Buf, cchSize) = DLL("COMDLG32.dll", "int GetFileTitleA(char*, char*, int)")
# 呼び出し: GetFileTitleA(param0, Buf, cchSize)
# param0 : LPCSTR -> "char*"
# Buf : LPSTR out -> "char*"
# cchSize : WORD -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。