DefineDosDeviceA
関数シグネチャ
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
BOOL DefineDosDeviceA(
DEFINE_DOS_DEVICE_FLAGS dwFlags,
LPCSTR lpDeviceName,
LPCSTR lpTargetPath // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| dwFlags | DEFINE_DOS_DEVICE_FLAGS | in | DefineDosDevice 関数の制御可能な動作を指定します。このパラメーターには、次の値のうち 1 つ以上を指定できます。
| ||||||||||
| lpDeviceName | LPCSTR | in | 関数が定義、再定義、または削除するデバイスを指定する MS-DOS デバイス名文字列へのポインター。ドライブ文字を定義、再定義、または削除する場合を除き、デバイス名文字列の末尾の文字をコロンにすることはできません。たとえば、ドライブ C は文字列 "C:" になります。いかなる場合も、末尾のバックスラッシュ ("") は使用できません。 | ||||||||||
| lpTargetPath | LPCSTR | inoptional | このデバイスを実装するパス文字列へのポインター。DDD_RAW_TARGET_PATH フラグが指定されている場合を除き、この文字列は MS-DOS パス文字列です。指定されている場合は、この文字列はパス文字列です。 |
戻り値の型: BOOL
公式ドキュメント
MS-DOS デバイス名を定義、再定義、または削除します。(DefineDosDeviceA)
戻り値
関数が成功した場合、戻り値は 0 以外の値になります。
関数が失敗した場合、戻り値は 0 になります。拡張エラー情報を取得するには、GetLastError を呼び出してください。
解説(Remarks)
MS-DOS デバイス名は、オブジェクト名前空間内にジャンクションとして格納されます。MS-DOS パスを対応するパスに変換するコードは、これらのジャンクションを使用して MS-DOS デバイスおよびドライブ文字をマップします。DefineDosDevice 関数を使用すると、アプリケーションは MS-DOS デバイス名前空間の実装に使用されるジャンクションを変更できます。
特定の MS-DOS デバイス名の現在のマッピングを取得したり、システムが認識しているすべての MS-DOS デバイスの一覧を取得したりするには、QueryDosDevice 関数を使用してください。
再起動後も保持され、ネットワーク共有ではないドライブ文字の割り当てを定義するには、SetVolumeMountPoint 関数を使用してください。マウントするボリュームに既にドライブ文字が割り当てられている場合は、DeleteVolumeMountPoint 関数を使用してその割り当てを削除してください。
システム起動時に定義されたドライブ文字およびデバイス名は、ユーザーが管理者でない限り、再定義や削除から保護されます。
Windows XP 以降では、この関数は、"LocalSystem" コンテキストで実行されていない呼び出し元に対して、そのローカル MS-DOS デバイス名前空間内にデバイス名を作成します。呼び出し元が "LocalSystem" コンテキストで実行されている場合、関数はグローバル MS-DOS デバイス名前空間にデバイス名を作成します。詳細については、Defining an MS DOS Device Name および File Names, Paths, and Namespaces を参照してください。
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 の場合、新しい名前はクラスター内の他のノードに複製されません。
例
例については、Editing Drive Letter Assignments を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
BOOL DefineDosDeviceA(
DEFINE_DOS_DEVICE_FLAGS dwFlags,
LPCSTR lpDeviceName,
LPCSTR lpTargetPath // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool DefineDosDeviceA(
uint dwFlags, // DEFINE_DOS_DEVICE_FLAGS
[MarshalAs(UnmanagedType.LPStr)] string lpDeviceName, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] string lpTargetPath // LPCSTR optional
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function DefineDosDeviceA(
dwFlags As UInteger, ' DEFINE_DOS_DEVICE_FLAGS
<MarshalAs(UnmanagedType.LPStr)> lpDeviceName As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> lpTargetPath As String ' LPCSTR optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' dwFlags : DEFINE_DOS_DEVICE_FLAGS
' lpDeviceName : LPCSTR
' lpTargetPath : LPCSTR optional
Declare PtrSafe Function DefineDosDeviceA Lib "kernel32" ( _
ByVal dwFlags As Long, _
ByVal lpDeviceName As String, _
ByVal lpTargetPath As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
DefineDosDeviceA = ctypes.windll.kernel32.DefineDosDeviceA
DefineDosDeviceA.restype = wintypes.BOOL
DefineDosDeviceA.argtypes = [
wintypes.DWORD, # dwFlags : DEFINE_DOS_DEVICE_FLAGS
wintypes.LPCSTR, # lpDeviceName : LPCSTR
wintypes.LPCSTR, # lpTargetPath : LPCSTR optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
DefineDosDeviceA = Fiddle::Function.new(
lib['DefineDosDeviceA'],
[
-Fiddle::TYPE_INT, # dwFlags : DEFINE_DOS_DEVICE_FLAGS
Fiddle::TYPE_VOIDP, # lpDeviceName : LPCSTR
Fiddle::TYPE_VOIDP, # lpTargetPath : LPCSTR optional
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn DefineDosDeviceA(
dwFlags: u32, // DEFINE_DOS_DEVICE_FLAGS
lpDeviceName: *const u8, // LPCSTR
lpTargetPath: *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 DefineDosDeviceA(uint dwFlags, [MarshalAs(UnmanagedType.LPStr)] string lpDeviceName, [MarshalAs(UnmanagedType.LPStr)] string lpTargetPath);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_DefineDosDeviceA' -Namespace Win32 -PassThru
# $api::DefineDosDeviceA(dwFlags, lpDeviceName, lpTargetPath)#uselib "KERNEL32.dll"
#func global DefineDosDeviceA "DefineDosDeviceA" sptr, sptr, sptr
; DefineDosDeviceA dwFlags, lpDeviceName, lpTargetPath ; 戻り値は stat
; dwFlags : DEFINE_DOS_DEVICE_FLAGS -> "sptr"
; lpDeviceName : LPCSTR -> "sptr"
; lpTargetPath : LPCSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global DefineDosDeviceA "DefineDosDeviceA" int, str, str
; res = DefineDosDeviceA(dwFlags, lpDeviceName, lpTargetPath)
; dwFlags : DEFINE_DOS_DEVICE_FLAGS -> "int"
; lpDeviceName : LPCSTR -> "str"
; lpTargetPath : LPCSTR optional -> "str"; BOOL DefineDosDeviceA(DEFINE_DOS_DEVICE_FLAGS dwFlags, LPCSTR lpDeviceName, LPCSTR lpTargetPath)
#uselib "KERNEL32.dll"
#cfunc global DefineDosDeviceA "DefineDosDeviceA" int, str, str
; res = DefineDosDeviceA(dwFlags, lpDeviceName, lpTargetPath)
; dwFlags : DEFINE_DOS_DEVICE_FLAGS -> "int"
; lpDeviceName : LPCSTR -> "str"
; lpTargetPath : LPCSTR optional -> "str"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procDefineDosDeviceA = kernel32.NewProc("DefineDosDeviceA")
)
// dwFlags (DEFINE_DOS_DEVICE_FLAGS), lpDeviceName (LPCSTR), lpTargetPath (LPCSTR optional)
r1, _, err := procDefineDosDeviceA.Call(
uintptr(dwFlags),
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpDeviceName))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpTargetPath))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction DefineDosDeviceA(
dwFlags: DWORD; // DEFINE_DOS_DEVICE_FLAGS
lpDeviceName: PAnsiChar; // LPCSTR
lpTargetPath: PAnsiChar // LPCSTR optional
): BOOL; stdcall;
external 'KERNEL32.dll' name 'DefineDosDeviceA';result := DllCall("KERNEL32\DefineDosDeviceA"
, "UInt", dwFlags ; DEFINE_DOS_DEVICE_FLAGS
, "AStr", lpDeviceName ; LPCSTR
, "AStr", lpTargetPath ; LPCSTR optional
, "Int") ; return: BOOL●DefineDosDeviceA(dwFlags, lpDeviceName, lpTargetPath) = DLL("KERNEL32.dll", "bool DefineDosDeviceA(dword, char*, char*)")
# 呼び出し: DefineDosDeviceA(dwFlags, lpDeviceName, lpTargetPath)
# dwFlags : DEFINE_DOS_DEVICE_FLAGS -> "dword"
# lpDeviceName : LPCSTR -> "char*"
# lpTargetPath : LPCSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "kernel32" fn DefineDosDeviceA(
dwFlags: u32, // DEFINE_DOS_DEVICE_FLAGS
lpDeviceName: [*c]const u8, // LPCSTR
lpTargetPath: [*c]const u8 // LPCSTR optional
) callconv(std.os.windows.WINAPI) i32;proc DefineDosDeviceA(
dwFlags: uint32, # DEFINE_DOS_DEVICE_FLAGS
lpDeviceName: cstring, # LPCSTR
lpTargetPath: cstring # LPCSTR optional
): int32 {.importc: "DefineDosDeviceA", stdcall, dynlib: "KERNEL32.dll".}pragma(lib, "kernel32");
extern(Windows)
int DefineDosDeviceA(
uint dwFlags, // DEFINE_DOS_DEVICE_FLAGS
const(char)* lpDeviceName, // LPCSTR
const(char)* lpTargetPath // LPCSTR optional
);ccall((:DefineDosDeviceA, "KERNEL32.dll"), stdcall, Int32,
(UInt32, Cstring, Cstring),
dwFlags, lpDeviceName, lpTargetPath)
# dwFlags : DEFINE_DOS_DEVICE_FLAGS -> UInt32
# lpDeviceName : LPCSTR -> Cstring
# lpTargetPath : LPCSTR optional -> Cstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t DefineDosDeviceA(
uint32_t dwFlags,
const char* lpDeviceName,
const char* lpTargetPath);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.DefineDosDeviceA(dwFlags, lpDeviceName, lpTargetPath)
-- dwFlags : DEFINE_DOS_DEVICE_FLAGS
-- lpDeviceName : LPCSTR
-- lpTargetPath : LPCSTR optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const DefineDosDeviceA = lib.func('__stdcall', 'DefineDosDeviceA', 'int32_t', ['uint32_t', 'str', 'str']);
// DefineDosDeviceA(dwFlags, lpDeviceName, lpTargetPath)
// dwFlags : DEFINE_DOS_DEVICE_FLAGS -> 'uint32_t'
// lpDeviceName : LPCSTR -> 'str'
// lpTargetPath : LPCSTR optional -> 'str'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
DefineDosDeviceA: { parameters: ["u32", "buffer", "buffer"], result: "i32" },
});
// lib.symbols.DefineDosDeviceA(dwFlags, lpDeviceName, lpTargetPath)
// dwFlags : DEFINE_DOS_DEVICE_FLAGS -> "u32"
// lpDeviceName : LPCSTR -> "buffer"
// lpTargetPath : LPCSTR optional -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t DefineDosDeviceA(
uint32_t dwFlags,
const char* lpDeviceName,
const char* lpTargetPath);
C, "KERNEL32.dll");
// $ffi->DefineDosDeviceA(dwFlags, lpDeviceName, lpTargetPath);
// dwFlags : DEFINE_DOS_DEVICE_FLAGS
// lpDeviceName : LPCSTR
// lpTargetPath : LPCSTR optional
// 構造体/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 DefineDosDeviceA(
int dwFlags, // DEFINE_DOS_DEVICE_FLAGS
String lpDeviceName, // LPCSTR
String lpTargetPath // LPCSTR optional
);
}@[Link("kernel32")]
lib LibKERNEL32
fun DefineDosDeviceA = DefineDosDeviceA(
dwFlags : UInt32, # DEFINE_DOS_DEVICE_FLAGS
lpDeviceName : UInt8*, # LPCSTR
lpTargetPath : UInt8* # LPCSTR optional
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef DefineDosDeviceANative = Int32 Function(Uint32, Pointer<Utf8>, Pointer<Utf8>);
typedef DefineDosDeviceADart = int Function(int, Pointer<Utf8>, Pointer<Utf8>);
final DefineDosDeviceA = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<DefineDosDeviceANative, DefineDosDeviceADart>('DefineDosDeviceA');
// dwFlags : DEFINE_DOS_DEVICE_FLAGS -> Uint32
// lpDeviceName : LPCSTR -> Pointer<Utf8>
// lpTargetPath : LPCSTR optional -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function DefineDosDeviceA(
dwFlags: DWORD; // DEFINE_DOS_DEVICE_FLAGS
lpDeviceName: PAnsiChar; // LPCSTR
lpTargetPath: PAnsiChar // LPCSTR optional
): BOOL; stdcall;
external 'KERNEL32.dll' name 'DefineDosDeviceA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DefineDosDeviceA"
c_DefineDosDeviceA :: Word32 -> CString -> CString -> IO CInt
-- dwFlags : DEFINE_DOS_DEVICE_FLAGS -> Word32
-- lpDeviceName : LPCSTR -> CString
-- lpTargetPath : LPCSTR optional -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let definedosdevicea =
foreign "DefineDosDeviceA"
(uint32_t @-> string @-> string @-> returning int32_t)
(* dwFlags : DEFINE_DOS_DEVICE_FLAGS -> uint32_t *)
(* lpDeviceName : LPCSTR -> string *)
(* lpTargetPath : LPCSTR optional -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("DefineDosDeviceA" define-dos-device-a :convention :stdcall) :int32
(dw-flags :uint32) ; DEFINE_DOS_DEVICE_FLAGS
(lp-device-name :string) ; LPCSTR
(lp-target-path :string)) ; LPCSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $DefineDosDeviceA = Win32::API::More->new('KERNEL32',
'BOOL DefineDosDeviceA(DWORD dwFlags, LPCSTR lpDeviceName, LPCSTR lpTargetPath)');
# my $ret = $DefineDosDeviceA->Call($dwFlags, $lpDeviceName, $lpTargetPath);
# dwFlags : DEFINE_DOS_DEVICE_FLAGS -> DWORD
# lpDeviceName : LPCSTR -> LPCSTR
# lpTargetPath : LPCSTR optional -> LPCSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f DefineDosDeviceW (Unicode版) — MS-DOSデバイス名とパスのマッピングを定義または削除する。
- f DeleteVolumeMountPointA — 指定したボリュームマウントポイントを削除する(ANSI版)。
- f QueryDosDeviceA — MS-DOSデバイス名に対応するパス情報を取得する(ANSI版)。
- f SetVolumeMountPointA — 指定パスにボリュームをマウントする(ANSI版)。