Win32 API 日本語リファレンス
ホームUI.Shell › PathCchFindExtension

PathCchFindExtension

関数
パス内の拡張子位置を検索して返す。
DLLapi-ms-win-core-path-l1-1-0.dll呼出規約winapi対応OSwindows8.0

シグネチャ

// api-ms-win-core-path-l1-1-0.dll
#include <windows.h>

HRESULT PathCchFindExtension(
    LPCWSTR pszPath,
    UINT_PTR cchPath,
    LPCWSTR* ppszExt
);

パラメーター

名前方向
pszPathLPCWSTRin
cchPathUINT_PTRin
ppszExtLPCWSTR*out

戻り値の型: HRESULT

各言語での呼び出し定義

// api-ms-win-core-path-l1-1-0.dll
#include <windows.h>

HRESULT PathCchFindExtension(
    LPCWSTR pszPath,
    UINT_PTR cchPath,
    LPCWSTR* ppszExt
);
[DllImport("api-ms-win-core-path-l1-1-0.dll", ExactSpelling = true)]
static extern int PathCchFindExtension(
    [MarshalAs(UnmanagedType.LPWStr)] string pszPath,   // LPCWSTR
    UIntPtr cchPath,   // UINT_PTR
    IntPtr ppszExt   // LPCWSTR* out
);
<DllImport("api-ms-win-core-path-l1-1-0.dll", ExactSpelling:=True)>
Public Shared Function PathCchFindExtension(
    <MarshalAs(UnmanagedType.LPWStr)> pszPath As String,   ' LPCWSTR
    cchPath As UIntPtr,   ' UINT_PTR
    ppszExt As IntPtr   ' LPCWSTR* out
) As Integer
End Function
' pszPath : LPCWSTR
' cchPath : UINT_PTR
' ppszExt : LPCWSTR* out
Declare PtrSafe Function PathCchFindExtension Lib "api-ms-win-core-path-l1-1-0" ( _
    ByVal pszPath As LongPtr, _
    ByVal cchPath As LongPtr, _
    ByVal ppszExt As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

PathCchFindExtension = ctypes.windll.LoadLibrary("api-ms-win-core-path-l1-1-0.dll").PathCchFindExtension
PathCchFindExtension.restype = ctypes.c_int
PathCchFindExtension.argtypes = [
    wintypes.LPCWSTR,  # pszPath : LPCWSTR
    ctypes.c_size_t,  # cchPath : UINT_PTR
    ctypes.c_void_p,  # ppszExt : LPCWSTR* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('api-ms-win-core-path-l1-1-0.dll')
PathCchFindExtension = Fiddle::Function.new(
  lib['PathCchFindExtension'],
  [
    Fiddle::TYPE_VOIDP,  # pszPath : LPCWSTR
    Fiddle::TYPE_UINTPTR_T,  # cchPath : UINT_PTR
    Fiddle::TYPE_VOIDP,  # ppszExt : LPCWSTR* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "api-ms-win-core-path-l1-1-0")]
extern "system" {
    fn PathCchFindExtension(
        pszPath: *const u16,  // LPCWSTR
        cchPath: usize,  // UINT_PTR
        ppszExt: *const *const u16  // LPCWSTR* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("api-ms-win-core-path-l1-1-0.dll")]
public static extern int PathCchFindExtension([MarshalAs(UnmanagedType.LPWStr)] string pszPath, UIntPtr cchPath, IntPtr ppszExt);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-core-path-l1-1-0_PathCchFindExtension' -Namespace Win32 -PassThru
# $api::PathCchFindExtension(pszPath, cchPath, ppszExt)
#uselib "api-ms-win-core-path-l1-1-0.dll"
#func global PathCchFindExtension "PathCchFindExtension" sptr, sptr, sptr
; PathCchFindExtension pszPath, cchPath, varptr(ppszExt)   ; 戻り値は stat
; pszPath : LPCWSTR -> "sptr"
; cchPath : UINT_PTR -> "sptr"
; ppszExt : LPCWSTR* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "api-ms-win-core-path-l1-1-0.dll"
#cfunc global PathCchFindExtension "PathCchFindExtension" wstr, sptr, var
; res = PathCchFindExtension(pszPath, cchPath, ppszExt)
; pszPath : LPCWSTR -> "wstr"
; cchPath : UINT_PTR -> "sptr"
; ppszExt : LPCWSTR* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT PathCchFindExtension(LPCWSTR pszPath, UINT_PTR cchPath, LPCWSTR* ppszExt)
#uselib "api-ms-win-core-path-l1-1-0.dll"
#cfunc global PathCchFindExtension "PathCchFindExtension" wstr, intptr, var
; res = PathCchFindExtension(pszPath, cchPath, ppszExt)
; pszPath : LPCWSTR -> "wstr"
; cchPath : UINT_PTR -> "intptr"
; ppszExt : LPCWSTR* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	api_ms_win_core_path_l1_1_0 = windows.NewLazySystemDLL("api-ms-win-core-path-l1-1-0.dll")
	procPathCchFindExtension = api_ms_win_core_path_l1_1_0.NewProc("PathCchFindExtension")
)

// pszPath (LPCWSTR), cchPath (UINT_PTR), ppszExt (LPCWSTR* out)
r1, _, err := procPathCchFindExtension.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszPath))),
	uintptr(cchPath),
	uintptr(ppszExt),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function PathCchFindExtension(
  pszPath: PWideChar;   // LPCWSTR
  cchPath: NativeUInt;   // UINT_PTR
  ppszExt: PPWideChar   // LPCWSTR* out
): Integer; stdcall;
  external 'api-ms-win-core-path-l1-1-0.dll' name 'PathCchFindExtension';
result := DllCall("api-ms-win-core-path-l1-1-0\PathCchFindExtension"
    , "WStr", pszPath   ; LPCWSTR
    , "UPtr", cchPath   ; UINT_PTR
    , "Ptr", ppszExt   ; LPCWSTR* out
    , "Int")   ; return: HRESULT
●PathCchFindExtension(pszPath, cchPath, ppszExt) = DLL("api-ms-win-core-path-l1-1-0.dll", "int PathCchFindExtension(char*, int, void*)")
# 呼び出し: PathCchFindExtension(pszPath, cchPath, ppszExt)
# pszPath : LPCWSTR -> "char*"
# cchPath : UINT_PTR -> "int"
# ppszExt : LPCWSTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。