ホーム › System.WindowsProgramming › ReplacePartitionUnit
ReplacePartitionUnit
関数対象パーティションを予備パーティションに置き換える。
シグネチャ
// KERNEL32.dll
#include <windows.h>
BOOL ReplacePartitionUnit(
LPWSTR TargetPartition,
LPWSTR SparePartition,
DWORD Flags
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| TargetPartition | LPWSTR | in |
| SparePartition | LPWSTR | in |
| Flags | DWORD | in |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
BOOL ReplacePartitionUnit(
LPWSTR TargetPartition,
LPWSTR SparePartition,
DWORD Flags
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern bool ReplacePartitionUnit(
[MarshalAs(UnmanagedType.LPWStr)] string TargetPartition, // LPWSTR
[MarshalAs(UnmanagedType.LPWStr)] string SparePartition, // LPWSTR
uint Flags // DWORD
);<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function ReplacePartitionUnit(
<MarshalAs(UnmanagedType.LPWStr)> TargetPartition As String, ' LPWSTR
<MarshalAs(UnmanagedType.LPWStr)> SparePartition As String, ' LPWSTR
Flags As UInteger ' DWORD
) As Boolean
End Function' TargetPartition : LPWSTR
' SparePartition : LPWSTR
' Flags : DWORD
Declare PtrSafe Function ReplacePartitionUnit Lib "kernel32" ( _
ByVal TargetPartition As LongPtr, _
ByVal SparePartition As LongPtr, _
ByVal Flags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ReplacePartitionUnit = ctypes.windll.kernel32.ReplacePartitionUnit
ReplacePartitionUnit.restype = wintypes.BOOL
ReplacePartitionUnit.argtypes = [
wintypes.LPCWSTR, # TargetPartition : LPWSTR
wintypes.LPCWSTR, # SparePartition : LPWSTR
wintypes.DWORD, # Flags : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
ReplacePartitionUnit = Fiddle::Function.new(
lib['ReplacePartitionUnit'],
[
Fiddle::TYPE_VOIDP, # TargetPartition : LPWSTR
Fiddle::TYPE_VOIDP, # SparePartition : LPWSTR
-Fiddle::TYPE_INT, # Flags : DWORD
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn ReplacePartitionUnit(
TargetPartition: *mut u16, // LPWSTR
SparePartition: *mut u16, // LPWSTR
Flags: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll")]
public static extern bool ReplacePartitionUnit([MarshalAs(UnmanagedType.LPWStr)] string TargetPartition, [MarshalAs(UnmanagedType.LPWStr)] string SparePartition, uint Flags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_ReplacePartitionUnit' -Namespace Win32 -PassThru
# $api::ReplacePartitionUnit(TargetPartition, SparePartition, Flags)#uselib "KERNEL32.dll"
#func global ReplacePartitionUnit "ReplacePartitionUnit" sptr, sptr, sptr
; ReplacePartitionUnit TargetPartition, SparePartition, Flags ; 戻り値は stat
; TargetPartition : LPWSTR -> "sptr"
; SparePartition : LPWSTR -> "sptr"
; Flags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global ReplacePartitionUnit "ReplacePartitionUnit" wstr, wstr, int
; res = ReplacePartitionUnit(TargetPartition, SparePartition, Flags)
; TargetPartition : LPWSTR -> "wstr"
; SparePartition : LPWSTR -> "wstr"
; Flags : DWORD -> "int"; BOOL ReplacePartitionUnit(LPWSTR TargetPartition, LPWSTR SparePartition, DWORD Flags)
#uselib "KERNEL32.dll"
#cfunc global ReplacePartitionUnit "ReplacePartitionUnit" wstr, wstr, int
; res = ReplacePartitionUnit(TargetPartition, SparePartition, Flags)
; TargetPartition : LPWSTR -> "wstr"
; SparePartition : LPWSTR -> "wstr"
; Flags : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procReplacePartitionUnit = kernel32.NewProc("ReplacePartitionUnit")
)
// TargetPartition (LPWSTR), SparePartition (LPWSTR), Flags (DWORD)
r1, _, err := procReplacePartitionUnit.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(TargetPartition))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(SparePartition))),
uintptr(Flags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction ReplacePartitionUnit(
TargetPartition: PWideChar; // LPWSTR
SparePartition: PWideChar; // LPWSTR
Flags: DWORD // DWORD
): BOOL; stdcall;
external 'KERNEL32.dll' name 'ReplacePartitionUnit';result := DllCall("KERNEL32\ReplacePartitionUnit"
, "WStr", TargetPartition ; LPWSTR
, "WStr", SparePartition ; LPWSTR
, "UInt", Flags ; DWORD
, "Int") ; return: BOOL●ReplacePartitionUnit(TargetPartition, SparePartition, Flags) = DLL("KERNEL32.dll", "bool ReplacePartitionUnit(char*, char*, dword)")
# 呼び出し: ReplacePartitionUnit(TargetPartition, SparePartition, Flags)
# TargetPartition : LPWSTR -> "char*"
# SparePartition : LPWSTR -> "char*"
# Flags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。