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

SHFormatDrive

関数
ドライブのフォーマットダイアログを表示し実行する。
DLLSHELL32.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

// SHELL32.dll
#include <windows.h>

DWORD SHFormatDrive(
    HWND hwnd,
    DWORD drive,
    SHFMT_ID fmtID,
    DWORD options
);

パラメーター

名前方向
hwndHWNDin
driveDWORDin
fmtIDSHFMT_IDin
optionsDWORDin

戻り値の型: DWORD

各言語での呼び出し定義

// SHELL32.dll
#include <windows.h>

DWORD SHFormatDrive(
    HWND hwnd,
    DWORD drive,
    SHFMT_ID fmtID,
    DWORD options
);
[DllImport("SHELL32.dll", ExactSpelling = true)]
static extern uint SHFormatDrive(
    IntPtr hwnd,   // HWND
    uint drive,   // DWORD
    uint fmtID,   // SHFMT_ID
    uint options   // DWORD
);
<DllImport("SHELL32.dll", ExactSpelling:=True)>
Public Shared Function SHFormatDrive(
    hwnd As IntPtr,   ' HWND
    drive As UInteger,   ' DWORD
    fmtID As UInteger,   ' SHFMT_ID
    options As UInteger   ' DWORD
) As UInteger
End Function
' hwnd : HWND
' drive : DWORD
' fmtID : SHFMT_ID
' options : DWORD
Declare PtrSafe Function SHFormatDrive Lib "shell32" ( _
    ByVal hwnd As LongPtr, _
    ByVal drive As Long, _
    ByVal fmtID As Long, _
    ByVal options As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SHFormatDrive = ctypes.windll.shell32.SHFormatDrive
SHFormatDrive.restype = wintypes.DWORD
SHFormatDrive.argtypes = [
    wintypes.HANDLE,  # hwnd : HWND
    wintypes.DWORD,  # drive : DWORD
    wintypes.DWORD,  # fmtID : SHFMT_ID
    wintypes.DWORD,  # options : DWORD
]
require 'fiddle'
require 'fiddle/import'

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

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procSHFormatDrive = shell32.NewProc("SHFormatDrive")
)

// hwnd (HWND), drive (DWORD), fmtID (SHFMT_ID), options (DWORD)
r1, _, err := procSHFormatDrive.Call(
	uintptr(hwnd),
	uintptr(drive),
	uintptr(fmtID),
	uintptr(options),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function SHFormatDrive(
  hwnd: THandle;   // HWND
  drive: DWORD;   // DWORD
  fmtID: DWORD;   // SHFMT_ID
  options: DWORD   // DWORD
): DWORD; stdcall;
  external 'SHELL32.dll' name 'SHFormatDrive';
result := DllCall("SHELL32\SHFormatDrive"
    , "Ptr", hwnd   ; HWND
    , "UInt", drive   ; DWORD
    , "UInt", fmtID   ; SHFMT_ID
    , "UInt", options   ; DWORD
    , "UInt")   ; return: DWORD
●SHFormatDrive(hwnd, drive, fmtID, options) = DLL("SHELL32.dll", "dword SHFormatDrive(void*, dword, dword, dword)")
# 呼び出し: SHFormatDrive(hwnd, drive, fmtID, options)
# hwnd : HWND -> "void*"
# drive : DWORD -> "dword"
# fmtID : SHFMT_ID -> "dword"
# options : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。