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

SetVolumeMountPointA

関数
指定パスにボリュームをマウントする(ANSI版)。
DLLKERNEL32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL SetVolumeMountPointA(
    LPCSTR lpszVolumeMountPoint,
    LPCSTR lpszVolumeName
);

パラメーター

名前方向
lpszVolumeMountPointLPCSTRin
lpszVolumeNameLPCSTRin

戻り値の型: BOOL

各言語での呼び出し定義

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

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

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

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procSetVolumeMountPointA = kernel32.NewProc("SetVolumeMountPointA")
)

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