Win32 API 日本語リファレンス
ホームUI.Shell › PathGetCharTypeA

PathGetCharTypeA

関数
パス中の1文字が持つ意味の種類を示すフラグを取得する。
DLLSHLWAPI.dll文字セットANSI (-A)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

DWORD PathGetCharTypeA(
    BYTE ch
);

パラメーター

名前方向説明
chBYTEin種類を判定する対象の文字。

戻り値の型: DWORD

公式ドキュメント

パスとの関連において、文字の種類を判定します。(ANSI)

戻り値

型: UINT

文字の種類を定義する、次の値のうち 1 つ以上を返します。

戻り値 説明
GCT_INVALID
その文字はパス内で無効です。
GCT_LFNCHAR
その文字は長いファイル名で有効です。
GCT_SEPARATOR
その文字はパス区切り文字です。
GCT_SHORTCHAR
その文字は短い (8.3 形式) ファイル名で有効です。
GCT_WILD
その文字はワイルドカード文字です。

解説(Remarks)

メモ

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

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

各言語での呼び出し定義

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

DWORD PathGetCharTypeA(
    BYTE ch
);
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint PathGetCharTypeA(
    byte ch   // BYTE
);
<DllImport("SHLWAPI.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function PathGetCharTypeA(
    ch As Byte   ' BYTE
) As UInteger
End Function
' ch : BYTE
Declare PtrSafe Function PathGetCharTypeA Lib "shlwapi" ( _
    ByVal ch As Byte) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

PathGetCharTypeA = ctypes.windll.shlwapi.PathGetCharTypeA
PathGetCharTypeA.restype = wintypes.DWORD
PathGetCharTypeA.argtypes = [
    ctypes.c_ubyte,  # ch : BYTE
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHLWAPI.dll')
PathGetCharTypeA = Fiddle::Function.new(
  lib['PathGetCharTypeA'],
  [
    -Fiddle::TYPE_CHAR,  # ch : BYTE
  ],
  -Fiddle::TYPE_INT)
#[link(name = "shlwapi")]
extern "system" {
    fn PathGetCharTypeA(
        ch: u8  // BYTE
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi)]
public static extern uint PathGetCharTypeA(byte ch);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_PathGetCharTypeA' -Namespace Win32 -PassThru
# $api::PathGetCharTypeA(ch)
#uselib "SHLWAPI.dll"
#func global PathGetCharTypeA "PathGetCharTypeA" sptr
; PathGetCharTypeA ch   ; 戻り値は stat
; ch : BYTE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SHLWAPI.dll"
#cfunc global PathGetCharTypeA "PathGetCharTypeA" int
; res = PathGetCharTypeA(ch)
; ch : BYTE -> "int"
; DWORD PathGetCharTypeA(BYTE ch)
#uselib "SHLWAPI.dll"
#cfunc global PathGetCharTypeA "PathGetCharTypeA" int
; res = PathGetCharTypeA(ch)
; ch : BYTE -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procPathGetCharTypeA = shlwapi.NewProc("PathGetCharTypeA")
)

// ch (BYTE)
r1, _, err := procPathGetCharTypeA.Call(
	uintptr(ch),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function PathGetCharTypeA(
  ch: Byte   // BYTE
): DWORD; stdcall;
  external 'SHLWAPI.dll' name 'PathGetCharTypeA';
result := DllCall("SHLWAPI\PathGetCharTypeA"
    , "UChar", ch   ; BYTE
    , "UInt")   ; return: DWORD
●PathGetCharTypeA(ch) = DLL("SHLWAPI.dll", "dword PathGetCharTypeA(byte)")
# 呼び出し: PathGetCharTypeA(ch)
# ch : BYTE -> "byte"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef PathGetCharTypeANative = Uint32 Function(Uint8);
typedef PathGetCharTypeADart = int Function(int);
final PathGetCharTypeA = DynamicLibrary.open('SHLWAPI.dll')
    .lookupFunction<PathGetCharTypeANative, PathGetCharTypeADart>('PathGetCharTypeA');
// ch : BYTE -> Uint8
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function PathGetCharTypeA(
  ch: Byte   // BYTE
): DWORD; stdcall;
  external 'SHLWAPI.dll' name 'PathGetCharTypeA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "PathGetCharTypeA"
  c_PathGetCharTypeA :: Word8 -> IO Word32
-- ch : BYTE -> Word8
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let pathgetchartypea =
  foreign "PathGetCharTypeA"
    (uint8_t @-> returning uint32_t)
(* ch : BYTE -> uint8_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library shlwapi (t "SHLWAPI.dll"))
(cffi:use-foreign-library shlwapi)

(cffi:defcfun ("PathGetCharTypeA" path-get-char-type-a :convention :stdcall) :uint32
  (ch :uint8))   ; BYTE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $PathGetCharTypeA = Win32::API::More->new('SHLWAPI',
    'DWORD PathGetCharTypeA(BYTE ch)');
# my $ret = $PathGetCharTypeA->Call($ch);
# ch : BYTE -> BYTE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い