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

SHEmptyRecycleBinA

関数
指定ドライブのごみ箱を空にする。
DLLSHELL32.dll文字セットANSI (-A)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HRESULT SHEmptyRecycleBinA(
    HWND hwnd,   // optional
    LPCSTR pszRootPath,   // optional
    DWORD dwFlags
);

パラメーター

名前方向説明
hwndHWNDinoptional操作中に表示される可能性のあるダイアログボックスの親ウィンドウへのハンドルです。このパラメーターは NULL にできます。
pszRootPathLPCSTRinoptionalごみ箱が配置されているルートドライブのパスを格納した、最大長 MAX_PATH の null 終端文字列のアドレスです。このパラメーターには、c:\windows\system\ のようにドライブ、フォルダー、サブフォルダー名で構成された文字列のアドレスを指定できます。また、空文字列または NULL を指定することもできます。この値が空文字列または NULL の場合、すべてのドライブ上のすべてのごみ箱が空にされます。
dwFlagsDWORDin

次の値の 1 つ以上を指定します。

SHERB_NOCONFIRMATION

オブジェクトの削除を確認するダイアログボックスは表示されません。

SHERB_NOPROGRESSUI

進行状況を示すダイアログボックスは表示されません。

SHERB_NOSOUND

操作の完了時にサウンドは再生されません。

戻り値の型: HRESULT

公式ドキュメント

指定したドライブのごみ箱を空にします。(ANSI)

戻り値

型: HRESULT

この関数が成功した場合は S_OK を返します。それ以外の場合は HRESULT エラーコードを返します。

解説(Remarks)

メモ

shellapi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして SHEmptyRecycleBin を定義します。エンコーディング非依存のエイリアスの使用を、エンコーディング非依存でないコードと混在させると、コンパイルエラーや実行時エラーを引き起こす不整合につながる可能性があります。詳細については、関数プロトタイプの規則を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

HRESULT SHEmptyRecycleBinA(
    HWND hwnd,   // optional
    LPCSTR pszRootPath,   // optional
    DWORD dwFlags
);
[DllImport("SHELL32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern int SHEmptyRecycleBinA(
    IntPtr hwnd,   // HWND optional
    [MarshalAs(UnmanagedType.LPStr)] string pszRootPath,   // LPCSTR optional
    uint dwFlags   // DWORD
);
<DllImport("SHELL32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SHEmptyRecycleBinA(
    hwnd As IntPtr,   ' HWND optional
    <MarshalAs(UnmanagedType.LPStr)> pszRootPath As String,   ' LPCSTR optional
    dwFlags As UInteger   ' DWORD
) As Integer
End Function
' hwnd : HWND optional
' pszRootPath : LPCSTR optional
' dwFlags : DWORD
Declare PtrSafe Function SHEmptyRecycleBinA Lib "shell32" ( _
    ByVal hwnd As LongPtr, _
    ByVal pszRootPath As String, _
    ByVal dwFlags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SHEmptyRecycleBinA = ctypes.windll.shell32.SHEmptyRecycleBinA
SHEmptyRecycleBinA.restype = ctypes.c_int
SHEmptyRecycleBinA.argtypes = [
    wintypes.HANDLE,  # hwnd : HWND optional
    wintypes.LPCSTR,  # pszRootPath : LPCSTR optional
    wintypes.DWORD,  # dwFlags : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHELL32.dll')
SHEmptyRecycleBinA = Fiddle::Function.new(
  lib['SHEmptyRecycleBinA'],
  [
    Fiddle::TYPE_VOIDP,  # hwnd : HWND optional
    Fiddle::TYPE_VOIDP,  # pszRootPath : LPCSTR optional
    -Fiddle::TYPE_INT,  # dwFlags : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "shell32")]
extern "system" {
    fn SHEmptyRecycleBinA(
        hwnd: *mut core::ffi::c_void,  // HWND optional
        pszRootPath: *const u8,  // LPCSTR optional
        dwFlags: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHELL32.dll", CharSet = CharSet.Ansi)]
public static extern int SHEmptyRecycleBinA(IntPtr hwnd, [MarshalAs(UnmanagedType.LPStr)] string pszRootPath, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_SHEmptyRecycleBinA' -Namespace Win32 -PassThru
# $api::SHEmptyRecycleBinA(hwnd, pszRootPath, dwFlags)
#uselib "SHELL32.dll"
#func global SHEmptyRecycleBinA "SHEmptyRecycleBinA" sptr, sptr, sptr
; SHEmptyRecycleBinA hwnd, pszRootPath, dwFlags   ; 戻り値は stat
; hwnd : HWND optional -> "sptr"
; pszRootPath : LPCSTR optional -> "sptr"
; dwFlags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SHELL32.dll"
#cfunc global SHEmptyRecycleBinA "SHEmptyRecycleBinA" sptr, str, int
; res = SHEmptyRecycleBinA(hwnd, pszRootPath, dwFlags)
; hwnd : HWND optional -> "sptr"
; pszRootPath : LPCSTR optional -> "str"
; dwFlags : DWORD -> "int"
; HRESULT SHEmptyRecycleBinA(HWND hwnd, LPCSTR pszRootPath, DWORD dwFlags)
#uselib "SHELL32.dll"
#cfunc global SHEmptyRecycleBinA "SHEmptyRecycleBinA" intptr, str, int
; res = SHEmptyRecycleBinA(hwnd, pszRootPath, dwFlags)
; hwnd : HWND optional -> "intptr"
; pszRootPath : LPCSTR optional -> "str"
; dwFlags : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procSHEmptyRecycleBinA = shell32.NewProc("SHEmptyRecycleBinA")
)

// hwnd (HWND optional), pszRootPath (LPCSTR optional), dwFlags (DWORD)
r1, _, err := procSHEmptyRecycleBinA.Call(
	uintptr(hwnd),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(pszRootPath))),
	uintptr(dwFlags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function SHEmptyRecycleBinA(
  hwnd: THandle;   // HWND optional
  pszRootPath: PAnsiChar;   // LPCSTR optional
  dwFlags: DWORD   // DWORD
): Integer; stdcall;
  external 'SHELL32.dll' name 'SHEmptyRecycleBinA';
result := DllCall("SHELL32\SHEmptyRecycleBinA"
    , "Ptr", hwnd   ; HWND optional
    , "AStr", pszRootPath   ; LPCSTR optional
    , "UInt", dwFlags   ; DWORD
    , "Int")   ; return: HRESULT
●SHEmptyRecycleBinA(hwnd, pszRootPath, dwFlags) = DLL("SHELL32.dll", "int SHEmptyRecycleBinA(void*, char*, dword)")
# 呼び出し: SHEmptyRecycleBinA(hwnd, pszRootPath, dwFlags)
# hwnd : HWND optional -> "void*"
# pszRootPath : LPCSTR optional -> "char*"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "shell32" fn SHEmptyRecycleBinA(
    hwnd: ?*anyopaque, // HWND optional
    pszRootPath: [*c]const u8, // LPCSTR optional
    dwFlags: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
proc SHEmptyRecycleBinA(
    hwnd: pointer,  # HWND optional
    pszRootPath: cstring,  # LPCSTR optional
    dwFlags: uint32  # DWORD
): int32 {.importc: "SHEmptyRecycleBinA", stdcall, dynlib: "SHELL32.dll".}
pragma(lib, "shell32");
extern(Windows)
int SHEmptyRecycleBinA(
    void* hwnd,   // HWND optional
    const(char)* pszRootPath,   // LPCSTR optional
    uint dwFlags   // DWORD
);
ccall((:SHEmptyRecycleBinA, "SHELL32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Cstring, UInt32),
      hwnd, pszRootPath, dwFlags)
# hwnd : HWND optional -> Ptr{Cvoid}
# pszRootPath : LPCSTR optional -> Cstring
# dwFlags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SHEmptyRecycleBinA(
    void* hwnd,
    const char* pszRootPath,
    uint32_t dwFlags);
]]
local shell32 = ffi.load("shell32")
-- shell32.SHEmptyRecycleBinA(hwnd, pszRootPath, dwFlags)
-- hwnd : HWND optional
-- pszRootPath : LPCSTR optional
-- dwFlags : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SHELL32.dll');
const SHEmptyRecycleBinA = lib.func('__stdcall', 'SHEmptyRecycleBinA', 'int32_t', ['void *', 'str', 'uint32_t']);
// SHEmptyRecycleBinA(hwnd, pszRootPath, dwFlags)
// hwnd : HWND optional -> 'void *'
// pszRootPath : LPCSTR optional -> 'str'
// dwFlags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SHELL32.dll", {
  SHEmptyRecycleBinA: { parameters: ["pointer", "buffer", "u32"], result: "i32" },
});
// lib.symbols.SHEmptyRecycleBinA(hwnd, pszRootPath, dwFlags)
// hwnd : HWND optional -> "pointer"
// pszRootPath : LPCSTR optional -> "buffer"
// dwFlags : DWORD -> "u32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SHEmptyRecycleBinA(
    void* hwnd,
    const char* pszRootPath,
    uint32_t dwFlags);
C, "SHELL32.dll");
// $ffi->SHEmptyRecycleBinA(hwnd, pszRootPath, dwFlags);
// hwnd : HWND optional
// pszRootPath : LPCSTR 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.ASCII_OPTIONS);
    int SHEmptyRecycleBinA(
        Pointer hwnd,   // HWND optional
        String pszRootPath,   // LPCSTR optional
        int dwFlags   // DWORD
    );
}
@[Link("shell32")]
lib LibSHELL32
  fun SHEmptyRecycleBinA = SHEmptyRecycleBinA(
    hwnd : Void*,   # HWND optional
    pszRootPath : UInt8*,   # LPCSTR 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 SHEmptyRecycleBinANative = Int32 Function(Pointer<Void>, Pointer<Utf8>, Uint32);
typedef SHEmptyRecycleBinADart = int Function(Pointer<Void>, Pointer<Utf8>, int);
final SHEmptyRecycleBinA = DynamicLibrary.open('SHELL32.dll')
    .lookupFunction<SHEmptyRecycleBinANative, SHEmptyRecycleBinADart>('SHEmptyRecycleBinA');
// hwnd : HWND optional -> Pointer<Void>
// pszRootPath : LPCSTR optional -> Pointer<Utf8>
// dwFlags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SHEmptyRecycleBinA(
  hwnd: THandle;   // HWND optional
  pszRootPath: PAnsiChar;   // LPCSTR optional
  dwFlags: DWORD   // DWORD
): Integer; stdcall;
  external 'SHELL32.dll' name 'SHEmptyRecycleBinA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SHEmptyRecycleBinA"
  c_SHEmptyRecycleBinA :: Ptr () -> CString -> Word32 -> IO Int32
-- hwnd : HWND optional -> Ptr ()
-- pszRootPath : LPCSTR optional -> CString
-- dwFlags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let shemptyrecyclebina =
  foreign "SHEmptyRecycleBinA"
    ((ptr void) @-> string @-> uint32_t @-> returning int32_t)
(* hwnd : HWND optional -> (ptr void) *)
(* pszRootPath : LPCSTR optional -> string *)
(* 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 ("SHEmptyRecycleBinA" shempty-recycle-bin-a :convention :stdcall) :int32
  (hwnd :pointer)   ; HWND optional
  (psz-root-path :string)   ; LPCSTR optional
  (dw-flags :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SHEmptyRecycleBinA = Win32::API::More->new('SHELL32',
    'int SHEmptyRecycleBinA(HANDLE hwnd, LPCSTR pszRootPath, DWORD dwFlags)');
# my $ret = $SHEmptyRecycleBinA->Call($hwnd, $pszRootPath, $dwFlags);
# hwnd : HWND optional -> HANDLE
# pszRootPath : LPCSTR optional -> LPCSTR
# dwFlags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い
公式の関連項目