Win32 API 日本語リファレンス
ホームStorage.FileSystem › RemoveDirectory2A

RemoveDirectory2A

関数
フラグを指定してディレクトリを削除する(ANSI版)。
DLLKERNEL32.dll文字セットANSI (-A)呼出規約winapi

シグネチャ

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

BOOL RemoveDirectory2A(
    LPCSTR lpPathName,
    DIRECTORY_FLAGS DirectoryFlags
);

パラメーター

名前方向説明
lpPathNameLPCSTRin削除する空ディレクトリのパス。ANSI文字列。
DirectoryFlagsDIRECTORY_FLAGSin削除動作を制御する DIRECTORY_FLAGS フラグ。

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL RemoveDirectory2A(
    LPCSTR lpPathName,
    DIRECTORY_FLAGS DirectoryFlags
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern bool RemoveDirectory2A(
    [MarshalAs(UnmanagedType.LPStr)] string lpPathName,   // LPCSTR
    int DirectoryFlags   // DIRECTORY_FLAGS
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function RemoveDirectory2A(
    <MarshalAs(UnmanagedType.LPStr)> lpPathName As String,   ' LPCSTR
    DirectoryFlags As Integer   ' DIRECTORY_FLAGS
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' lpPathName : LPCSTR
' DirectoryFlags : DIRECTORY_FLAGS
Declare PtrSafe Function RemoveDirectory2A Lib "kernel32" ( _
    ByVal lpPathName As String, _
    ByVal DirectoryFlags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RemoveDirectory2A = ctypes.windll.kernel32.RemoveDirectory2A
RemoveDirectory2A.restype = wintypes.BOOL
RemoveDirectory2A.argtypes = [
    wintypes.LPCSTR,  # lpPathName : LPCSTR
    ctypes.c_int,  # DirectoryFlags : DIRECTORY_FLAGS
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
RemoveDirectory2A = Fiddle::Function.new(
  lib['RemoveDirectory2A'],
  [
    Fiddle::TYPE_VOIDP,  # lpPathName : LPCSTR
    Fiddle::TYPE_INT,  # DirectoryFlags : DIRECTORY_FLAGS
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn RemoveDirectory2A(
        lpPathName: *const u8,  // LPCSTR
        DirectoryFlags: i32  // DIRECTORY_FLAGS
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi)]
public static extern bool RemoveDirectory2A([MarshalAs(UnmanagedType.LPStr)] string lpPathName, int DirectoryFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_RemoveDirectory2A' -Namespace Win32 -PassThru
# $api::RemoveDirectory2A(lpPathName, DirectoryFlags)
#uselib "KERNEL32.dll"
#func global RemoveDirectory2A "RemoveDirectory2A" sptr, sptr
; RemoveDirectory2A lpPathName, DirectoryFlags   ; 戻り値は stat
; lpPathName : LPCSTR -> "sptr"
; DirectoryFlags : DIRECTORY_FLAGS -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global RemoveDirectory2A "RemoveDirectory2A" str, int
; res = RemoveDirectory2A(lpPathName, DirectoryFlags)
; lpPathName : LPCSTR -> "str"
; DirectoryFlags : DIRECTORY_FLAGS -> "int"
; BOOL RemoveDirectory2A(LPCSTR lpPathName, DIRECTORY_FLAGS DirectoryFlags)
#uselib "KERNEL32.dll"
#cfunc global RemoveDirectory2A "RemoveDirectory2A" str, int
; res = RemoveDirectory2A(lpPathName, DirectoryFlags)
; lpPathName : LPCSTR -> "str"
; DirectoryFlags : DIRECTORY_FLAGS -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procRemoveDirectory2A = kernel32.NewProc("RemoveDirectory2A")
)

// lpPathName (LPCSTR), DirectoryFlags (DIRECTORY_FLAGS)
r1, _, err := procRemoveDirectory2A.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpPathName))),
	uintptr(DirectoryFlags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function RemoveDirectory2A(
  lpPathName: PAnsiChar;   // LPCSTR
  DirectoryFlags: Integer   // DIRECTORY_FLAGS
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'RemoveDirectory2A';
result := DllCall("KERNEL32\RemoveDirectory2A"
    , "AStr", lpPathName   ; LPCSTR
    , "Int", DirectoryFlags   ; DIRECTORY_FLAGS
    , "Int")   ; return: BOOL
●RemoveDirectory2A(lpPathName, DirectoryFlags) = DLL("KERNEL32.dll", "bool RemoveDirectory2A(char*, int)")
# 呼び出し: RemoveDirectory2A(lpPathName, DirectoryFlags)
# lpPathName : LPCSTR -> "char*"
# DirectoryFlags : DIRECTORY_FLAGS -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "kernel32" fn RemoveDirectory2A(
    lpPathName: [*c]const u8, // LPCSTR
    DirectoryFlags: i32 // DIRECTORY_FLAGS
) callconv(std.os.windows.WINAPI) i32;
proc RemoveDirectory2A(
    lpPathName: cstring,  # LPCSTR
    DirectoryFlags: int32  # DIRECTORY_FLAGS
): int32 {.importc: "RemoveDirectory2A", stdcall, dynlib: "KERNEL32.dll".}
pragma(lib, "kernel32");
extern(Windows)
int RemoveDirectory2A(
    const(char)* lpPathName,   // LPCSTR
    int DirectoryFlags   // DIRECTORY_FLAGS
);
ccall((:RemoveDirectory2A, "KERNEL32.dll"), stdcall, Int32,
      (Cstring, Int32),
      lpPathName, DirectoryFlags)
# lpPathName : LPCSTR -> Cstring
# DirectoryFlags : DIRECTORY_FLAGS -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t RemoveDirectory2A(
    const char* lpPathName,
    int32_t DirectoryFlags);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.RemoveDirectory2A(lpPathName, DirectoryFlags)
-- lpPathName : LPCSTR
-- DirectoryFlags : DIRECTORY_FLAGS
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const RemoveDirectory2A = lib.func('__stdcall', 'RemoveDirectory2A', 'int32_t', ['str', 'int32_t']);
// RemoveDirectory2A(lpPathName, DirectoryFlags)
// lpPathName : LPCSTR -> 'str'
// DirectoryFlags : DIRECTORY_FLAGS -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  RemoveDirectory2A: { parameters: ["buffer", "i32"], result: "i32" },
});
// lib.symbols.RemoveDirectory2A(lpPathName, DirectoryFlags)
// lpPathName : LPCSTR -> "buffer"
// DirectoryFlags : DIRECTORY_FLAGS -> "i32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t RemoveDirectory2A(
    const char* lpPathName,
    int32_t DirectoryFlags);
C, "KERNEL32.dll");
// $ffi->RemoveDirectory2A(lpPathName, DirectoryFlags);
// lpPathName : LPCSTR
// DirectoryFlags : DIRECTORY_FLAGS
// 構造体/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.ASCII_OPTIONS);
    boolean RemoveDirectory2A(
        String lpPathName,   // LPCSTR
        int DirectoryFlags   // DIRECTORY_FLAGS
    );
}
@[Link("kernel32")]
lib LibKERNEL32
  fun RemoveDirectory2A = RemoveDirectory2A(
    lpPathName : UInt8*,   # LPCSTR
    DirectoryFlags : Int32   # DIRECTORY_FLAGS
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef RemoveDirectory2ANative = Int32 Function(Pointer<Utf8>, Int32);
typedef RemoveDirectory2ADart = int Function(Pointer<Utf8>, int);
final RemoveDirectory2A = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<RemoveDirectory2ANative, RemoveDirectory2ADart>('RemoveDirectory2A');
// lpPathName : LPCSTR -> Pointer<Utf8>
// DirectoryFlags : DIRECTORY_FLAGS -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function RemoveDirectory2A(
  lpPathName: PAnsiChar;   // LPCSTR
  DirectoryFlags: Integer   // DIRECTORY_FLAGS
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'RemoveDirectory2A';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "RemoveDirectory2A"
  c_RemoveDirectory2A :: CString -> Int32 -> IO CInt
-- lpPathName : LPCSTR -> CString
-- DirectoryFlags : DIRECTORY_FLAGS -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let removedirectory2a =
  foreign "RemoveDirectory2A"
    (string @-> int32_t @-> returning int32_t)
(* lpPathName : LPCSTR -> string *)
(* DirectoryFlags : DIRECTORY_FLAGS -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("RemoveDirectory2A" remove-directory2-a :convention :stdcall) :int32
  (lp-path-name :string)   ; LPCSTR
  (directory-flags :int32))   ; DIRECTORY_FLAGS
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $RemoveDirectory2A = Win32::API::More->new('KERNEL32',
    'BOOL RemoveDirectory2A(LPCSTR lpPathName, int DirectoryFlags)');
# my $ret = $RemoveDirectory2A->Call($lpPathName, $DirectoryFlags);
# lpPathName : LPCSTR -> LPCSTR
# DirectoryFlags : DIRECTORY_FLAGS -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い
類似 API
使用する型