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ボリュームに関連付けるユーザーモードのパスです。これはドライブ文字(例: "X:\")でも、 別のボリューム上のディレクトリ(例: "Y:\MountX\")でもかまいません。文字列は末尾にバックスラッシュ('\')を付けて終了する必要があります。
lpszVolumeNameLPCWSTRinボリュームのボリューム GUID パスです。この文字列は "\\?\Volume{GUID}\" の形式である必要があり、ここで GUID はボリュームを識別する GUID です。"\\?\" はパス解析を無効にし、 Naming a Volume で説明されているとおり、パスの一部としては無視されます。

戻り値の型: BOOL

公式ドキュメント

ボリュームをドライブ文字、または別のボリューム上のディレクトリに関連付けます。(Unicode)

戻り値

関数が成功した場合、戻り値は 0 以外の値になります。

関数が失敗した場合、戻り値は 0 になります。拡張エラー情報を取得するには、 GetLastError を呼び出します。

lpszVolumeMountPoint パラメーターにマウントされたフォルダーへのパスが含まれている場合、ディレクトリが空であっても GetLastErrorERROR_DIR_NOT_EMPTY を返します。

解説(Remarks)

この関数を使用してボリュームを別のボリューム上のディレクトリに関連付けると、その関連付けられたディレクトリは マウントされたフォルダー と呼ばれます。

ファイルやサブディレクトリを含むディレクトリにボリュームを関連付けることはエラーになります。この エラーは、システムディレクトリや隠しディレクトリ、その他のディレクトリで発生し、また システムファイルや隠しファイルでも発生します。

クラスター化されたディスク上のボリュームにマウントされたフォルダーを作成すると、特定の 状況下で予期せず削除されることがあります。これが起こらないようにマウントされたフォルダーを作成および構成する方法については、 Cluster Disk and Drive Connection Problems を参照してください。

Windows 8 および Windows Server 2012 では、この関数は次のテクノロジでサポートされています。

テクノロジ サポート
Server Message Block (SMB) 3.0 プロトコル いいえ
SMB 3.0 Transparent Failover (TFO) いいえ
SMB 3.0 with Scale-out File Shares (SO) いいえ
Cluster Shared Volume File System (CsvFS) いいえ
Resilient File System (ReFS) いいえ

SMB はボリューム管理関数をサポートしていません。CsvFS の場合、新しいマウントポイントはクラスター内の他のノードに複製されません。

例については、 Creating a Mounted Folder を参照してください。

メモ

winbase.h ヘッダーは SetVolumeMountPoint を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI バージョンまたは Unicode バージョンを自動的に選択するエイリアスとして定義しています。エンコーディング中立なエイリアスの使用と、エンコーディング中立でないコードを混在させると、コンパイルエラーまたは実行時エラーを引き起こす不一致につながる可能性があります。詳細については、Conventions for Function Prototypes を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// 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 <MarshalAs(UnmanagedType.Bool)> 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 版の利用を推奨。
const std = @import("std");

extern "kernel32" fn SetVolumeMountPointW(
    lpszVolumeMountPoint: [*c]const u16, // LPCWSTR
    lpszVolumeName: [*c]const u16 // LPCWSTR
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc SetVolumeMountPointW(
    lpszVolumeMountPoint: WideCString,  # LPCWSTR
    lpszVolumeName: WideCString  # LPCWSTR
): int32 {.importc: "SetVolumeMountPointW", stdcall, dynlib: "KERNEL32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "kernel32");
extern(Windows)
int SetVolumeMountPointW(
    const(wchar)* lpszVolumeMountPoint,   // LPCWSTR
    const(wchar)* lpszVolumeName   // LPCWSTR
);
ccall((:SetVolumeMountPointW, "KERNEL32.dll"), stdcall, Int32,
      (Cwstring, Cwstring),
      lpszVolumeMountPoint, lpszVolumeName)
# lpszVolumeMountPoint : LPCWSTR -> Cwstring
# lpszVolumeName : LPCWSTR -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetVolumeMountPointW(
    const uint16_t* lpszVolumeMountPoint,
    const uint16_t* lpszVolumeName);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.SetVolumeMountPointW(lpszVolumeMountPoint, lpszVolumeName)
-- lpszVolumeMountPoint : LPCWSTR
-- lpszVolumeName : LPCWSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const SetVolumeMountPointW = lib.func('__stdcall', 'SetVolumeMountPointW', 'int32_t', ['str16', 'str16']);
// SetVolumeMountPointW(lpszVolumeMountPoint, lpszVolumeName)
// lpszVolumeMountPoint : LPCWSTR -> 'str16'
// lpszVolumeName : LPCWSTR -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  SetVolumeMountPointW: { parameters: ["buffer", "buffer"], result: "i32" },
});
// lib.symbols.SetVolumeMountPointW(lpszVolumeMountPoint, lpszVolumeName)
// lpszVolumeMountPoint : LPCWSTR -> "buffer"
// lpszVolumeName : LPCWSTR -> "buffer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetVolumeMountPointW(
    const uint16_t* lpszVolumeMountPoint,
    const uint16_t* lpszVolumeName);
C, "KERNEL32.dll");
// $ffi->SetVolumeMountPointW(lpszVolumeMountPoint, lpszVolumeName);
// lpszVolumeMountPoint : LPCWSTR
// lpszVolumeName : LPCWSTR
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Kernel32 extends StdCallLibrary {
    Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class, W32APIOptions.UNICODE_OPTIONS);
    boolean SetVolumeMountPointW(
        WString lpszVolumeMountPoint,   // LPCWSTR
        WString lpszVolumeName   // LPCWSTR
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("kernel32")]
lib LibKERNEL32
  fun SetVolumeMountPointW = SetVolumeMountPointW(
    lpszVolumeMountPoint : UInt16*,   # LPCWSTR
    lpszVolumeName : UInt16*   # LPCWSTR
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SetVolumeMountPointWNative = Int32 Function(Pointer<Utf16>, Pointer<Utf16>);
typedef SetVolumeMountPointWDart = int Function(Pointer<Utf16>, Pointer<Utf16>);
final SetVolumeMountPointW = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<SetVolumeMountPointWNative, SetVolumeMountPointWDart>('SetVolumeMountPointW');
// lpszVolumeMountPoint : LPCWSTR -> Pointer<Utf16>
// lpszVolumeName : LPCWSTR -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetVolumeMountPointW(
  lpszVolumeMountPoint: PWideChar;   // LPCWSTR
  lpszVolumeName: PWideChar   // LPCWSTR
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'SetVolumeMountPointW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetVolumeMountPointW"
  c_SetVolumeMountPointW :: CWString -> CWString -> IO CInt
-- lpszVolumeMountPoint : LPCWSTR -> CWString
-- lpszVolumeName : LPCWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setvolumemountpointw =
  foreign "SetVolumeMountPointW"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> returning int32_t)
(* lpszVolumeMountPoint : LPCWSTR -> (ptr uint16_t) *)
(* lpszVolumeName : LPCWSTR -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("SetVolumeMountPointW" set-volume-mount-point-w :convention :stdcall) :int32
  (lpsz-volume-mount-point (:string :encoding :utf-16le))   ; LPCWSTR
  (lpsz-volume-name (:string :encoding :utf-16le)))   ; LPCWSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetVolumeMountPointW = Win32::API::More->new('KERNEL32',
    'BOOL SetVolumeMountPointW(LPCWSTR lpszVolumeMountPoint, LPCWSTR lpszVolumeName)');
# my $ret = $SetVolumeMountPointW->Call($lpszVolumeMountPoint, $lpszVolumeName);
# lpszVolumeMountPoint : LPCWSTR -> LPCWSTR
# lpszVolumeName : LPCWSTR -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
公式の関連項目