QueryDosDeviceW
関数シグネチャ
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
DWORD QueryDosDeviceW(
LPCWSTR lpDeviceName, // optional
LPWSTR lpTargetPath, // optional
DWORD ucchMax
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lpDeviceName | LPCWSTR | inoptional | クエリの対象を指定する MS-DOS デバイス名文字列です。デバイス名の末尾に バックスラッシュを付けることはできません。たとえば "C:\" ではなく "C:" を使用します。 このパラメーターは NULL にすることができます。その場合、 QueryDosDevice 関数は既存のすべての MS-DOS デバイス名の一覧を lpTargetPath が指す バッファーに格納します。 |
| lpTargetPath | LPWSTR | outoptional | クエリの結果を受け取るバッファーへのポインターです。関数はこのバッファーを 1 つ以上の null 終端文字列で満たします。最後の null 終端文字列の後には、さらに NULL が続きます。 lpDeviceName が NULL 以外の場合、関数は lpDeviceName で指定された 特定の MS-DOS デバイスに関する情報を取得します。バッファーに格納される最初の null 終端文字列は、そのデバイスの現在のマッピングです。その他の null 終端 文字列は、そのデバイスについて削除されずに残っている過去のマッピングを表します。 lpDeviceName が NULL の場合、関数は既存のすべての MS-DOS デバイス名の一覧を取得します。バッファーに格納される各 null 終端文字列は、既存の MS-DOS デバイスの名前です。たとえば \Device\HarddiskVolume1 や \Device\Floppy0 です。 |
| ucchMax | DWORD | in | lpTargetPath が指すバッファーに格納できる TCHAR の最大数です。 |
戻り値の型: DWORD
公式ドキュメント
MS-DOS デバイス名に関する情報を取得します。(QueryDosDeviceW)
戻り値
関数が成功した場合、戻り値は lpTargetPath が指すバッファーに格納された TCHAR の数です。
関数が失敗した場合、戻り値は 0 です。拡張エラー情報を取得するには、 GetLastError を呼び出します。
バッファーが小さすぎる場合、関数は失敗し、最後のエラーコードは ERROR_INSUFFICIENT_BUFFER になります。
解説(Remarks)
DefineDosDevice 関数を使用すると、アプリケーションは MS-DOS デバイス名前空間を実装するために使用されるジャンクションを作成および変更できます。
Windows Server 2003 および Windows XP: QueryDosDevice は、指定されたデバイス名について まずローカル MS-DOS デバイス名前空間を検索します。デバイス名が見つからない場合、関数は次に グローバル MS-DOS デバイス名前空間を検索します。
既存のすべての MS-DOS デバイス名をクエリした場合、返されるデバイス名の一覧は、 "LocalSystem" コンテキストで実行されているかどうかに依存します。実行されている場合、グローバル MS-DOS デバイス名前空間に含まれるデバイス名のみが返されます。そうでない場合、グローバルおよびローカル MS-DOS デバイス名前空間のデバイス名を連結したものが返されます。あるデバイス名が両方の名前空間に存在する場合、 QueryDosDevice はローカル MS-DOS デバイス名前空間のエントリを返します。
グローバルおよびローカル MS-DOS デバイス名前空間と、MS-DOS デバイス名のアクセシビリティの変更に関する詳細は、 Defining an MS DOS Device Name を参照してください。
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 はボリューム管理関数をサポートしていません。
例
例については、 Obtaining a File Name From a File Handle または Displaying Volume Paths を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 版の利用を推奨。const std = @import("std");
extern "kernel32" fn QueryDosDeviceW(
lpDeviceName: [*c]const u16, // LPCWSTR optional
lpTargetPath: [*c]u16, // LPWSTR optional, out
ucchMax: u32 // DWORD
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc QueryDosDeviceW(
lpDeviceName: WideCString, # LPCWSTR optional
lpTargetPath: ptr uint16, # LPWSTR optional, out
ucchMax: uint32 # DWORD
): uint32 {.importc: "QueryDosDeviceW", stdcall, dynlib: "KERNEL32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "kernel32");
extern(Windows)
uint QueryDosDeviceW(
const(wchar)* lpDeviceName, // LPCWSTR optional
wchar* lpTargetPath, // LPWSTR optional, out
uint ucchMax // DWORD
);ccall((:QueryDosDeviceW, "KERNEL32.dll"), stdcall, UInt32,
(Cwstring, Ptr{UInt16}, UInt32),
lpDeviceName, lpTargetPath, ucchMax)
# lpDeviceName : LPCWSTR optional -> Cwstring
# lpTargetPath : LPWSTR optional, out -> Ptr{UInt16}
# ucchMax : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t QueryDosDeviceW(
const uint16_t* lpDeviceName,
uint16_t* lpTargetPath,
uint32_t ucchMax);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.QueryDosDeviceW(lpDeviceName, lpTargetPath, ucchMax)
-- lpDeviceName : LPCWSTR optional
-- lpTargetPath : LPWSTR optional, out
-- ucchMax : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const QueryDosDeviceW = lib.func('__stdcall', 'QueryDosDeviceW', 'uint32_t', ['str16', 'uint16_t *', 'uint32_t']);
// QueryDosDeviceW(lpDeviceName, lpTargetPath, ucchMax)
// lpDeviceName : LPCWSTR optional -> 'str16'
// lpTargetPath : LPWSTR optional, out -> 'uint16_t *'
// ucchMax : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
QueryDosDeviceW: { parameters: ["buffer", "buffer", "u32"], result: "u32" },
});
// lib.symbols.QueryDosDeviceW(lpDeviceName, lpTargetPath, ucchMax)
// lpDeviceName : LPCWSTR optional -> "buffer"
// lpTargetPath : LPWSTR optional, out -> "buffer"
// ucchMax : DWORD -> "u32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t QueryDosDeviceW(
const uint16_t* lpDeviceName,
uint16_t* lpTargetPath,
uint32_t ucchMax);
C, "KERNEL32.dll");
// $ffi->QueryDosDeviceW(lpDeviceName, lpTargetPath, ucchMax);
// lpDeviceName : LPCWSTR optional
// lpTargetPath : LPWSTR optional, out
// ucchMax : DWORD
// 構造体/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.UNICODE_OPTIONS);
int QueryDosDeviceW(
WString lpDeviceName, // LPCWSTR optional
char[] lpTargetPath, // LPWSTR optional, out
int ucchMax // DWORD
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("kernel32")]
lib LibKERNEL32
fun QueryDosDeviceW = QueryDosDeviceW(
lpDeviceName : UInt16*, # LPCWSTR optional
lpTargetPath : UInt16*, # LPWSTR optional, out
ucchMax : UInt32 # DWORD
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef QueryDosDeviceWNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Uint32);
typedef QueryDosDeviceWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, int);
final QueryDosDeviceW = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<QueryDosDeviceWNative, QueryDosDeviceWDart>('QueryDosDeviceW');
// lpDeviceName : LPCWSTR optional -> Pointer<Utf16>
// lpTargetPath : LPWSTR optional, out -> Pointer<Utf16>
// ucchMax : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function QueryDosDeviceW(
lpDeviceName: PWideChar; // LPCWSTR optional
lpTargetPath: PWideChar; // LPWSTR optional, out
ucchMax: DWORD // DWORD
): DWORD; stdcall;
external 'KERNEL32.dll' name 'QueryDosDeviceW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "QueryDosDeviceW"
c_QueryDosDeviceW :: CWString -> CWString -> Word32 -> IO Word32
-- lpDeviceName : LPCWSTR optional -> CWString
-- lpTargetPath : LPWSTR optional, out -> CWString
-- ucchMax : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let querydosdevicew =
foreign "QueryDosDeviceW"
((ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> returning uint32_t)
(* lpDeviceName : LPCWSTR optional -> (ptr uint16_t) *)
(* lpTargetPath : LPWSTR optional, out -> (ptr uint16_t) *)
(* ucchMax : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("QueryDosDeviceW" query-dos-device-w :convention :stdcall) :uint32
(lp-device-name (:string :encoding :utf-16le)) ; LPCWSTR optional
(lp-target-path :pointer) ; LPWSTR optional, out
(ucch-max :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $QueryDosDeviceW = Win32::API::More->new('KERNEL32',
'DWORD QueryDosDeviceW(LPCWSTR lpDeviceName, LPWSTR lpTargetPath, DWORD ucchMax)');
# my $ret = $QueryDosDeviceW->Call($lpDeviceName, $lpTargetPath, $ucchMax);
# lpDeviceName : LPCWSTR optional -> LPCWSTR
# lpTargetPath : LPWSTR optional, out -> LPWSTR
# ucchMax : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f QueryDosDeviceA (ANSI版) — MS-DOSデバイス名に対応するパス情報を取得する(ANSI版)。
- f DefineDosDeviceW — MS-DOSデバイス名とパスのマッピングを定義または削除する。