Win32 API 日本語リファレンス
ホームStorage.FileSystem › SetVolumeLabelA

SetVolumeLabelA

関数
ボリュームのラベル名を設定する(ANSI版)。
DLLKERNEL32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL SetVolumeLabelA(
    LPCSTR lpRootPathName,   // optional
    LPCSTR lpVolumeName   // optional
);

パラメーター

名前方向
lpRootPathNameLPCSTRinoptional
lpVolumeNameLPCSTRinoptional

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetVolumeLabelA(
    LPCSTR lpRootPathName,   // optional
    LPCSTR lpVolumeName   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SetVolumeLabelA(
    [MarshalAs(UnmanagedType.LPStr)] string lpRootPathName,   // LPCSTR optional
    [MarshalAs(UnmanagedType.LPStr)] string lpVolumeName   // LPCSTR optional
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetVolumeLabelA(
    <MarshalAs(UnmanagedType.LPStr)> lpRootPathName As String,   ' LPCSTR optional
    <MarshalAs(UnmanagedType.LPStr)> lpVolumeName As String   ' LPCSTR optional
) As Boolean
End Function
' lpRootPathName : LPCSTR optional
' lpVolumeName : LPCSTR optional
Declare PtrSafe Function SetVolumeLabelA Lib "kernel32" ( _
    ByVal lpRootPathName As String, _
    ByVal lpVolumeName As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetVolumeLabelA = ctypes.windll.kernel32.SetVolumeLabelA
SetVolumeLabelA.restype = wintypes.BOOL
SetVolumeLabelA.argtypes = [
    wintypes.LPCSTR,  # lpRootPathName : LPCSTR optional
    wintypes.LPCSTR,  # lpVolumeName : LPCSTR optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
SetVolumeLabelA = Fiddle::Function.new(
  lib['SetVolumeLabelA'],
  [
    Fiddle::TYPE_VOIDP,  # lpRootPathName : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # lpVolumeName : LPCSTR optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn SetVolumeLabelA(
        lpRootPathName: *const u8,  // LPCSTR optional
        lpVolumeName: *const u8  // LPCSTR optional
    ) -> 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 SetVolumeLabelA([MarshalAs(UnmanagedType.LPStr)] string lpRootPathName, [MarshalAs(UnmanagedType.LPStr)] string lpVolumeName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SetVolumeLabelA' -Namespace Win32 -PassThru
# $api::SetVolumeLabelA(lpRootPathName, lpVolumeName)
#uselib "KERNEL32.dll"
#func global SetVolumeLabelA "SetVolumeLabelA" sptr, sptr
; SetVolumeLabelA lpRootPathName, lpVolumeName   ; 戻り値は stat
; lpRootPathName : LPCSTR optional -> "sptr"
; lpVolumeName : LPCSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global SetVolumeLabelA "SetVolumeLabelA" str, str
; res = SetVolumeLabelA(lpRootPathName, lpVolumeName)
; lpRootPathName : LPCSTR optional -> "str"
; lpVolumeName : LPCSTR optional -> "str"
; BOOL SetVolumeLabelA(LPCSTR lpRootPathName, LPCSTR lpVolumeName)
#uselib "KERNEL32.dll"
#cfunc global SetVolumeLabelA "SetVolumeLabelA" str, str
; res = SetVolumeLabelA(lpRootPathName, lpVolumeName)
; lpRootPathName : LPCSTR optional -> "str"
; lpVolumeName : LPCSTR optional -> "str"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procSetVolumeLabelA = kernel32.NewProc("SetVolumeLabelA")
)

// lpRootPathName (LPCSTR optional), lpVolumeName (LPCSTR optional)
r1, _, err := procSetVolumeLabelA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpRootPathName))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpVolumeName))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetVolumeLabelA(
  lpRootPathName: PAnsiChar;   // LPCSTR optional
  lpVolumeName: PAnsiChar   // LPCSTR optional
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'SetVolumeLabelA';
result := DllCall("KERNEL32\SetVolumeLabelA"
    , "AStr", lpRootPathName   ; LPCSTR optional
    , "AStr", lpVolumeName   ; LPCSTR optional
    , "Int")   ; return: BOOL
●SetVolumeLabelA(lpRootPathName, lpVolumeName) = DLL("KERNEL32.dll", "bool SetVolumeLabelA(char*, char*)")
# 呼び出し: SetVolumeLabelA(lpRootPathName, lpVolumeName)
# lpRootPathName : LPCSTR optional -> "char*"
# lpVolumeName : LPCSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。