ホーム › Storage.FileSystem › CheckNameLegalDOS8Dot3W
CheckNameLegalDOS8Dot3W
関数名前が有効な8.3形式DOS名かを検証する(Unicode版)。
シグネチャ
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
BOOL CheckNameLegalDOS8Dot3W(
LPCWSTR lpName,
LPSTR lpOemName, // optional
DWORD OemNameSize,
BOOL* pbNameContainsSpaces, // optional
BOOL* pbNameLegal
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpName | LPCWSTR | in |
| lpOemName | LPSTR | outoptional |
| OemNameSize | DWORD | in |
| pbNameContainsSpaces | BOOL* | outoptional |
| pbNameLegal | BOOL* | out |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
BOOL CheckNameLegalDOS8Dot3W(
LPCWSTR lpName,
LPSTR lpOemName, // optional
DWORD OemNameSize,
BOOL* pbNameContainsSpaces, // optional
BOOL* pbNameLegal
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool CheckNameLegalDOS8Dot3W(
[MarshalAs(UnmanagedType.LPWStr)] string lpName, // LPCWSTR
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpOemName, // LPSTR optional, out
uint OemNameSize, // DWORD
IntPtr pbNameContainsSpaces, // BOOL* optional, out
out int pbNameLegal // BOOL* out
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CheckNameLegalDOS8Dot3W(
<MarshalAs(UnmanagedType.LPWStr)> lpName As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPStr)> lpOemName As System.Text.StringBuilder, ' LPSTR optional, out
OemNameSize As UInteger, ' DWORD
pbNameContainsSpaces As IntPtr, ' BOOL* optional, out
<Out> ByRef pbNameLegal As Integer ' BOOL* out
) As Boolean
End Function' lpName : LPCWSTR
' lpOemName : LPSTR optional, out
' OemNameSize : DWORD
' pbNameContainsSpaces : BOOL* optional, out
' pbNameLegal : BOOL* out
Declare PtrSafe Function CheckNameLegalDOS8Dot3W Lib "kernel32" ( _
ByVal lpName As LongPtr, _
ByVal lpOemName As String, _
ByVal OemNameSize As Long, _
ByVal pbNameContainsSpaces As LongPtr, _
ByRef pbNameLegal As Long) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CheckNameLegalDOS8Dot3W = ctypes.windll.kernel32.CheckNameLegalDOS8Dot3W
CheckNameLegalDOS8Dot3W.restype = wintypes.BOOL
CheckNameLegalDOS8Dot3W.argtypes = [
wintypes.LPCWSTR, # lpName : LPCWSTR
wintypes.LPSTR, # lpOemName : LPSTR optional, out
wintypes.DWORD, # OemNameSize : DWORD
ctypes.c_void_p, # pbNameContainsSpaces : BOOL* optional, out
ctypes.c_void_p, # pbNameLegal : BOOL* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
CheckNameLegalDOS8Dot3W = Fiddle::Function.new(
lib['CheckNameLegalDOS8Dot3W'],
[
Fiddle::TYPE_VOIDP, # lpName : LPCWSTR
Fiddle::TYPE_VOIDP, # lpOemName : LPSTR optional, out
-Fiddle::TYPE_INT, # OemNameSize : DWORD
Fiddle::TYPE_VOIDP, # pbNameContainsSpaces : BOOL* optional, out
Fiddle::TYPE_VOIDP, # pbNameLegal : BOOL* out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "kernel32")]
extern "system" {
fn CheckNameLegalDOS8Dot3W(
lpName: *const u16, // LPCWSTR
lpOemName: *mut u8, // LPSTR optional, out
OemNameSize: u32, // DWORD
pbNameContainsSpaces: *mut i32, // BOOL* optional, out
pbNameLegal: *mut i32 // BOOL* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool CheckNameLegalDOS8Dot3W([MarshalAs(UnmanagedType.LPWStr)] string lpName, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpOemName, uint OemNameSize, IntPtr pbNameContainsSpaces, out int pbNameLegal);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_CheckNameLegalDOS8Dot3W' -Namespace Win32 -PassThru
# $api::CheckNameLegalDOS8Dot3W(lpName, lpOemName, OemNameSize, pbNameContainsSpaces, pbNameLegal)#uselib "KERNEL32.dll"
#func global CheckNameLegalDOS8Dot3W "CheckNameLegalDOS8Dot3W" wptr, wptr, wptr, wptr, wptr
; CheckNameLegalDOS8Dot3W lpName, varptr(lpOemName), OemNameSize, pbNameContainsSpaces, pbNameLegal ; 戻り値は stat
; lpName : LPCWSTR -> "wptr"
; lpOemName : LPSTR optional, out -> "wptr"
; OemNameSize : DWORD -> "wptr"
; pbNameContainsSpaces : BOOL* optional, out -> "wptr"
; pbNameLegal : BOOL* out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global CheckNameLegalDOS8Dot3W "CheckNameLegalDOS8Dot3W" wstr, var, int, int, int ; res = CheckNameLegalDOS8Dot3W(lpName, lpOemName, OemNameSize, pbNameContainsSpaces, pbNameLegal) ; lpName : LPCWSTR -> "wstr" ; lpOemName : LPSTR optional, out -> "var" ; OemNameSize : DWORD -> "int" ; pbNameContainsSpaces : BOOL* optional, out -> "int" ; pbNameLegal : BOOL* out -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global CheckNameLegalDOS8Dot3W "CheckNameLegalDOS8Dot3W" wstr, sptr, int, int, int ; res = CheckNameLegalDOS8Dot3W(lpName, varptr(lpOemName), OemNameSize, pbNameContainsSpaces, pbNameLegal) ; lpName : LPCWSTR -> "wstr" ; lpOemName : LPSTR optional, out -> "sptr" ; OemNameSize : DWORD -> "int" ; pbNameContainsSpaces : BOOL* optional, out -> "int" ; pbNameLegal : BOOL* out -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL CheckNameLegalDOS8Dot3W(LPCWSTR lpName, LPSTR lpOemName, DWORD OemNameSize, BOOL* pbNameContainsSpaces, BOOL* pbNameLegal) #uselib "KERNEL32.dll" #cfunc global CheckNameLegalDOS8Dot3W "CheckNameLegalDOS8Dot3W" wstr, var, int, int, int ; res = CheckNameLegalDOS8Dot3W(lpName, lpOemName, OemNameSize, pbNameContainsSpaces, pbNameLegal) ; lpName : LPCWSTR -> "wstr" ; lpOemName : LPSTR optional, out -> "var" ; OemNameSize : DWORD -> "int" ; pbNameContainsSpaces : BOOL* optional, out -> "int" ; pbNameLegal : BOOL* out -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL CheckNameLegalDOS8Dot3W(LPCWSTR lpName, LPSTR lpOemName, DWORD OemNameSize, BOOL* pbNameContainsSpaces, BOOL* pbNameLegal) #uselib "KERNEL32.dll" #cfunc global CheckNameLegalDOS8Dot3W "CheckNameLegalDOS8Dot3W" wstr, intptr, int, int, int ; res = CheckNameLegalDOS8Dot3W(lpName, varptr(lpOemName), OemNameSize, pbNameContainsSpaces, pbNameLegal) ; lpName : LPCWSTR -> "wstr" ; lpOemName : LPSTR optional, out -> "intptr" ; OemNameSize : DWORD -> "int" ; pbNameContainsSpaces : BOOL* optional, out -> "int" ; pbNameLegal : BOOL* out -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procCheckNameLegalDOS8Dot3W = kernel32.NewProc("CheckNameLegalDOS8Dot3W")
)
// lpName (LPCWSTR), lpOemName (LPSTR optional, out), OemNameSize (DWORD), pbNameContainsSpaces (BOOL* optional, out), pbNameLegal (BOOL* out)
r1, _, err := procCheckNameLegalDOS8Dot3W.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpName))),
uintptr(lpOemName),
uintptr(OemNameSize),
uintptr(pbNameContainsSpaces),
uintptr(pbNameLegal),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CheckNameLegalDOS8Dot3W(
lpName: PWideChar; // LPCWSTR
lpOemName: PAnsiChar; // LPSTR optional, out
OemNameSize: DWORD; // DWORD
pbNameContainsSpaces: Pointer; // BOOL* optional, out
pbNameLegal: Pointer // BOOL* out
): BOOL; stdcall;
external 'KERNEL32.dll' name 'CheckNameLegalDOS8Dot3W';result := DllCall("KERNEL32\CheckNameLegalDOS8Dot3W"
, "WStr", lpName ; LPCWSTR
, "Ptr", lpOemName ; LPSTR optional, out
, "UInt", OemNameSize ; DWORD
, "Ptr", pbNameContainsSpaces ; BOOL* optional, out
, "Ptr", pbNameLegal ; BOOL* out
, "Int") ; return: BOOL●CheckNameLegalDOS8Dot3W(lpName, lpOemName, OemNameSize, pbNameContainsSpaces, pbNameLegal) = DLL("KERNEL32.dll", "bool CheckNameLegalDOS8Dot3W(char*, char*, dword, void*, void*)")
# 呼び出し: CheckNameLegalDOS8Dot3W(lpName, lpOemName, OemNameSize, pbNameContainsSpaces, pbNameLegal)
# lpName : LPCWSTR -> "char*"
# lpOemName : LPSTR optional, out -> "char*"
# OemNameSize : DWORD -> "dword"
# pbNameContainsSpaces : BOOL* optional, out -> "void*"
# pbNameLegal : BOOL* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。