Win32 API 日本語リファレンス
ホームStorage.FileSystem › SearchPathA

SearchPathA

関数
指定パスから条件に合うファイルを検索しフルパスを取得する(ANSI版)。
DLLKERNEL32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

DWORD SearchPathA(
    LPCSTR lpPath,   // optional
    LPCSTR lpFileName,
    LPCSTR lpExtension,   // optional
    DWORD nBufferLength,
    LPSTR lpBuffer,   // optional
    LPSTR* lpFilePart   // optional
);

パラメーター

名前方向説明
lpPathLPCSTRinoptional

ファイルを検索するパス。

このパラメーターが NULL の場合、関数はレジストリに依存するシステム検索パスを使用して、一致するファイルを検索します。詳細については、「解説」セクションを参照してください。

lpFileNameLPCSTRin

検索対象のファイル名。

既定では、名前は MAX_PATH 文字に制限されます。この制限を 32,767 ワイド文字に拡張するには、パスの先頭に "\\?\" を付加します。詳細については、ファイル、パス、名前空間の名前付けを参照してください。

ヒント

Windows 10 バージョン 1607 以降では、"\\?\" を付加せずに MAX_PATH の制限を取り除くようにオプトインできます。詳細については、ファイル、パス、名前空間の名前付けの「Maximum Path Length Limitation」セクションを参照してください。

lpExtensionLPCSTRinoptional

ファイルを検索する際にファイル名に追加する拡張子。ファイル名の拡張子の最初の文字はピリオド (.) でなければなりません。拡張子は、指定したファイル名が拡張子で終わっていない場合にのみ追加されます。

ファイル名の拡張子が不要な場合、またはファイル名に拡張子が含まれている場合、このパラメーターは NULL にできます。

nBufferLengthDWORDin有効なパスとファイル名(終端の null 文字を含む)を受け取るバッファーのサイズ(TCHAR 単位)。
lpBufferLPSTRoutoptional見つかったファイルのパスとファイル名を受け取るバッファーへのポインター。文字列は null 終端文字列です。
lpFilePartLPSTR*outoptional有効なパスとファイル名の最後のコンポーネントのアドレス(lpBuffer 内)を受け取る変数へのポインター。これは、パス内の最後の円記号 (\) の直後の文字のアドレスです。

戻り値の型: DWORD

公式ドキュメント

指定したパス内で指定したファイルを検索します。(ANSI)

戻り値

関数が成功した場合、戻り値はバッファーにコピーされた文字列の長さ(TCHAR 単位、終端の null 文字を含まない)です。戻り値が nBufferLength より大きい場合、戻り値はパスを保持するために必要なバッファーのサイズ(終端の null 文字を含む)です。

関数が失敗した場合、戻り値はゼロです。拡張エラー情報を取得するには、GetLastError を呼び出します。

解説(Remarks)

lpPath パラメーターが NULL の場合、SearchPath は次のレジストリ値の現在の値に基づいて一致するファイルを検索します。

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\SafeProcessSearchMode

この REG_DWORD レジストリ値が 1 に設定されている場合、SearchPath はまずシステムパスで指定されたフォルダーを検索し、次に現在の作業フォルダーを検索します。このレジストリ値が 0 に設定されている場合、コンピューターはまず現在の作業フォルダーを検索し、次にシステムパスで指定されたフォルダーを検索します。このレジストリキーのシステム既定値は 0 です。

SearchPath 関数で使用される検索モードは、SetSearchPathMode 関数を呼び出すことによってプロセスごとに設定することもできます。

出力を LoadLibrary 関数の呼び出しで使用する予定がある場合、.dll ファイルを特定する方法として SearchPath 関数は推奨されません。SearchPath 関数の検索順序は LoadLibrary 関数で使用される検索順序と異なるため、誤った .dll ファイルが特定される可能性があります。.dll ファイルを特定して読み込む必要がある場合は、LoadLibrary 関数を使用してください。

Windows 8 および Windows Server 2012 では、この関数は次のテクノロジによってサポートされています。

テクノロジ サポート
Server Message Block (SMB) 3.0 プロトコル はい
SMB 3.0 Transparent Failover (TFO) はい
SMB 3.0 with Scale-out File Shares (SO) はい
Cluster Shared Volume File System (CsvFS) はい
Resilient File System (ReFS) はい
メモ

processenv.h ヘッダーは、SearchPath を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義します。エンコーディング中立のエイリアスの使用と、エンコーディング中立でないコードを混在させると、コンパイルエラーや実行時エラーを引き起こす不一致が生じる可能性があります。詳細については、関数プロトタイプの規則を参照してください。

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

各言語での呼び出し定義

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

DWORD SearchPathA(
    LPCSTR lpPath,   // optional
    LPCSTR lpFileName,
    LPCSTR lpExtension,   // optional
    DWORD nBufferLength,
    LPSTR lpBuffer,   // optional
    LPSTR* lpFilePart   // optional
);
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern uint SearchPathA(
    [MarshalAs(UnmanagedType.LPStr)] string lpPath,   // LPCSTR optional
    [MarshalAs(UnmanagedType.LPStr)] string lpFileName,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] string lpExtension,   // LPCSTR optional
    uint nBufferLength,   // DWORD
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpBuffer,   // LPSTR optional, out
    IntPtr lpFilePart   // LPSTR* optional, out
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SearchPathA(
    <MarshalAs(UnmanagedType.LPStr)> lpPath As String,   ' LPCSTR optional
    <MarshalAs(UnmanagedType.LPStr)> lpFileName As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> lpExtension As String,   ' LPCSTR optional
    nBufferLength As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPStr)> lpBuffer As System.Text.StringBuilder,   ' LPSTR optional, out
    lpFilePart As IntPtr   ' LPSTR* optional, out
) As UInteger
End Function
' lpPath : LPCSTR optional
' lpFileName : LPCSTR
' lpExtension : LPCSTR optional
' nBufferLength : DWORD
' lpBuffer : LPSTR optional, out
' lpFilePart : LPSTR* optional, out
Declare PtrSafe Function SearchPathA Lib "kernel32" ( _
    ByVal lpPath As String, _
    ByVal lpFileName As String, _
    ByVal lpExtension As String, _
    ByVal nBufferLength As Long, _
    ByVal lpBuffer As String, _
    ByVal lpFilePart As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SearchPathA = ctypes.windll.kernel32.SearchPathA
SearchPathA.restype = wintypes.DWORD
SearchPathA.argtypes = [
    wintypes.LPCSTR,  # lpPath : LPCSTR optional
    wintypes.LPCSTR,  # lpFileName : LPCSTR
    wintypes.LPCSTR,  # lpExtension : LPCSTR optional
    wintypes.DWORD,  # nBufferLength : DWORD
    wintypes.LPSTR,  # lpBuffer : LPSTR optional, out
    ctypes.c_void_p,  # lpFilePart : LPSTR* optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
SearchPathA = Fiddle::Function.new(
  lib['SearchPathA'],
  [
    Fiddle::TYPE_VOIDP,  # lpPath : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # lpFileName : LPCSTR
    Fiddle::TYPE_VOIDP,  # lpExtension : LPCSTR optional
    -Fiddle::TYPE_INT,  # nBufferLength : DWORD
    Fiddle::TYPE_VOIDP,  # lpBuffer : LPSTR optional, out
    Fiddle::TYPE_VOIDP,  # lpFilePart : LPSTR* optional, out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn SearchPathA(
        lpPath: *const u8,  // LPCSTR optional
        lpFileName: *const u8,  // LPCSTR
        lpExtension: *const u8,  // LPCSTR optional
        nBufferLength: u32,  // DWORD
        lpBuffer: *mut u8,  // LPSTR optional, out
        lpFilePart: *mut *mut u8  // LPSTR* optional, out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern uint SearchPathA([MarshalAs(UnmanagedType.LPStr)] string lpPath, [MarshalAs(UnmanagedType.LPStr)] string lpFileName, [MarshalAs(UnmanagedType.LPStr)] string lpExtension, uint nBufferLength, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpBuffer, IntPtr lpFilePart);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SearchPathA' -Namespace Win32 -PassThru
# $api::SearchPathA(lpPath, lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart)
#uselib "KERNEL32.dll"
#func global SearchPathA "SearchPathA" sptr, sptr, sptr, sptr, sptr, sptr
; SearchPathA lpPath, lpFileName, lpExtension, nBufferLength, varptr(lpBuffer), varptr(lpFilePart)   ; 戻り値は stat
; lpPath : LPCSTR optional -> "sptr"
; lpFileName : LPCSTR -> "sptr"
; lpExtension : LPCSTR optional -> "sptr"
; nBufferLength : DWORD -> "sptr"
; lpBuffer : LPSTR optional, out -> "sptr"
; lpFilePart : LPSTR* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global SearchPathA "SearchPathA" str, str, str, int, var, var
; res = SearchPathA(lpPath, lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart)
; lpPath : LPCSTR optional -> "str"
; lpFileName : LPCSTR -> "str"
; lpExtension : LPCSTR optional -> "str"
; nBufferLength : DWORD -> "int"
; lpBuffer : LPSTR optional, out -> "var"
; lpFilePart : LPSTR* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD SearchPathA(LPCSTR lpPath, LPCSTR lpFileName, LPCSTR lpExtension, DWORD nBufferLength, LPSTR lpBuffer, LPSTR* lpFilePart)
#uselib "KERNEL32.dll"
#cfunc global SearchPathA "SearchPathA" str, str, str, int, var, var
; res = SearchPathA(lpPath, lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart)
; lpPath : LPCSTR optional -> "str"
; lpFileName : LPCSTR -> "str"
; lpExtension : LPCSTR optional -> "str"
; nBufferLength : DWORD -> "int"
; lpBuffer : LPSTR optional, out -> "var"
; lpFilePart : LPSTR* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procSearchPathA = kernel32.NewProc("SearchPathA")
)

// lpPath (LPCSTR optional), lpFileName (LPCSTR), lpExtension (LPCSTR optional), nBufferLength (DWORD), lpBuffer (LPSTR optional, out), lpFilePart (LPSTR* optional, out)
r1, _, err := procSearchPathA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpPath))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpFileName))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpExtension))),
	uintptr(nBufferLength),
	uintptr(lpBuffer),
	uintptr(lpFilePart),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function SearchPathA(
  lpPath: PAnsiChar;   // LPCSTR optional
  lpFileName: PAnsiChar;   // LPCSTR
  lpExtension: PAnsiChar;   // LPCSTR optional
  nBufferLength: DWORD;   // DWORD
  lpBuffer: PAnsiChar;   // LPSTR optional, out
  lpFilePart: PPAnsiChar   // LPSTR* optional, out
): DWORD; stdcall;
  external 'KERNEL32.dll' name 'SearchPathA';
result := DllCall("KERNEL32\SearchPathA"
    , "AStr", lpPath   ; LPCSTR optional
    , "AStr", lpFileName   ; LPCSTR
    , "AStr", lpExtension   ; LPCSTR optional
    , "UInt", nBufferLength   ; DWORD
    , "Ptr", lpBuffer   ; LPSTR optional, out
    , "Ptr", lpFilePart   ; LPSTR* optional, out
    , "UInt")   ; return: DWORD
●SearchPathA(lpPath, lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart) = DLL("KERNEL32.dll", "dword SearchPathA(char*, char*, char*, dword, char*, void*)")
# 呼び出し: SearchPathA(lpPath, lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart)
# lpPath : LPCSTR optional -> "char*"
# lpFileName : LPCSTR -> "char*"
# lpExtension : LPCSTR optional -> "char*"
# nBufferLength : DWORD -> "dword"
# lpBuffer : LPSTR optional, out -> "char*"
# lpFilePart : LPSTR* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "kernel32" fn SearchPathA(
    lpPath: [*c]const u8, // LPCSTR optional
    lpFileName: [*c]const u8, // LPCSTR
    lpExtension: [*c]const u8, // LPCSTR optional
    nBufferLength: u32, // DWORD
    lpBuffer: [*c]u8, // LPSTR optional, out
    lpFilePart: [*c][*c]u8 // LPSTR* optional, out
) callconv(std.os.windows.WINAPI) u32;
proc SearchPathA(
    lpPath: cstring,  # LPCSTR optional
    lpFileName: cstring,  # LPCSTR
    lpExtension: cstring,  # LPCSTR optional
    nBufferLength: uint32,  # DWORD
    lpBuffer: ptr char,  # LPSTR optional, out
    lpFilePart: ptr cstring  # LPSTR* optional, out
): uint32 {.importc: "SearchPathA", stdcall, dynlib: "KERNEL32.dll".}
pragma(lib, "kernel32");
extern(Windows)
uint SearchPathA(
    const(char)* lpPath,   // LPCSTR optional
    const(char)* lpFileName,   // LPCSTR
    const(char)* lpExtension,   // LPCSTR optional
    uint nBufferLength,   // DWORD
    char* lpBuffer,   // LPSTR optional, out
    char** lpFilePart   // LPSTR* optional, out
);
ccall((:SearchPathA, "KERNEL32.dll"), stdcall, UInt32,
      (Cstring, Cstring, Cstring, UInt32, Ptr{UInt8}, Ptr{Ptr{UInt8}}),
      lpPath, lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart)
# lpPath : LPCSTR optional -> Cstring
# lpFileName : LPCSTR -> Cstring
# lpExtension : LPCSTR optional -> Cstring
# nBufferLength : DWORD -> UInt32
# lpBuffer : LPSTR optional, out -> Ptr{UInt8}
# lpFilePart : LPSTR* optional, out -> Ptr{Ptr{UInt8}}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t SearchPathA(
    const char* lpPath,
    const char* lpFileName,
    const char* lpExtension,
    uint32_t nBufferLength,
    char* lpBuffer,
    char** lpFilePart);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.SearchPathA(lpPath, lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart)
-- lpPath : LPCSTR optional
-- lpFileName : LPCSTR
-- lpExtension : LPCSTR optional
-- nBufferLength : DWORD
-- lpBuffer : LPSTR optional, out
-- lpFilePart : LPSTR* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const SearchPathA = lib.func('__stdcall', 'SearchPathA', 'uint32_t', ['str', 'str', 'str', 'uint32_t', 'char *', 'void *']);
// SearchPathA(lpPath, lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart)
// lpPath : LPCSTR optional -> 'str'
// lpFileName : LPCSTR -> 'str'
// lpExtension : LPCSTR optional -> 'str'
// nBufferLength : DWORD -> 'uint32_t'
// lpBuffer : LPSTR optional, out -> 'char *'
// lpFilePart : LPSTR* optional, out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  SearchPathA: { parameters: ["buffer", "buffer", "buffer", "u32", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.SearchPathA(lpPath, lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart)
// lpPath : LPCSTR optional -> "buffer"
// lpFileName : LPCSTR -> "buffer"
// lpExtension : LPCSTR optional -> "buffer"
// nBufferLength : DWORD -> "u32"
// lpBuffer : LPSTR optional, out -> "buffer"
// lpFilePart : LPSTR* optional, out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t SearchPathA(
    const char* lpPath,
    const char* lpFileName,
    const char* lpExtension,
    uint32_t nBufferLength,
    char* lpBuffer,
    char** lpFilePart);
C, "KERNEL32.dll");
// $ffi->SearchPathA(lpPath, lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart);
// lpPath : LPCSTR optional
// lpFileName : LPCSTR
// lpExtension : LPCSTR optional
// nBufferLength : DWORD
// lpBuffer : LPSTR optional, out
// lpFilePart : LPSTR* optional, 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 Kernel32 extends StdCallLibrary {
    Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class, W32APIOptions.ASCII_OPTIONS);
    int SearchPathA(
        String lpPath,   // LPCSTR optional
        String lpFileName,   // LPCSTR
        String lpExtension,   // LPCSTR optional
        int nBufferLength,   // DWORD
        byte[] lpBuffer,   // LPSTR optional, out
        PointerByReference lpFilePart   // LPSTR* optional, out
    );
}
@[Link("kernel32")]
lib LibKERNEL32
  fun SearchPathA = SearchPathA(
    lpPath : UInt8*,   # LPCSTR optional
    lpFileName : UInt8*,   # LPCSTR
    lpExtension : UInt8*,   # LPCSTR optional
    nBufferLength : UInt32,   # DWORD
    lpBuffer : UInt8*,   # LPSTR optional, out
    lpFilePart : UInt8**   # LPSTR* optional, out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SearchPathANative = Uint32 Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Uint32, Pointer<Utf8>, Pointer<Pointer<Utf8>>);
typedef SearchPathADart = int Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, int, Pointer<Utf8>, Pointer<Pointer<Utf8>>);
final SearchPathA = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<SearchPathANative, SearchPathADart>('SearchPathA');
// lpPath : LPCSTR optional -> Pointer<Utf8>
// lpFileName : LPCSTR -> Pointer<Utf8>
// lpExtension : LPCSTR optional -> Pointer<Utf8>
// nBufferLength : DWORD -> Uint32
// lpBuffer : LPSTR optional, out -> Pointer<Utf8>
// lpFilePart : LPSTR* optional, out -> Pointer<Pointer<Utf8>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SearchPathA(
  lpPath: PAnsiChar;   // LPCSTR optional
  lpFileName: PAnsiChar;   // LPCSTR
  lpExtension: PAnsiChar;   // LPCSTR optional
  nBufferLength: DWORD;   // DWORD
  lpBuffer: PAnsiChar;   // LPSTR optional, out
  lpFilePart: PPAnsiChar   // LPSTR* optional, out
): DWORD; stdcall;
  external 'KERNEL32.dll' name 'SearchPathA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SearchPathA"
  c_SearchPathA :: CString -> CString -> CString -> Word32 -> CString -> Ptr CString -> IO Word32
-- lpPath : LPCSTR optional -> CString
-- lpFileName : LPCSTR -> CString
-- lpExtension : LPCSTR optional -> CString
-- nBufferLength : DWORD -> Word32
-- lpBuffer : LPSTR optional, out -> CString
-- lpFilePart : LPSTR* optional, out -> Ptr CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let searchpatha =
  foreign "SearchPathA"
    (string @-> string @-> string @-> uint32_t @-> string @-> (ptr string) @-> returning uint32_t)
(* lpPath : LPCSTR optional -> string *)
(* lpFileName : LPCSTR -> string *)
(* lpExtension : LPCSTR optional -> string *)
(* nBufferLength : DWORD -> uint32_t *)
(* lpBuffer : LPSTR optional, out -> string *)
(* lpFilePart : LPSTR* optional, out -> (ptr string) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("SearchPathA" search-path-a :convention :stdcall) :uint32
  (lp-path :string)   ; LPCSTR optional
  (lp-file-name :string)   ; LPCSTR
  (lp-extension :string)   ; LPCSTR optional
  (n-buffer-length :uint32)   ; DWORD
  (lp-buffer :pointer)   ; LPSTR optional, out
  (lp-file-part :pointer))   ; LPSTR* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SearchPathA = Win32::API::More->new('KERNEL32',
    'DWORD SearchPathA(LPCSTR lpPath, LPCSTR lpFileName, LPCSTR lpExtension, DWORD nBufferLength, LPSTR lpBuffer, LPVOID lpFilePart)');
# my $ret = $SearchPathA->Call($lpPath, $lpFileName, $lpExtension, $nBufferLength, $lpBuffer, $lpFilePart);
# lpPath : LPCSTR optional -> LPCSTR
# lpFileName : LPCSTR -> LPCSTR
# lpExtension : LPCSTR optional -> LPCSTR
# nBufferLength : DWORD -> DWORD
# lpBuffer : LPSTR optional, out -> LPSTR
# lpFilePart : LPSTR* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い
公式の関連項目