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

QueryDosDeviceA

関数
MS-DOSデバイス名に対応するパス情報を取得する(ANSI版)。
DLLKERNEL32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// KERNEL32.dll  (ANSI / -A)
#include <windows.h>

DWORD QueryDosDeviceA(
    LPCSTR lpDeviceName,   // optional
    LPSTR lpTargetPath,   // optional
    DWORD ucchMax
);

パラメーター

名前方向
lpDeviceNameLPCSTRinoptional
lpTargetPathLPSTRoutoptional
ucchMaxDWORDin

戻り値の型: DWORD

各言語での呼び出し定義

// KERNEL32.dll  (ANSI / -A)
#include <windows.h>

DWORD QueryDosDeviceA(
    LPCSTR lpDeviceName,   // optional
    LPSTR lpTargetPath,   // optional
    DWORD ucchMax
);
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern uint QueryDosDeviceA(
    [MarshalAs(UnmanagedType.LPStr)] string lpDeviceName,   // LPCSTR optional
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpTargetPath,   // LPSTR optional, out
    uint ucchMax   // DWORD
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function QueryDosDeviceA(
    <MarshalAs(UnmanagedType.LPStr)> lpDeviceName As String,   ' LPCSTR optional
    <MarshalAs(UnmanagedType.LPStr)> lpTargetPath As System.Text.StringBuilder,   ' LPSTR optional, out
    ucchMax As UInteger   ' DWORD
) As UInteger
End Function
' lpDeviceName : LPCSTR optional
' lpTargetPath : LPSTR optional, out
' ucchMax : DWORD
Declare PtrSafe Function QueryDosDeviceA Lib "kernel32" ( _
    ByVal lpDeviceName As String, _
    ByVal lpTargetPath As String, _
    ByVal ucchMax As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

QueryDosDeviceA = ctypes.windll.kernel32.QueryDosDeviceA
QueryDosDeviceA.restype = wintypes.DWORD
QueryDosDeviceA.argtypes = [
    wintypes.LPCSTR,  # lpDeviceName : LPCSTR optional
    wintypes.LPSTR,  # lpTargetPath : LPSTR 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')
QueryDosDeviceA = Fiddle::Function.new(
  lib['QueryDosDeviceA'],
  [
    Fiddle::TYPE_VOIDP,  # lpDeviceName : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # lpTargetPath : LPSTR optional, out
    -Fiddle::TYPE_INT,  # ucchMax : DWORD
  ],
  -Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn QueryDosDeviceA(
        lpDeviceName: *const u8,  // LPCSTR optional
        lpTargetPath: *mut u8,  // LPSTR optional, out
        ucchMax: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern uint QueryDosDeviceA([MarshalAs(UnmanagedType.LPStr)] string lpDeviceName, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpTargetPath, uint ucchMax);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_QueryDosDeviceA' -Namespace Win32 -PassThru
# $api::QueryDosDeviceA(lpDeviceName, lpTargetPath, ucchMax)
#uselib "KERNEL32.dll"
#func global QueryDosDeviceA "QueryDosDeviceA" sptr, sptr, sptr
; QueryDosDeviceA lpDeviceName, varptr(lpTargetPath), ucchMax   ; 戻り値は stat
; lpDeviceName : LPCSTR optional -> "sptr"
; lpTargetPath : LPSTR optional, out -> "sptr"
; ucchMax : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global QueryDosDeviceA "QueryDosDeviceA" str, var, int
; res = QueryDosDeviceA(lpDeviceName, lpTargetPath, ucchMax)
; lpDeviceName : LPCSTR optional -> "str"
; lpTargetPath : LPSTR optional, out -> "var"
; ucchMax : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD QueryDosDeviceA(LPCSTR lpDeviceName, LPSTR lpTargetPath, DWORD ucchMax)
#uselib "KERNEL32.dll"
#cfunc global QueryDosDeviceA "QueryDosDeviceA" str, var, int
; res = QueryDosDeviceA(lpDeviceName, lpTargetPath, ucchMax)
; lpDeviceName : LPCSTR optional -> "str"
; lpTargetPath : LPSTR optional, out -> "var"
; ucchMax : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procQueryDosDeviceA = kernel32.NewProc("QueryDosDeviceA")
)

// lpDeviceName (LPCSTR optional), lpTargetPath (LPSTR optional, out), ucchMax (DWORD)
r1, _, err := procQueryDosDeviceA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpDeviceName))),
	uintptr(lpTargetPath),
	uintptr(ucchMax),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function QueryDosDeviceA(
  lpDeviceName: PAnsiChar;   // LPCSTR optional
  lpTargetPath: PAnsiChar;   // LPSTR optional, out
  ucchMax: DWORD   // DWORD
): DWORD; stdcall;
  external 'KERNEL32.dll' name 'QueryDosDeviceA';
result := DllCall("KERNEL32\QueryDosDeviceA"
    , "AStr", lpDeviceName   ; LPCSTR optional
    , "Ptr", lpTargetPath   ; LPSTR optional, out
    , "UInt", ucchMax   ; DWORD
    , "UInt")   ; return: DWORD
●QueryDosDeviceA(lpDeviceName, lpTargetPath, ucchMax) = DLL("KERNEL32.dll", "dword QueryDosDeviceA(char*, char*, dword)")
# 呼び出し: QueryDosDeviceA(lpDeviceName, lpTargetPath, ucchMax)
# lpDeviceName : LPCSTR optional -> "char*"
# lpTargetPath : LPSTR optional, out -> "char*"
# ucchMax : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。