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_PTRinpszPath が指すバッファーのサイズ。null 終端文字を含む文字数で指定します。
ppszExtLPCWSTR*outこの関数が正常に終了したときに、pszPath 内の拡張子の前にある "." 文字を指すポインターのアドレス。拡張子が見つからない場合は、文字列の終端 null 文字を指します。

戻り値の型: HRESULT

公式ドキュメント

パスを検索し、".exe" や ".ini" などのファイル名拡張子を見つけます。

戻り値

この関数が成功した場合は S_OK を返します。それ以外の場合は HRESULT エラーコードを返します。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// 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)。
const std = @import("std");

extern "api-ms-win-core-path-l1-1-0" fn PathCchFindExtension(
    pszPath: [*c]const u16, // LPCWSTR
    cchPath: usize, // UINT_PTR
    ppszExt: [*c][*c]u16 // LPCWSTR* out
) callconv(std.os.windows.WINAPI) i32;
proc PathCchFindExtension(
    pszPath: WideCString,  # LPCWSTR
    cchPath: uint,  # UINT_PTR
    ppszExt: ptr WideCString  # LPCWSTR* out
): int32 {.importc: "PathCchFindExtension", stdcall, dynlib: "api-ms-win-core-path-l1-1-0.dll".}
pragma(lib, "api-ms-win-core-path-l1-1-0");
extern(Windows)
int PathCchFindExtension(
    const(wchar)* pszPath,   // LPCWSTR
    size_t cchPath,   // UINT_PTR
    wchar** ppszExt   // LPCWSTR* out
);
ccall((:PathCchFindExtension, "api-ms-win-core-path-l1-1-0.dll"), stdcall, Int32,
      (Cwstring, Csize_t, Ptr{Ptr{UInt16}}),
      pszPath, cchPath, ppszExt)
# pszPath : LPCWSTR -> Cwstring
# cchPath : UINT_PTR -> Csize_t
# ppszExt : LPCWSTR* out -> Ptr{Ptr{UInt16}}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t PathCchFindExtension(
    const uint16_t* pszPath,
    uintptr_t cchPath,
    uint16_t** ppszExt);
]]
local api-ms-win-core-path-l1-1-0 = ffi.load("api-ms-win-core-path-l1-1-0")
-- api-ms-win-core-path-l1-1-0.PathCchFindExtension(pszPath, cchPath, ppszExt)
-- pszPath : LPCWSTR
-- cchPath : UINT_PTR
-- ppszExt : LPCWSTR* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('api-ms-win-core-path-l1-1-0.dll');
const PathCchFindExtension = lib.func('__stdcall', 'PathCchFindExtension', 'int32_t', ['str16', 'uintptr_t', 'void *']);
// PathCchFindExtension(pszPath, cchPath, ppszExt)
// pszPath : LPCWSTR -> 'str16'
// cchPath : UINT_PTR -> 'uintptr_t'
// ppszExt : LPCWSTR* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("api-ms-win-core-path-l1-1-0.dll", {
  PathCchFindExtension: { parameters: ["buffer", "usize", "pointer"], result: "i32" },
});
// lib.symbols.PathCchFindExtension(pszPath, cchPath, ppszExt)
// pszPath : LPCWSTR -> "buffer"
// cchPath : UINT_PTR -> "usize"
// ppszExt : LPCWSTR* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t PathCchFindExtension(
    const uint16_t* pszPath,
    size_t cchPath,
    uint16_t** ppszExt);
C, "api-ms-win-core-path-l1-1-0.dll");
// $ffi->PathCchFindExtension(pszPath, cchPath, ppszExt);
// pszPath : LPCWSTR
// cchPath : UINT_PTR
// ppszExt : LPCWSTR* out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Api-ms-win-core-path-l1-1-0 extends StdCallLibrary {
    Api-ms-win-core-path-l1-1-0 INSTANCE = Native.load("api-ms-win-core-path-l1-1-0", Api-ms-win-core-path-l1-1-0.class);
    int PathCchFindExtension(
        WString pszPath,   // LPCWSTR
        long cchPath,   // UINT_PTR
        PointerByReference ppszExt   // LPCWSTR* out
    );
}
@[Link("api-ms-win-core-path-l1-1-0")]
lib Libapi-ms-win-core-path-l1-1-0
  fun PathCchFindExtension = PathCchFindExtension(
    pszPath : UInt16*,   # LPCWSTR
    cchPath : LibC::SizeT,   # UINT_PTR
    ppszExt : UInt16**   # LPCWSTR* out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef PathCchFindExtensionNative = Int32 Function(Pointer<Utf16>, UintPtr, Pointer<Pointer<Utf16>>);
typedef PathCchFindExtensionDart = int Function(Pointer<Utf16>, int, Pointer<Pointer<Utf16>>);
final PathCchFindExtension = DynamicLibrary.open('api-ms-win-core-path-l1-1-0.dll')
    .lookupFunction<PathCchFindExtensionNative, PathCchFindExtensionDart>('PathCchFindExtension');
// pszPath : LPCWSTR -> Pointer<Utf16>
// cchPath : UINT_PTR -> UintPtr
// ppszExt : LPCWSTR* out -> Pointer<Pointer<Utf16>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "PathCchFindExtension"
  c_PathCchFindExtension :: CWString -> CUIntPtr -> Ptr CWString -> IO Int32
-- pszPath : LPCWSTR -> CWString
-- cchPath : UINT_PTR -> CUIntPtr
-- ppszExt : LPCWSTR* out -> Ptr CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let pathcchfindextension =
  foreign "PathCchFindExtension"
    ((ptr uint16_t) @-> size_t @-> (ptr (ptr uint16_t)) @-> returning int32_t)
(* pszPath : LPCWSTR -> (ptr uint16_t) *)
(* cchPath : UINT_PTR -> size_t *)
(* ppszExt : LPCWSTR* out -> (ptr (ptr uint16_t)) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library api-ms-win-core-path-l1-1-0 (t "api-ms-win-core-path-l1-1-0.dll"))
(cffi:use-foreign-library api-ms-win-core-path-l1-1-0)

(cffi:defcfun ("PathCchFindExtension" path-cch-find-extension :convention :stdcall) :int32
  (psz-path (:string :encoding :utf-16le))   ; LPCWSTR
  (cch-path :uint64)   ; UINT_PTR
  (ppsz-ext :pointer))   ; LPCWSTR* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $PathCchFindExtension = Win32::API::More->new('api-ms-win-core-path-l1-1-0',
    'int PathCchFindExtension(LPCWSTR pszPath, WPARAM cchPath, LPVOID ppszExt)');
# my $ret = $PathCchFindExtension->Call($pszPath, $cchPath, $ppszExt);
# pszPath : LPCWSTR -> LPCWSTR
# cchPath : UINT_PTR -> WPARAM
# ppszExt : LPCWSTR* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。