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

DefineDosDeviceW

関数
MS-DOSデバイス名とパスのマッピングを定義または削除する。
DLLKERNEL32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL DefineDosDeviceW(
    DEFINE_DOS_DEVICE_FLAGS dwFlags,
    LPCWSTR lpDeviceName,
    LPCWSTR lpTargetPath   // optional
);

パラメーター

名前方向
dwFlagsDEFINE_DOS_DEVICE_FLAGSin
lpDeviceNameLPCWSTRin
lpTargetPathLPCWSTRinoptional

戻り値の型: BOOL

各言語での呼び出し定義

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

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

DefineDosDeviceW = ctypes.windll.kernel32.DefineDosDeviceW
DefineDosDeviceW.restype = wintypes.BOOL
DefineDosDeviceW.argtypes = [
    wintypes.DWORD,  # dwFlags : DEFINE_DOS_DEVICE_FLAGS
    wintypes.LPCWSTR,  # lpDeviceName : LPCWSTR
    wintypes.LPCWSTR,  # lpTargetPath : LPCWSTR optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procDefineDosDeviceW = kernel32.NewProc("DefineDosDeviceW")
)

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