Win32 API 日本語リファレンス
ホームUI.Shell › DragQueryFileW

DragQueryFileW

関数
ドロップされたファイル名(Unicode)や個数を取得する。
DLLSHELL32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

DWORD DragQueryFileW(
    HDROP hDrop,
    DWORD iFile,
    LPWSTR lpszFile,   // optional
    DWORD cch
);

パラメーター

名前方向
hDropHDROPin
iFileDWORDin
lpszFileLPWSTRoutoptional
cchDWORDin

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD DragQueryFileW(
    HDROP hDrop,
    DWORD iFile,
    LPWSTR lpszFile,   // optional
    DWORD cch
);
[DllImport("SHELL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint DragQueryFileW(
    IntPtr hDrop,   // HDROP
    uint iFile,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpszFile,   // LPWSTR optional, out
    uint cch   // DWORD
);
<DllImport("SHELL32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function DragQueryFileW(
    hDrop As IntPtr,   ' HDROP
    iFile As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> lpszFile As System.Text.StringBuilder,   ' LPWSTR optional, out
    cch As UInteger   ' DWORD
) As UInteger
End Function
' hDrop : HDROP
' iFile : DWORD
' lpszFile : LPWSTR optional, out
' cch : DWORD
Declare PtrSafe Function DragQueryFileW Lib "shell32" ( _
    ByVal hDrop As LongPtr, _
    ByVal iFile As Long, _
    ByVal lpszFile As LongPtr, _
    ByVal cch 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

DragQueryFileW = ctypes.windll.shell32.DragQueryFileW
DragQueryFileW.restype = wintypes.DWORD
DragQueryFileW.argtypes = [
    wintypes.HANDLE,  # hDrop : HDROP
    wintypes.DWORD,  # iFile : DWORD
    wintypes.LPWSTR,  # lpszFile : LPWSTR optional, out
    wintypes.DWORD,  # cch : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHELL32.dll')
DragQueryFileW = Fiddle::Function.new(
  lib['DragQueryFileW'],
  [
    Fiddle::TYPE_VOIDP,  # hDrop : HDROP
    -Fiddle::TYPE_INT,  # iFile : DWORD
    Fiddle::TYPE_VOIDP,  # lpszFile : LPWSTR optional, out
    -Fiddle::TYPE_INT,  # cch : DWORD
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "shell32")]
extern "system" {
    fn DragQueryFileW(
        hDrop: *mut core::ffi::c_void,  // HDROP
        iFile: u32,  // DWORD
        lpszFile: *mut u16,  // LPWSTR optional, out
        cch: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHELL32.dll", CharSet = CharSet.Unicode)]
public static extern uint DragQueryFileW(IntPtr hDrop, uint iFile, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpszFile, uint cch);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_DragQueryFileW' -Namespace Win32 -PassThru
# $api::DragQueryFileW(hDrop, iFile, lpszFile, cch)
#uselib "SHELL32.dll"
#func global DragQueryFileW "DragQueryFileW" wptr, wptr, wptr, wptr
; DragQueryFileW hDrop, iFile, varptr(lpszFile), cch   ; 戻り値は stat
; hDrop : HDROP -> "wptr"
; iFile : DWORD -> "wptr"
; lpszFile : LPWSTR optional, out -> "wptr"
; cch : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SHELL32.dll"
#cfunc global DragQueryFileW "DragQueryFileW" sptr, int, var, int
; res = DragQueryFileW(hDrop, iFile, lpszFile, cch)
; hDrop : HDROP -> "sptr"
; iFile : DWORD -> "int"
; lpszFile : LPWSTR optional, out -> "var"
; cch : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD DragQueryFileW(HDROP hDrop, DWORD iFile, LPWSTR lpszFile, DWORD cch)
#uselib "SHELL32.dll"
#cfunc global DragQueryFileW "DragQueryFileW" intptr, int, var, int
; res = DragQueryFileW(hDrop, iFile, lpszFile, cch)
; hDrop : HDROP -> "intptr"
; iFile : DWORD -> "int"
; lpszFile : LPWSTR optional, out -> "var"
; cch : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procDragQueryFileW = shell32.NewProc("DragQueryFileW")
)

// hDrop (HDROP), iFile (DWORD), lpszFile (LPWSTR optional, out), cch (DWORD)
r1, _, err := procDragQueryFileW.Call(
	uintptr(hDrop),
	uintptr(iFile),
	uintptr(lpszFile),
	uintptr(cch),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function DragQueryFileW(
  hDrop: THandle;   // HDROP
  iFile: DWORD;   // DWORD
  lpszFile: PWideChar;   // LPWSTR optional, out
  cch: DWORD   // DWORD
): DWORD; stdcall;
  external 'SHELL32.dll' name 'DragQueryFileW';
result := DllCall("SHELL32\DragQueryFileW"
    , "Ptr", hDrop   ; HDROP
    , "UInt", iFile   ; DWORD
    , "Ptr", lpszFile   ; LPWSTR optional, out
    , "UInt", cch   ; DWORD
    , "UInt")   ; return: DWORD
●DragQueryFileW(hDrop, iFile, lpszFile, cch) = DLL("SHELL32.dll", "dword DragQueryFileW(void*, dword, char*, dword)")
# 呼び出し: DragQueryFileW(hDrop, iFile, lpszFile, cch)
# hDrop : HDROP -> "void*"
# iFile : DWORD -> "dword"
# lpszFile : LPWSTR optional, out -> "char*"
# cch : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。