SHEmptyRecycleBinW
関数指定ドライブのごみ箱を空にする。
シグネチャ
// SHELL32.dll (Unicode / -W)
#include <windows.h>
HRESULT SHEmptyRecycleBinW(
HWND hwnd, // optional
LPCWSTR pszRootPath, // optional
DWORD dwFlags
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hwnd | HWND | inoptional | 操作中に表示される可能性があるダイアログボックスの親ウィンドウへのハンドルです。このパラメーターには NULL を指定できます。 |
| pszRootPath | LPCWSTR | inoptional | ごみ箱が配置されているルートドライブのパスを格納する、最大長 MAX_PATH の null 終端文字列のアドレスです。このパラメーターには、ドライブ名、フォルダー名、サブフォルダー名を含む形式の文字列のアドレス(例: c:\windows\system)を指定できます。また、空文字列または NULL を指定することもできます。この値が空文字列または NULL の場合、すべてのドライブ上のすべてのごみ箱が空にされます。 |
| dwFlags | DWORD | in | 次の値のうち 1 つ以上を指定します。 SHERB_NOCONFIRMATIONオブジェクトの削除を確認するダイアログボックスを表示しません。 SHERB_NOPROGRESSUI進行状況を示すダイアログボックスを表示しません。 SHERB_NOSOUND操作完了時にサウンドを再生しません。 - dwFlags.SHERB_NOCONFIRMATIONオブジェクトの削除を確認するダイアログボックスを表示しません。 - dwFlags.SHERB_NOPROGRESSUI進行状況を示すダイアログボックスを表示しません。 - dwFlags.SHERB_NOSOUND操作完了時にサウンドを再生しません。 |
戻り値の型: HRESULT
公式ドキュメント
指定したドライブのごみ箱を空にします。(Unicode)
戻り値
型: HRESULT
この関数が成功した場合は S_OK を返します。それ以外の場合は HRESULT エラーコードを返します。
解説(Remarks)
メモ
shellapi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして SHEmptyRecycleBin を定義します。エンコーディング非依存のエイリアスを、エンコーディング非依存ではないコードと混在させて使用すると、不一致が生じ、コンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SHELL32.dll (Unicode / -W)
#include <windows.h>
HRESULT SHEmptyRecycleBinW(
HWND hwnd, // optional
LPCWSTR pszRootPath, // optional
DWORD dwFlags
);[DllImport("SHELL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int SHEmptyRecycleBinW(
IntPtr hwnd, // HWND optional
[MarshalAs(UnmanagedType.LPWStr)] string pszRootPath, // LPCWSTR optional
uint dwFlags // DWORD
);<DllImport("SHELL32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SHEmptyRecycleBinW(
hwnd As IntPtr, ' HWND optional
<MarshalAs(UnmanagedType.LPWStr)> pszRootPath As String, ' LPCWSTR optional
dwFlags As UInteger ' DWORD
) As Integer
End Function' hwnd : HWND optional
' pszRootPath : LPCWSTR optional
' dwFlags : DWORD
Declare PtrSafe Function SHEmptyRecycleBinW Lib "shell32" ( _
ByVal hwnd As LongPtr, _
ByVal pszRootPath As LongPtr, _
ByVal dwFlags 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
SHEmptyRecycleBinW = ctypes.windll.shell32.SHEmptyRecycleBinW
SHEmptyRecycleBinW.restype = ctypes.c_int
SHEmptyRecycleBinW.argtypes = [
wintypes.HANDLE, # hwnd : HWND optional
wintypes.LPCWSTR, # pszRootPath : LPCWSTR optional
wintypes.DWORD, # dwFlags : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHELL32.dll')
SHEmptyRecycleBinW = Fiddle::Function.new(
lib['SHEmptyRecycleBinW'],
[
Fiddle::TYPE_VOIDP, # hwnd : HWND optional
Fiddle::TYPE_VOIDP, # pszRootPath : LPCWSTR optional
-Fiddle::TYPE_INT, # dwFlags : DWORD
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "shell32")]
extern "system" {
fn SHEmptyRecycleBinW(
hwnd: *mut core::ffi::c_void, // HWND optional
pszRootPath: *const u16, // LPCWSTR optional
dwFlags: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SHELL32.dll", CharSet = CharSet.Unicode)]
public static extern int SHEmptyRecycleBinW(IntPtr hwnd, [MarshalAs(UnmanagedType.LPWStr)] string pszRootPath, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_SHEmptyRecycleBinW' -Namespace Win32 -PassThru
# $api::SHEmptyRecycleBinW(hwnd, pszRootPath, dwFlags)#uselib "SHELL32.dll"
#func global SHEmptyRecycleBinW "SHEmptyRecycleBinW" wptr, wptr, wptr
; SHEmptyRecycleBinW hwnd, pszRootPath, dwFlags ; 戻り値は stat
; hwnd : HWND optional -> "wptr"
; pszRootPath : LPCWSTR optional -> "wptr"
; dwFlags : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SHELL32.dll"
#cfunc global SHEmptyRecycleBinW "SHEmptyRecycleBinW" sptr, wstr, int
; res = SHEmptyRecycleBinW(hwnd, pszRootPath, dwFlags)
; hwnd : HWND optional -> "sptr"
; pszRootPath : LPCWSTR optional -> "wstr"
; dwFlags : DWORD -> "int"; HRESULT SHEmptyRecycleBinW(HWND hwnd, LPCWSTR pszRootPath, DWORD dwFlags)
#uselib "SHELL32.dll"
#cfunc global SHEmptyRecycleBinW "SHEmptyRecycleBinW" intptr, wstr, int
; res = SHEmptyRecycleBinW(hwnd, pszRootPath, dwFlags)
; hwnd : HWND optional -> "intptr"
; pszRootPath : LPCWSTR optional -> "wstr"
; dwFlags : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shell32 = windows.NewLazySystemDLL("SHELL32.dll")
procSHEmptyRecycleBinW = shell32.NewProc("SHEmptyRecycleBinW")
)
// hwnd (HWND optional), pszRootPath (LPCWSTR optional), dwFlags (DWORD)
r1, _, err := procSHEmptyRecycleBinW.Call(
uintptr(hwnd),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszRootPath))),
uintptr(dwFlags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction SHEmptyRecycleBinW(
hwnd: THandle; // HWND optional
pszRootPath: PWideChar; // LPCWSTR optional
dwFlags: DWORD // DWORD
): Integer; stdcall;
external 'SHELL32.dll' name 'SHEmptyRecycleBinW';result := DllCall("SHELL32\SHEmptyRecycleBinW"
, "Ptr", hwnd ; HWND optional
, "WStr", pszRootPath ; LPCWSTR optional
, "UInt", dwFlags ; DWORD
, "Int") ; return: HRESULT●SHEmptyRecycleBinW(hwnd, pszRootPath, dwFlags) = DLL("SHELL32.dll", "int SHEmptyRecycleBinW(void*, char*, dword)")
# 呼び出し: SHEmptyRecycleBinW(hwnd, pszRootPath, dwFlags)
# hwnd : HWND optional -> "void*"
# pszRootPath : LPCWSTR optional -> "char*"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "shell32" fn SHEmptyRecycleBinW(
hwnd: ?*anyopaque, // HWND optional
pszRootPath: [*c]const u16, // LPCWSTR optional
dwFlags: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc SHEmptyRecycleBinW(
hwnd: pointer, # HWND optional
pszRootPath: WideCString, # LPCWSTR optional
dwFlags: uint32 # DWORD
): int32 {.importc: "SHEmptyRecycleBinW", stdcall, dynlib: "SHELL32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "shell32");
extern(Windows)
int SHEmptyRecycleBinW(
void* hwnd, // HWND optional
const(wchar)* pszRootPath, // LPCWSTR optional
uint dwFlags // DWORD
);ccall((:SHEmptyRecycleBinW, "SHELL32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Cwstring, UInt32),
hwnd, pszRootPath, dwFlags)
# hwnd : HWND optional -> Ptr{Cvoid}
# pszRootPath : LPCWSTR optional -> Cwstring
# dwFlags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t SHEmptyRecycleBinW(
void* hwnd,
const uint16_t* pszRootPath,
uint32_t dwFlags);
]]
local shell32 = ffi.load("shell32")
-- shell32.SHEmptyRecycleBinW(hwnd, pszRootPath, dwFlags)
-- hwnd : HWND optional
-- pszRootPath : LPCWSTR optional
-- dwFlags : 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('SHELL32.dll');
const SHEmptyRecycleBinW = lib.func('__stdcall', 'SHEmptyRecycleBinW', 'int32_t', ['void *', 'str16', 'uint32_t']);
// SHEmptyRecycleBinW(hwnd, pszRootPath, dwFlags)
// hwnd : HWND optional -> 'void *'
// pszRootPath : LPCWSTR optional -> 'str16'
// dwFlags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHELL32.dll", {
SHEmptyRecycleBinW: { parameters: ["pointer", "buffer", "u32"], result: "i32" },
});
// lib.symbols.SHEmptyRecycleBinW(hwnd, pszRootPath, dwFlags)
// hwnd : HWND optional -> "pointer"
// pszRootPath : LPCWSTR optional -> "buffer"
// dwFlags : DWORD -> "u32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SHEmptyRecycleBinW(
void* hwnd,
const uint16_t* pszRootPath,
uint32_t dwFlags);
C, "SHELL32.dll");
// $ffi->SHEmptyRecycleBinW(hwnd, pszRootPath, dwFlags);
// hwnd : HWND optional
// pszRootPath : LPCWSTR optional
// dwFlags : 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 Shell32 extends StdCallLibrary {
Shell32 INSTANCE = Native.load("shell32", Shell32.class, W32APIOptions.UNICODE_OPTIONS);
int SHEmptyRecycleBinW(
Pointer hwnd, // HWND optional
WString pszRootPath, // LPCWSTR optional
int dwFlags // DWORD
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("shell32")]
lib LibSHELL32
fun SHEmptyRecycleBinW = SHEmptyRecycleBinW(
hwnd : Void*, # HWND optional
pszRootPath : UInt16*, # LPCWSTR optional
dwFlags : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SHEmptyRecycleBinWNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Uint32);
typedef SHEmptyRecycleBinWDart = int Function(Pointer<Void>, Pointer<Utf16>, int);
final SHEmptyRecycleBinW = DynamicLibrary.open('SHELL32.dll')
.lookupFunction<SHEmptyRecycleBinWNative, SHEmptyRecycleBinWDart>('SHEmptyRecycleBinW');
// hwnd : HWND optional -> Pointer<Void>
// pszRootPath : LPCWSTR optional -> Pointer<Utf16>
// dwFlags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SHEmptyRecycleBinW(
hwnd: THandle; // HWND optional
pszRootPath: PWideChar; // LPCWSTR optional
dwFlags: DWORD // DWORD
): Integer; stdcall;
external 'SHELL32.dll' name 'SHEmptyRecycleBinW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SHEmptyRecycleBinW"
c_SHEmptyRecycleBinW :: Ptr () -> CWString -> Word32 -> IO Int32
-- hwnd : HWND optional -> Ptr ()
-- pszRootPath : LPCWSTR optional -> CWString
-- dwFlags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let shemptyrecyclebinw =
foreign "SHEmptyRecycleBinW"
((ptr void) @-> (ptr uint16_t) @-> uint32_t @-> returning int32_t)
(* hwnd : HWND optional -> (ptr void) *)
(* pszRootPath : LPCWSTR optional -> (ptr uint16_t) *)
(* dwFlags : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library shell32 (t "SHELL32.dll"))
(cffi:use-foreign-library shell32)
(cffi:defcfun ("SHEmptyRecycleBinW" shempty-recycle-bin-w :convention :stdcall) :int32
(hwnd :pointer) ; HWND optional
(psz-root-path (:string :encoding :utf-16le)) ; LPCWSTR optional
(dw-flags :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SHEmptyRecycleBinW = Win32::API::More->new('SHELL32',
'int SHEmptyRecycleBinW(HANDLE hwnd, LPCWSTR pszRootPath, DWORD dwFlags)');
# my $ret = $SHEmptyRecycleBinW->Call($hwnd, $pszRootPath, $dwFlags);
# hwnd : HWND optional -> HANDLE
# pszRootPath : LPCWSTR optional -> LPCWSTR
# dwFlags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f SHEmptyRecycleBinA (ANSI版) — 指定ドライブのごみ箱を空にする。
公式の関連項目
- f SHQueryRecycleBinW — ごみ箱内の項目数と合計サイズを取得する。