ホーム › Storage.FileSystem › DefineDosDeviceA
DefineDosDeviceA
関数MS-DOSデバイス名を定義・変更・削除する(ANSI版)。
シグネチャ
// 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 |
| lpDeviceName | LPCSTR | in |
| lpTargetPath | LPCSTR | inoptional |
戻り値の型: BOOL
各言語での呼び出し定義
// 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 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)。