ホーム › Storage.FileSystem › QueryDosDeviceW
QueryDosDeviceW
関数MS-DOSデバイス名に対応するターゲットパスを取得する。
シグネチャ
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
DWORD QueryDosDeviceW(
LPCWSTR lpDeviceName, // optional
LPWSTR lpTargetPath, // optional
DWORD ucchMax
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpDeviceName | LPCWSTR | inoptional |
| lpTargetPath | LPWSTR | outoptional |
| ucchMax | DWORD | in |
戻り値の型: DWORD
各言語での呼び出し定義
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
DWORD QueryDosDeviceW(
LPCWSTR lpDeviceName, // optional
LPWSTR lpTargetPath, // optional
DWORD ucchMax
);[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern uint QueryDosDeviceW(
[MarshalAs(UnmanagedType.LPWStr)] string lpDeviceName, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpTargetPath, // LPWSTR optional, out
uint ucchMax // DWORD
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function QueryDosDeviceW(
<MarshalAs(UnmanagedType.LPWStr)> lpDeviceName As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> lpTargetPath As System.Text.StringBuilder, ' LPWSTR optional, out
ucchMax As UInteger ' DWORD
) As UInteger
End Function' lpDeviceName : LPCWSTR optional
' lpTargetPath : LPWSTR optional, out
' ucchMax : DWORD
Declare PtrSafe Function QueryDosDeviceW Lib "kernel32" ( _
ByVal lpDeviceName As LongPtr, _
ByVal lpTargetPath As LongPtr, _
ByVal ucchMax As Long) 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
QueryDosDeviceW = ctypes.windll.kernel32.QueryDosDeviceW
QueryDosDeviceW.restype = wintypes.DWORD
QueryDosDeviceW.argtypes = [
wintypes.LPCWSTR, # lpDeviceName : LPCWSTR optional
wintypes.LPWSTR, # lpTargetPath : LPWSTR optional, out
wintypes.DWORD, # ucchMax : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
QueryDosDeviceW = Fiddle::Function.new(
lib['QueryDosDeviceW'],
[
Fiddle::TYPE_VOIDP, # lpDeviceName : LPCWSTR optional
Fiddle::TYPE_VOIDP, # lpTargetPath : LPWSTR optional, out
-Fiddle::TYPE_INT, # ucchMax : DWORD
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "kernel32")]
extern "system" {
fn QueryDosDeviceW(
lpDeviceName: *const u16, // LPCWSTR optional
lpTargetPath: *mut u16, // LPWSTR optional, out
ucchMax: u32 // DWORD
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern uint QueryDosDeviceW([MarshalAs(UnmanagedType.LPWStr)] string lpDeviceName, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpTargetPath, uint ucchMax);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_QueryDosDeviceW' -Namespace Win32 -PassThru
# $api::QueryDosDeviceW(lpDeviceName, lpTargetPath, ucchMax)#uselib "KERNEL32.dll"
#func global QueryDosDeviceW "QueryDosDeviceW" wptr, wptr, wptr
; QueryDosDeviceW lpDeviceName, varptr(lpTargetPath), ucchMax ; 戻り値は stat
; lpDeviceName : LPCWSTR optional -> "wptr"
; lpTargetPath : LPWSTR optional, out -> "wptr"
; ucchMax : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global QueryDosDeviceW "QueryDosDeviceW" wstr, var, int ; res = QueryDosDeviceW(lpDeviceName, lpTargetPath, ucchMax) ; lpDeviceName : LPCWSTR optional -> "wstr" ; lpTargetPath : LPWSTR optional, out -> "var" ; ucchMax : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global QueryDosDeviceW "QueryDosDeviceW" wstr, sptr, int ; res = QueryDosDeviceW(lpDeviceName, varptr(lpTargetPath), ucchMax) ; lpDeviceName : LPCWSTR optional -> "wstr" ; lpTargetPath : LPWSTR optional, out -> "sptr" ; ucchMax : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD QueryDosDeviceW(LPCWSTR lpDeviceName, LPWSTR lpTargetPath, DWORD ucchMax) #uselib "KERNEL32.dll" #cfunc global QueryDosDeviceW "QueryDosDeviceW" wstr, var, int ; res = QueryDosDeviceW(lpDeviceName, lpTargetPath, ucchMax) ; lpDeviceName : LPCWSTR optional -> "wstr" ; lpTargetPath : LPWSTR optional, out -> "var" ; ucchMax : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD QueryDosDeviceW(LPCWSTR lpDeviceName, LPWSTR lpTargetPath, DWORD ucchMax) #uselib "KERNEL32.dll" #cfunc global QueryDosDeviceW "QueryDosDeviceW" wstr, intptr, int ; res = QueryDosDeviceW(lpDeviceName, varptr(lpTargetPath), ucchMax) ; lpDeviceName : LPCWSTR optional -> "wstr" ; lpTargetPath : LPWSTR optional, out -> "intptr" ; ucchMax : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procQueryDosDeviceW = kernel32.NewProc("QueryDosDeviceW")
)
// lpDeviceName (LPCWSTR optional), lpTargetPath (LPWSTR optional, out), ucchMax (DWORD)
r1, _, err := procQueryDosDeviceW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpDeviceName))),
uintptr(lpTargetPath),
uintptr(ucchMax),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction QueryDosDeviceW(
lpDeviceName: PWideChar; // LPCWSTR optional
lpTargetPath: PWideChar; // LPWSTR optional, out
ucchMax: DWORD // DWORD
): DWORD; stdcall;
external 'KERNEL32.dll' name 'QueryDosDeviceW';result := DllCall("KERNEL32\QueryDosDeviceW"
, "WStr", lpDeviceName ; LPCWSTR optional
, "Ptr", lpTargetPath ; LPWSTR optional, out
, "UInt", ucchMax ; DWORD
, "UInt") ; return: DWORD●QueryDosDeviceW(lpDeviceName, lpTargetPath, ucchMax) = DLL("KERNEL32.dll", "dword QueryDosDeviceW(char*, char*, dword)")
# 呼び出し: QueryDosDeviceW(lpDeviceName, lpTargetPath, ucchMax)
# lpDeviceName : LPCWSTR optional -> "char*"
# lpTargetPath : LPWSTR optional, out -> "char*"
# ucchMax : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。