SetVolumeMountPointA
関数シグネチャ
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
BOOL SetVolumeMountPointA(
LPCSTR lpszVolumeMountPoint,
LPCSTR lpszVolumeName
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lpszVolumeMountPoint | LPCSTR | in | ボリュームに関連付けるユーザーモードのパス。これはドライブ文字(例: "X:\")、または 別のボリューム上のディレクトリ(例: "Y:\MountX\")を指定できます。文字列は末尾のバックスラッシュ('\')で終わる必要があります。 |
| lpszVolumeName | LPCSTR | in | ボリュームのボリューム GUID パス。この文字列は "\\?\Volume{GUID}\" の形式である必要があり、GUID はそのボリュームを識別する GUID です。"\\?\" はパスの解析を無効にし、 Naming a Volume で説明されているとおり、パスの一部としては無視されます。 |
戻り値の型: BOOL
公式ドキュメント
ボリュームをドライブ文字、または別のボリューム上のディレクトリに関連付けます。(ANSI)
戻り値
関数が成功した場合、戻り値は 0 以外になります。
関数が失敗した場合、戻り値は 0 になります。拡張エラー情報を取得するには、 GetLastError を呼び出します。
lpszVolumeMountPoint パラメーターにマウントされたフォルダーへのパスが含まれている場合、ディレクトリが空であっても、GetLastError は ERROR_DIR_NOT_EMPTY を返します。
解説(Remarks)
この関数を使用してボリュームを別のボリューム上のディレクトリに関連付ける場合、関連付けられたディレクトリは マウントされたフォルダー と呼ばれます。
ファイルまたはサブディレクトリを含むディレクトリにボリュームを関連付けることはエラーになります。この エラーは、システムディレクトリや隠しディレクトリを含むあらゆるディレクトリで発生し、また システムファイルや隠しファイルについても発生します。
クラスター化されたディスク上のボリュームにマウントされたフォルダーを作成した場合、特定の 状況下で予期せず削除されることがあります。これを回避するためのマウントされたフォルダーの作成および構成方法については、 Cluster Disk and Drive Connection Problems を参照してください。
Windows 8 および Windows Server 2012 では、この関数は次のテクノロジによってサポートされています。
| テクノロジ | サポート |
|---|---|
| Server Message Block (SMB) 3.0 protocol | いいえ |
| 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 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 <MarshalAs(UnmanagedType.Bool)> 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 // BOOLfunction 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)。const std = @import("std");
extern "kernel32" fn SetVolumeMountPointA(
lpszVolumeMountPoint: [*c]const u8, // LPCSTR
lpszVolumeName: [*c]const u8 // LPCSTR
) callconv(std.os.windows.WINAPI) i32;proc SetVolumeMountPointA(
lpszVolumeMountPoint: cstring, # LPCSTR
lpszVolumeName: cstring # LPCSTR
): int32 {.importc: "SetVolumeMountPointA", stdcall, dynlib: "KERNEL32.dll".}pragma(lib, "kernel32");
extern(Windows)
int SetVolumeMountPointA(
const(char)* lpszVolumeMountPoint, // LPCSTR
const(char)* lpszVolumeName // LPCSTR
);ccall((:SetVolumeMountPointA, "KERNEL32.dll"), stdcall, Int32,
(Cstring, Cstring),
lpszVolumeMountPoint, lpszVolumeName)
# lpszVolumeMountPoint : LPCSTR -> Cstring
# lpszVolumeName : LPCSTR -> Cstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SetVolumeMountPointA(
const char* lpszVolumeMountPoint,
const char* lpszVolumeName);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.SetVolumeMountPointA(lpszVolumeMountPoint, lpszVolumeName)
-- lpszVolumeMountPoint : LPCSTR
-- lpszVolumeName : LPCSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const SetVolumeMountPointA = lib.func('__stdcall', 'SetVolumeMountPointA', 'int32_t', ['str', 'str']);
// SetVolumeMountPointA(lpszVolumeMountPoint, lpszVolumeName)
// lpszVolumeMountPoint : LPCSTR -> 'str'
// lpszVolumeName : LPCSTR -> 'str'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
SetVolumeMountPointA: { parameters: ["buffer", "buffer"], result: "i32" },
});
// lib.symbols.SetVolumeMountPointA(lpszVolumeMountPoint, lpszVolumeName)
// lpszVolumeMountPoint : LPCSTR -> "buffer"
// lpszVolumeName : LPCSTR -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetVolumeMountPointA(
const char* lpszVolumeMountPoint,
const char* lpszVolumeName);
C, "KERNEL32.dll");
// $ffi->SetVolumeMountPointA(lpszVolumeMountPoint, lpszVolumeName);
// lpszVolumeMountPoint : LPCSTR
// lpszVolumeName : LPCSTR
// 構造体/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.ASCII_OPTIONS);
boolean SetVolumeMountPointA(
String lpszVolumeMountPoint, // LPCSTR
String lpszVolumeName // LPCSTR
);
}@[Link("kernel32")]
lib LibKERNEL32
fun SetVolumeMountPointA = SetVolumeMountPointA(
lpszVolumeMountPoint : UInt8*, # LPCSTR
lpszVolumeName : UInt8* # LPCSTR
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetVolumeMountPointANative = Int32 Function(Pointer<Utf8>, Pointer<Utf8>);
typedef SetVolumeMountPointADart = int Function(Pointer<Utf8>, Pointer<Utf8>);
final SetVolumeMountPointA = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<SetVolumeMountPointANative, SetVolumeMountPointADart>('SetVolumeMountPointA');
// lpszVolumeMountPoint : LPCSTR -> Pointer<Utf8>
// lpszVolumeName : LPCSTR -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetVolumeMountPointA(
lpszVolumeMountPoint: PAnsiChar; // LPCSTR
lpszVolumeName: PAnsiChar // LPCSTR
): BOOL; stdcall;
external 'KERNEL32.dll' name 'SetVolumeMountPointA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetVolumeMountPointA"
c_SetVolumeMountPointA :: CString -> CString -> IO CInt
-- lpszVolumeMountPoint : LPCSTR -> CString
-- lpszVolumeName : LPCSTR -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setvolumemountpointa =
foreign "SetVolumeMountPointA"
(string @-> string @-> returning int32_t)
(* lpszVolumeMountPoint : LPCSTR -> string *)
(* lpszVolumeName : LPCSTR -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("SetVolumeMountPointA" set-volume-mount-point-a :convention :stdcall) :int32
(lpsz-volume-mount-point :string) ; LPCSTR
(lpsz-volume-name :string)) ; LPCSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetVolumeMountPointA = Win32::API::More->new('KERNEL32',
'BOOL SetVolumeMountPointA(LPCSTR lpszVolumeMountPoint, LPCSTR lpszVolumeName)');
# my $ret = $SetVolumeMountPointA->Call($lpszVolumeMountPoint, $lpszVolumeName);
# lpszVolumeMountPoint : LPCSTR -> LPCSTR
# lpszVolumeName : LPCSTR -> LPCSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f SetVolumeMountPointW (Unicode版) — 指定パスにボリュームをマウントする(Unicode版)。
- f DeleteVolumeMountPointA — 指定したボリュームマウントポイントを削除する(ANSI版)。
- f GetVolumeNameForVolumeMountPointA — マウントポイントから一意のボリューム名を取得する(ANSI版)。
- f GetVolumePathNameA — ファイルパスが属するボリュームのマウントパスを取得する(ANSI版)。