PathFindOnPathA
関数指定ディレクトリ群を探索し、ファイルが見つかれば完全パスを設定する。
シグネチャ
// SHLWAPI.dll (ANSI / -A)
#include <windows.h>
BOOL PathFindOnPathA(
LPSTR pszPath,
CHAR** ppszOtherDirs // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pszPath | LPSTR | inout | 検索対象のファイル名を含む、長さ MAX_PATH の null 終端文字列へのポインター。検索に成功した場合、このパラメーターには完全修飾されたパス名が返されます。 |
| ppszOtherDirs | CHAR** | inoptional | 最初に検索するディレクトリの、省略可能な null 終端配列です。この値は NULL でもかまいません。 |
戻り値の型: BOOL
公式ドキュメント
ファイルを検索します。(ANSI)
戻り値
型: BOOL
成功した場合は TRUE、それ以外の場合は FALSE を返します。
解説(Remarks)
PathFindOnPath は、pszFile で指定されたファイルを検索します。ppszOtherDirs でディレクトリが指定されていない場合、System32 などの標準ディレクトリや PATH 環境変数で指定されたディレクトリを検索してファイルを見つけようとします。処理を高速化したり、PathFindOnPath がより広範なディレクトリを検索できるようにするには、ppszOtherDirs パラメーターを使用して最初に検索する 1 つ以上のディレクトリを指定します。pszFile で指定された名前を持つファイルが複数存在する場合、PathFindOnPath は最初に見つかったものを返します。
メモ
shlwapi.h ヘッダーは PathFindOnPath をエイリアスとして定義しており、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版が自動的に選択されます。エンコーディング非依存のエイリアスの使用と、エンコーディング非依存でないコードを混在させると、不整合が生じ、コンパイルエラーや実行時エラーの原因となることがあります。詳細については、Conventions for Function Prototypes を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SHLWAPI.dll (ANSI / -A)
#include <windows.h>
BOOL PathFindOnPathA(
LPSTR pszPath,
CHAR** ppszOtherDirs // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern bool PathFindOnPathA(
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pszPath, // LPSTR in/out
IntPtr ppszOtherDirs // CHAR** optional
);<DllImport("SHLWAPI.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function PathFindOnPathA(
<MarshalAs(UnmanagedType.LPStr)> pszPath As System.Text.StringBuilder, ' LPSTR in/out
ppszOtherDirs As IntPtr ' CHAR** optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' pszPath : LPSTR in/out
' ppszOtherDirs : CHAR** optional
Declare PtrSafe Function PathFindOnPathA Lib "shlwapi" ( _
ByVal pszPath As String, _
ByVal ppszOtherDirs As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
PathFindOnPathA = ctypes.windll.shlwapi.PathFindOnPathA
PathFindOnPathA.restype = wintypes.BOOL
PathFindOnPathA.argtypes = [
wintypes.LPSTR, # pszPath : LPSTR in/out
ctypes.c_void_p, # ppszOtherDirs : CHAR** optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHLWAPI.dll')
PathFindOnPathA = Fiddle::Function.new(
lib['PathFindOnPathA'],
[
Fiddle::TYPE_VOIDP, # pszPath : LPSTR in/out
Fiddle::TYPE_VOIDP, # ppszOtherDirs : CHAR** optional
],
Fiddle::TYPE_INT)#[link(name = "shlwapi")]
extern "system" {
fn PathFindOnPathA(
pszPath: *mut u8, // LPSTR in/out
ppszOtherDirs: *mut *mut i8 // CHAR** optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi)]
public static extern bool PathFindOnPathA([MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pszPath, IntPtr ppszOtherDirs);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_PathFindOnPathA' -Namespace Win32 -PassThru
# $api::PathFindOnPathA(pszPath, ppszOtherDirs)#uselib "SHLWAPI.dll"
#func global PathFindOnPathA "PathFindOnPathA" sptr, sptr
; PathFindOnPathA varptr(pszPath), varptr(ppszOtherDirs) ; 戻り値は stat
; pszPath : LPSTR in/out -> "sptr"
; ppszOtherDirs : CHAR** optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SHLWAPI.dll" #cfunc global PathFindOnPathA "PathFindOnPathA" var, var ; res = PathFindOnPathA(pszPath, ppszOtherDirs) ; pszPath : LPSTR in/out -> "var" ; ppszOtherDirs : CHAR** optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHLWAPI.dll" #cfunc global PathFindOnPathA "PathFindOnPathA" sptr, sptr ; res = PathFindOnPathA(varptr(pszPath), varptr(ppszOtherDirs)) ; pszPath : LPSTR in/out -> "sptr" ; ppszOtherDirs : CHAR** optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL PathFindOnPathA(LPSTR pszPath, CHAR** ppszOtherDirs) #uselib "SHLWAPI.dll" #cfunc global PathFindOnPathA "PathFindOnPathA" var, var ; res = PathFindOnPathA(pszPath, ppszOtherDirs) ; pszPath : LPSTR in/out -> "var" ; ppszOtherDirs : CHAR** optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL PathFindOnPathA(LPSTR pszPath, CHAR** ppszOtherDirs) #uselib "SHLWAPI.dll" #cfunc global PathFindOnPathA "PathFindOnPathA" intptr, intptr ; res = PathFindOnPathA(varptr(pszPath), varptr(ppszOtherDirs)) ; pszPath : LPSTR in/out -> "intptr" ; ppszOtherDirs : CHAR** optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
procPathFindOnPathA = shlwapi.NewProc("PathFindOnPathA")
)
// pszPath (LPSTR in/out), ppszOtherDirs (CHAR** optional)
r1, _, err := procPathFindOnPathA.Call(
uintptr(pszPath),
uintptr(ppszOtherDirs),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction PathFindOnPathA(
pszPath: PAnsiChar; // LPSTR in/out
ppszOtherDirs: Pointer // CHAR** optional
): BOOL; stdcall;
external 'SHLWAPI.dll' name 'PathFindOnPathA';result := DllCall("SHLWAPI\PathFindOnPathA"
, "Ptr", pszPath ; LPSTR in/out
, "Ptr", ppszOtherDirs ; CHAR** optional
, "Int") ; return: BOOL●PathFindOnPathA(pszPath, ppszOtherDirs) = DLL("SHLWAPI.dll", "bool PathFindOnPathA(char*, void*)")
# 呼び出し: PathFindOnPathA(pszPath, ppszOtherDirs)
# pszPath : LPSTR in/out -> "char*"
# ppszOtherDirs : CHAR** optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "shlwapi" fn PathFindOnPathA(
pszPath: [*c]u8, // LPSTR in/out
ppszOtherDirs: [*c][*c]i8 // CHAR** optional
) callconv(std.os.windows.WINAPI) i32;proc PathFindOnPathA(
pszPath: ptr char, # LPSTR in/out
ppszOtherDirs: ptr int8 # CHAR** optional
): int32 {.importc: "PathFindOnPathA", stdcall, dynlib: "SHLWAPI.dll".}pragma(lib, "shlwapi");
extern(Windows)
int PathFindOnPathA(
char* pszPath, // LPSTR in/out
byte** ppszOtherDirs // CHAR** optional
);ccall((:PathFindOnPathA, "SHLWAPI.dll"), stdcall, Int32,
(Ptr{UInt8}, Ptr{Int8}),
pszPath, ppszOtherDirs)
# pszPath : LPSTR in/out -> Ptr{UInt8}
# ppszOtherDirs : CHAR** optional -> Ptr{Int8}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t PathFindOnPathA(
char* pszPath,
int8_t** ppszOtherDirs);
]]
local shlwapi = ffi.load("shlwapi")
-- shlwapi.PathFindOnPathA(pszPath, ppszOtherDirs)
-- pszPath : LPSTR in/out
-- ppszOtherDirs : CHAR** optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SHLWAPI.dll');
const PathFindOnPathA = lib.func('__stdcall', 'PathFindOnPathA', 'int32_t', ['char *', 'int8_t *']);
// PathFindOnPathA(pszPath, ppszOtherDirs)
// pszPath : LPSTR in/out -> 'char *'
// ppszOtherDirs : CHAR** optional -> 'int8_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHLWAPI.dll", {
PathFindOnPathA: { parameters: ["buffer", "pointer"], result: "i32" },
});
// lib.symbols.PathFindOnPathA(pszPath, ppszOtherDirs)
// pszPath : LPSTR in/out -> "buffer"
// ppszOtherDirs : CHAR** optional -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t PathFindOnPathA(
char* pszPath,
int8_t** ppszOtherDirs);
C, "SHLWAPI.dll");
// $ffi->PathFindOnPathA(pszPath, ppszOtherDirs);
// pszPath : LPSTR in/out
// ppszOtherDirs : CHAR** optional
// 構造体/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 Shlwapi extends StdCallLibrary {
Shlwapi INSTANCE = Native.load("shlwapi", Shlwapi.class, W32APIOptions.ASCII_OPTIONS);
boolean PathFindOnPathA(
byte[] pszPath, // LPSTR in/out
Pointer ppszOtherDirs // CHAR** optional
);
}@[Link("shlwapi")]
lib LibSHLWAPI
fun PathFindOnPathA = PathFindOnPathA(
pszPath : UInt8*, # LPSTR in/out
ppszOtherDirs : Int8** # CHAR** optional
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef PathFindOnPathANative = Int32 Function(Pointer<Utf8>, Pointer<Int8>);
typedef PathFindOnPathADart = int Function(Pointer<Utf8>, Pointer<Int8>);
final PathFindOnPathA = DynamicLibrary.open('SHLWAPI.dll')
.lookupFunction<PathFindOnPathANative, PathFindOnPathADart>('PathFindOnPathA');
// pszPath : LPSTR in/out -> Pointer<Utf8>
// ppszOtherDirs : CHAR** optional -> Pointer<Int8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function PathFindOnPathA(
pszPath: PAnsiChar; // LPSTR in/out
ppszOtherDirs: Pointer // CHAR** optional
): BOOL; stdcall;
external 'SHLWAPI.dll' name 'PathFindOnPathA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PathFindOnPathA"
c_PathFindOnPathA :: CString -> Ptr Int8 -> IO CInt
-- pszPath : LPSTR in/out -> CString
-- ppszOtherDirs : CHAR** optional -> Ptr Int8
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let pathfindonpatha =
foreign "PathFindOnPathA"
(string @-> (ptr int8_t) @-> returning int32_t)
(* pszPath : LPSTR in/out -> string *)
(* ppszOtherDirs : CHAR** optional -> (ptr int8_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library shlwapi (t "SHLWAPI.dll"))
(cffi:use-foreign-library shlwapi)
(cffi:defcfun ("PathFindOnPathA" path-find-on-path-a :convention :stdcall) :int32
(psz-path :pointer) ; LPSTR in/out
(ppsz-other-dirs :pointer)) ; CHAR** optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $PathFindOnPathA = Win32::API::More->new('SHLWAPI',
'BOOL PathFindOnPathA(LPSTR pszPath, LPVOID ppszOtherDirs)');
# my $ret = $PathFindOnPathA->Call($pszPath, $ppszOtherDirs);
# pszPath : LPSTR in/out -> LPSTR
# ppszOtherDirs : CHAR** optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f PathFindOnPathW (Unicode版) — 指定ディレクトリ群を探索し、ファイルが見つかれば完全パスを設定する。