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

SetVolumeMountPointW

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

シグネチャ

// KERNEL32.dll  (Unicode / -W)
#include <windows.h>

BOOL SetVolumeMountPointW(
    LPCWSTR lpszVolumeMountPoint,
    LPCWSTR lpszVolumeName
);

パラメーター

名前方向
lpszVolumeMountPointLPCWSTRin
lpszVolumeNameLPCWSTRin

戻り値の型: BOOL

各言語での呼び出し定義

// KERNEL32.dll  (Unicode / -W)
#include <windows.h>

BOOL SetVolumeMountPointW(
    LPCWSTR lpszVolumeMountPoint,
    LPCWSTR lpszVolumeName
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetVolumeMountPointW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpszVolumeMountPoint,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string lpszVolumeName   // LPCWSTR
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetVolumeMountPointW(
    <MarshalAs(UnmanagedType.LPWStr)> lpszVolumeMountPoint As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> lpszVolumeName As String   ' LPCWSTR
) As Boolean
End Function
' lpszVolumeMountPoint : LPCWSTR
' lpszVolumeName : LPCWSTR
Declare PtrSafe Function SetVolumeMountPointW Lib "kernel32" ( _
    ByVal lpszVolumeMountPoint As LongPtr, _
    ByVal lpszVolumeName 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

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

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procSetVolumeMountPointW = kernel32.NewProc("SetVolumeMountPointW")
)

// lpszVolumeMountPoint (LPCWSTR), lpszVolumeName (LPCWSTR)
r1, _, err := procSetVolumeMountPointW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszVolumeMountPoint))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszVolumeName))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetVolumeMountPointW(
  lpszVolumeMountPoint: PWideChar;   // LPCWSTR
  lpszVolumeName: PWideChar   // LPCWSTR
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'SetVolumeMountPointW';
result := DllCall("KERNEL32\SetVolumeMountPointW"
    , "WStr", lpszVolumeMountPoint   ; LPCWSTR
    , "WStr", lpszVolumeName   ; LPCWSTR
    , "Int")   ; return: BOOL
●SetVolumeMountPointW(lpszVolumeMountPoint, lpszVolumeName) = DLL("KERNEL32.dll", "bool SetVolumeMountPointW(char*, char*)")
# 呼び出し: SetVolumeMountPointW(lpszVolumeMountPoint, lpszVolumeName)
# lpszVolumeMountPoint : LPCWSTR -> "char*"
# lpszVolumeName : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。