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

DragQueryFileA

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

シグネチャ

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

DWORD DragQueryFileA(
    HDROP hDrop,
    DWORD iFile,
    LPSTR lpszFile,   // optional
    DWORD cch
);

パラメーター

名前方向
hDropHDROPin
iFileDWORDin
lpszFileLPSTRoutoptional
cchDWORDin

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD DragQueryFileA(
    HDROP hDrop,
    DWORD iFile,
    LPSTR lpszFile,   // optional
    DWORD cch
);
[DllImport("SHELL32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint DragQueryFileA(
    IntPtr hDrop,   // HDROP
    uint iFile,   // DWORD
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpszFile,   // LPSTR optional, out
    uint cch   // DWORD
);
<DllImport("SHELL32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function DragQueryFileA(
    hDrop As IntPtr,   ' HDROP
    iFile As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPStr)> lpszFile As System.Text.StringBuilder,   ' LPSTR optional, out
    cch As UInteger   ' DWORD
) As UInteger
End Function
' hDrop : HDROP
' iFile : DWORD
' lpszFile : LPSTR optional, out
' cch : DWORD
Declare PtrSafe Function DragQueryFileA Lib "shell32" ( _
    ByVal hDrop As LongPtr, _
    ByVal iFile As Long, _
    ByVal lpszFile As String, _
    ByVal cch As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

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

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

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procDragQueryFileA = shell32.NewProc("DragQueryFileA")
)

// hDrop (HDROP), iFile (DWORD), lpszFile (LPSTR optional, out), cch (DWORD)
r1, _, err := procDragQueryFileA.Call(
	uintptr(hDrop),
	uintptr(iFile),
	uintptr(lpszFile),
	uintptr(cch),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function DragQueryFileA(
  hDrop: THandle;   // HDROP
  iFile: DWORD;   // DWORD
  lpszFile: PAnsiChar;   // LPSTR optional, out
  cch: DWORD   // DWORD
): DWORD; stdcall;
  external 'SHELL32.dll' name 'DragQueryFileA';
result := DllCall("SHELL32\DragQueryFileA"
    , "Ptr", hDrop   ; HDROP
    , "UInt", iFile   ; DWORD
    , "Ptr", lpszFile   ; LPSTR optional, out
    , "UInt", cch   ; DWORD
    , "UInt")   ; return: DWORD
●DragQueryFileA(hDrop, iFile, lpszFile, cch) = DLL("SHELL32.dll", "dword DragQueryFileA(void*, dword, char*, dword)")
# 呼び出し: DragQueryFileA(hDrop, iFile, lpszFile, cch)
# hDrop : HDROP -> "void*"
# iFile : DWORD -> "dword"
# lpszFile : LPSTR optional, out -> "char*"
# cch : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。