PathIsPrefixA
関数指定のプレフィックスがパスの先頭に含まれるか判定する。
シグネチャ
// SHLWAPI.dll (ANSI / -A)
#include <windows.h>
BOOL PathIsPrefixA(
LPCSTR pszPrefix,
LPCSTR pszPath
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pszPrefix | LPCSTR | in | 照合する接頭辞を含む、最大長 MAX_PATH の null 終端文字列へのポインター。 |
| pszPath | LPCSTR | in | 調べる対象のパスを含む、最大長 MAX_PATH の null 終端文字列へのポインター。 |
戻り値の型: BOOL
公式ドキュメント
パスを調べ、pszPrefix で渡された接頭辞の値で始まるかどうかを判定します。(ANSI)
戻り値
型: BOOL
pszPath が pszPrefix で始まる場合は TRUE を返し、それ以外の場合は FALSE を返します。
解説(Remarks)
メモ
shlwapi.h ヘッダーは PathIsPrefix を、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 PathIsPrefixA(
LPCSTR pszPrefix,
LPCSTR pszPath
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern bool PathIsPrefixA(
[MarshalAs(UnmanagedType.LPStr)] string pszPrefix, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] string pszPath // LPCSTR
);<DllImport("SHLWAPI.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function PathIsPrefixA(
<MarshalAs(UnmanagedType.LPStr)> pszPrefix As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> pszPath As String ' LPCSTR
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' pszPrefix : LPCSTR
' pszPath : LPCSTR
Declare PtrSafe Function PathIsPrefixA Lib "shlwapi" ( _
ByVal pszPrefix As String, _
ByVal pszPath As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
PathIsPrefixA = ctypes.windll.shlwapi.PathIsPrefixA
PathIsPrefixA.restype = wintypes.BOOL
PathIsPrefixA.argtypes = [
wintypes.LPCSTR, # pszPrefix : LPCSTR
wintypes.LPCSTR, # pszPath : LPCSTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHLWAPI.dll')
PathIsPrefixA = Fiddle::Function.new(
lib['PathIsPrefixA'],
[
Fiddle::TYPE_VOIDP, # pszPrefix : LPCSTR
Fiddle::TYPE_VOIDP, # pszPath : LPCSTR
],
Fiddle::TYPE_INT)#[link(name = "shlwapi")]
extern "system" {
fn PathIsPrefixA(
pszPrefix: *const u8, // LPCSTR
pszPath: *const u8 // LPCSTR
) -> 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 PathIsPrefixA([MarshalAs(UnmanagedType.LPStr)] string pszPrefix, [MarshalAs(UnmanagedType.LPStr)] string pszPath);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_PathIsPrefixA' -Namespace Win32 -PassThru
# $api::PathIsPrefixA(pszPrefix, pszPath)#uselib "SHLWAPI.dll"
#func global PathIsPrefixA "PathIsPrefixA" sptr, sptr
; PathIsPrefixA pszPrefix, pszPath ; 戻り値は stat
; pszPrefix : LPCSTR -> "sptr"
; pszPath : LPCSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SHLWAPI.dll"
#cfunc global PathIsPrefixA "PathIsPrefixA" str, str
; res = PathIsPrefixA(pszPrefix, pszPath)
; pszPrefix : LPCSTR -> "str"
; pszPath : LPCSTR -> "str"; BOOL PathIsPrefixA(LPCSTR pszPrefix, LPCSTR pszPath)
#uselib "SHLWAPI.dll"
#cfunc global PathIsPrefixA "PathIsPrefixA" str, str
; res = PathIsPrefixA(pszPrefix, pszPath)
; pszPrefix : LPCSTR -> "str"
; pszPath : LPCSTR -> "str"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
procPathIsPrefixA = shlwapi.NewProc("PathIsPrefixA")
)
// pszPrefix (LPCSTR), pszPath (LPCSTR)
r1, _, err := procPathIsPrefixA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(pszPrefix))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(pszPath))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction PathIsPrefixA(
pszPrefix: PAnsiChar; // LPCSTR
pszPath: PAnsiChar // LPCSTR
): BOOL; stdcall;
external 'SHLWAPI.dll' name 'PathIsPrefixA';result := DllCall("SHLWAPI\PathIsPrefixA"
, "AStr", pszPrefix ; LPCSTR
, "AStr", pszPath ; LPCSTR
, "Int") ; return: BOOL●PathIsPrefixA(pszPrefix, pszPath) = DLL("SHLWAPI.dll", "bool PathIsPrefixA(char*, char*)")
# 呼び出し: PathIsPrefixA(pszPrefix, pszPath)
# pszPrefix : LPCSTR -> "char*"
# pszPath : LPCSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "shlwapi" fn PathIsPrefixA(
pszPrefix: [*c]const u8, // LPCSTR
pszPath: [*c]const u8 // LPCSTR
) callconv(std.os.windows.WINAPI) i32;proc PathIsPrefixA(
pszPrefix: cstring, # LPCSTR
pszPath: cstring # LPCSTR
): int32 {.importc: "PathIsPrefixA", stdcall, dynlib: "SHLWAPI.dll".}pragma(lib, "shlwapi");
extern(Windows)
int PathIsPrefixA(
const(char)* pszPrefix, // LPCSTR
const(char)* pszPath // LPCSTR
);ccall((:PathIsPrefixA, "SHLWAPI.dll"), stdcall, Int32,
(Cstring, Cstring),
pszPrefix, pszPath)
# pszPrefix : LPCSTR -> Cstring
# pszPath : LPCSTR -> Cstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t PathIsPrefixA(
const char* pszPrefix,
const char* pszPath);
]]
local shlwapi = ffi.load("shlwapi")
-- shlwapi.PathIsPrefixA(pszPrefix, pszPath)
-- pszPrefix : LPCSTR
-- pszPath : LPCSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SHLWAPI.dll');
const PathIsPrefixA = lib.func('__stdcall', 'PathIsPrefixA', 'int32_t', ['str', 'str']);
// PathIsPrefixA(pszPrefix, pszPath)
// pszPrefix : LPCSTR -> 'str'
// pszPath : LPCSTR -> 'str'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHLWAPI.dll", {
PathIsPrefixA: { parameters: ["buffer", "buffer"], result: "i32" },
});
// lib.symbols.PathIsPrefixA(pszPrefix, pszPath)
// pszPrefix : LPCSTR -> "buffer"
// pszPath : LPCSTR -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t PathIsPrefixA(
const char* pszPrefix,
const char* pszPath);
C, "SHLWAPI.dll");
// $ffi->PathIsPrefixA(pszPrefix, pszPath);
// pszPrefix : LPCSTR
// pszPath : LPCSTR
// 構造体/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 PathIsPrefixA(
String pszPrefix, // LPCSTR
String pszPath // LPCSTR
);
}@[Link("shlwapi")]
lib LibSHLWAPI
fun PathIsPrefixA = PathIsPrefixA(
pszPrefix : UInt8*, # LPCSTR
pszPath : UInt8* # LPCSTR
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef PathIsPrefixANative = Int32 Function(Pointer<Utf8>, Pointer<Utf8>);
typedef PathIsPrefixADart = int Function(Pointer<Utf8>, Pointer<Utf8>);
final PathIsPrefixA = DynamicLibrary.open('SHLWAPI.dll')
.lookupFunction<PathIsPrefixANative, PathIsPrefixADart>('PathIsPrefixA');
// pszPrefix : LPCSTR -> Pointer<Utf8>
// pszPath : LPCSTR -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function PathIsPrefixA(
pszPrefix: PAnsiChar; // LPCSTR
pszPath: PAnsiChar // LPCSTR
): BOOL; stdcall;
external 'SHLWAPI.dll' name 'PathIsPrefixA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PathIsPrefixA"
c_PathIsPrefixA :: CString -> CString -> IO CInt
-- pszPrefix : LPCSTR -> CString
-- pszPath : LPCSTR -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let pathisprefixa =
foreign "PathIsPrefixA"
(string @-> string @-> returning int32_t)
(* pszPrefix : LPCSTR -> string *)
(* pszPath : LPCSTR -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library shlwapi (t "SHLWAPI.dll"))
(cffi:use-foreign-library shlwapi)
(cffi:defcfun ("PathIsPrefixA" path-is-prefix-a :convention :stdcall) :int32
(psz-prefix :string) ; LPCSTR
(psz-path :string)) ; LPCSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $PathIsPrefixA = Win32::API::More->new('SHLWAPI',
'BOOL PathIsPrefixA(LPCSTR pszPrefix, LPCSTR pszPath)');
# my $ret = $PathIsPrefixA->Call($pszPrefix, $pszPath);
# pszPrefix : LPCSTR -> LPCSTR
# pszPath : LPCSTR -> LPCSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f PathIsPrefixW (Unicode版) — 指定のプレフィックスがパスの先頭に含まれるか判定する。