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