ホーム › Storage.FileSystem › SetVolumeLabelW
SetVolumeLabelW
関数ボリュームのラベル名を設定する(Unicode版)。
シグネチャ
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
BOOL SetVolumeLabelW(
LPCWSTR lpRootPathName, // optional
LPCWSTR lpVolumeName // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpRootPathName | LPCWSTR | inoptional |
| lpVolumeName | LPCWSTR | inoptional |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
BOOL SetVolumeLabelW(
LPCWSTR lpRootPathName, // optional
LPCWSTR lpVolumeName // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetVolumeLabelW(
[MarshalAs(UnmanagedType.LPWStr)] string lpRootPathName, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string lpVolumeName // LPCWSTR optional
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetVolumeLabelW(
<MarshalAs(UnmanagedType.LPWStr)> lpRootPathName As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> lpVolumeName As String ' LPCWSTR optional
) As Boolean
End Function' lpRootPathName : LPCWSTR optional
' lpVolumeName : LPCWSTR optional
Declare PtrSafe Function SetVolumeLabelW Lib "kernel32" ( _
ByVal lpRootPathName As LongPtr, _
ByVal lpVolumeName As LongPtr) 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
SetVolumeLabelW = ctypes.windll.kernel32.SetVolumeLabelW
SetVolumeLabelW.restype = wintypes.BOOL
SetVolumeLabelW.argtypes = [
wintypes.LPCWSTR, # lpRootPathName : LPCWSTR optional
wintypes.LPCWSTR, # lpVolumeName : LPCWSTR optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
SetVolumeLabelW = Fiddle::Function.new(
lib['SetVolumeLabelW'],
[
Fiddle::TYPE_VOIDP, # lpRootPathName : LPCWSTR optional
Fiddle::TYPE_VOIDP, # lpVolumeName : LPCWSTR optional
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "kernel32")]
extern "system" {
fn SetVolumeLabelW(
lpRootPathName: *const u16, // LPCWSTR optional
lpVolumeName: *const u16 // LPCWSTR optional
) -> 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 SetVolumeLabelW([MarshalAs(UnmanagedType.LPWStr)] string lpRootPathName, [MarshalAs(UnmanagedType.LPWStr)] string lpVolumeName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SetVolumeLabelW' -Namespace Win32 -PassThru
# $api::SetVolumeLabelW(lpRootPathName, lpVolumeName)#uselib "KERNEL32.dll"
#func global SetVolumeLabelW "SetVolumeLabelW" wptr, wptr
; SetVolumeLabelW lpRootPathName, lpVolumeName ; 戻り値は stat
; lpRootPathName : LPCWSTR optional -> "wptr"
; lpVolumeName : LPCWSTR optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global SetVolumeLabelW "SetVolumeLabelW" wstr, wstr
; res = SetVolumeLabelW(lpRootPathName, lpVolumeName)
; lpRootPathName : LPCWSTR optional -> "wstr"
; lpVolumeName : LPCWSTR optional -> "wstr"; BOOL SetVolumeLabelW(LPCWSTR lpRootPathName, LPCWSTR lpVolumeName)
#uselib "KERNEL32.dll"
#cfunc global SetVolumeLabelW "SetVolumeLabelW" wstr, wstr
; res = SetVolumeLabelW(lpRootPathName, lpVolumeName)
; lpRootPathName : LPCWSTR optional -> "wstr"
; lpVolumeName : LPCWSTR optional -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procSetVolumeLabelW = kernel32.NewProc("SetVolumeLabelW")
)
// lpRootPathName (LPCWSTR optional), lpVolumeName (LPCWSTR optional)
r1, _, err := procSetVolumeLabelW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpRootPathName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpVolumeName))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetVolumeLabelW(
lpRootPathName: PWideChar; // LPCWSTR optional
lpVolumeName: PWideChar // LPCWSTR optional
): BOOL; stdcall;
external 'KERNEL32.dll' name 'SetVolumeLabelW';result := DllCall("KERNEL32\SetVolumeLabelW"
, "WStr", lpRootPathName ; LPCWSTR optional
, "WStr", lpVolumeName ; LPCWSTR optional
, "Int") ; return: BOOL●SetVolumeLabelW(lpRootPathName, lpVolumeName) = DLL("KERNEL32.dll", "bool SetVolumeLabelW(char*, char*)")
# 呼び出し: SetVolumeLabelW(lpRootPathName, lpVolumeName)
# lpRootPathName : LPCWSTR optional -> "char*"
# lpVolumeName : LPCWSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。