ホーム › Storage.FileSystem › SetFileShortNameA
SetFileShortNameA
関数開いているファイルの短い名前(8.3名)を設定する(ANSI版)。
シグネチャ
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
BOOL SetFileShortNameA(
HANDLE hFile,
LPCSTR lpShortName
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hFile | HANDLE | in |
| lpShortName | LPCSTR | in |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
BOOL SetFileShortNameA(
HANDLE hFile,
LPCSTR lpShortName
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SetFileShortNameA(
IntPtr hFile, // HANDLE
[MarshalAs(UnmanagedType.LPStr)] string lpShortName // LPCSTR
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetFileShortNameA(
hFile As IntPtr, ' HANDLE
<MarshalAs(UnmanagedType.LPStr)> lpShortName As String ' LPCSTR
) As Boolean
End Function' hFile : HANDLE
' lpShortName : LPCSTR
Declare PtrSafe Function SetFileShortNameA Lib "kernel32" ( _
ByVal hFile As LongPtr, _
ByVal lpShortName As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetFileShortNameA = ctypes.windll.kernel32.SetFileShortNameA
SetFileShortNameA.restype = wintypes.BOOL
SetFileShortNameA.argtypes = [
wintypes.HANDLE, # hFile : HANDLE
wintypes.LPCSTR, # lpShortName : LPCSTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
SetFileShortNameA = Fiddle::Function.new(
lib['SetFileShortNameA'],
[
Fiddle::TYPE_VOIDP, # hFile : HANDLE
Fiddle::TYPE_VOIDP, # lpShortName : LPCSTR
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn SetFileShortNameA(
hFile: *mut core::ffi::c_void, // HANDLE
lpShortName: *const u8 // LPCSTR
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool SetFileShortNameA(IntPtr hFile, [MarshalAs(UnmanagedType.LPStr)] string lpShortName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SetFileShortNameA' -Namespace Win32 -PassThru
# $api::SetFileShortNameA(hFile, lpShortName)#uselib "KERNEL32.dll"
#func global SetFileShortNameA "SetFileShortNameA" sptr, sptr
; SetFileShortNameA hFile, lpShortName ; 戻り値は stat
; hFile : HANDLE -> "sptr"
; lpShortName : LPCSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global SetFileShortNameA "SetFileShortNameA" sptr, str
; res = SetFileShortNameA(hFile, lpShortName)
; hFile : HANDLE -> "sptr"
; lpShortName : LPCSTR -> "str"; BOOL SetFileShortNameA(HANDLE hFile, LPCSTR lpShortName)
#uselib "KERNEL32.dll"
#cfunc global SetFileShortNameA "SetFileShortNameA" intptr, str
; res = SetFileShortNameA(hFile, lpShortName)
; hFile : HANDLE -> "intptr"
; lpShortName : LPCSTR -> "str"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procSetFileShortNameA = kernel32.NewProc("SetFileShortNameA")
)
// hFile (HANDLE), lpShortName (LPCSTR)
r1, _, err := procSetFileShortNameA.Call(
uintptr(hFile),
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpShortName))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetFileShortNameA(
hFile: THandle; // HANDLE
lpShortName: PAnsiChar // LPCSTR
): BOOL; stdcall;
external 'KERNEL32.dll' name 'SetFileShortNameA';result := DllCall("KERNEL32\SetFileShortNameA"
, "Ptr", hFile ; HANDLE
, "AStr", lpShortName ; LPCSTR
, "Int") ; return: BOOL●SetFileShortNameA(hFile, lpShortName) = DLL("KERNEL32.dll", "bool SetFileShortNameA(void*, char*)")
# 呼び出し: SetFileShortNameA(hFile, lpShortName)
# hFile : HANDLE -> "void*"
# lpShortName : LPCSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。