Win32 API 日本語リファレンス
ホームDevices.DeviceAndDriverInstallation › SetupPrepareQueueForRestoreA

SetupPrepareQueueForRestoreA

関数
バックアップからの復元用にファイルキューを準備する。
DLLSETUPAPI.dll文字セットANSI (-A)呼出規約winapi

シグネチャ

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

BOOL SetupPrepareQueueForRestoreA(
    void* QueueHandle,
    LPCSTR BackupPath,
    DWORD RestoreFlags
);

パラメーター

名前方向説明
QueueHandlevoid*in復元用に準備するファイルキューのハンドル。
BackupPathLPCSTRin復元元となるバックアップディレクトリのパス(ANSI)。
RestoreFlagsDWORDin復元動作を制御するフラグ。通常は0。

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetupPrepareQueueForRestoreA(
    void* QueueHandle,
    LPCSTR BackupPath,
    DWORD RestoreFlags
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern bool SetupPrepareQueueForRestoreA(
    IntPtr QueueHandle,   // void*
    [MarshalAs(UnmanagedType.LPStr)] string BackupPath,   // LPCSTR
    uint RestoreFlags   // DWORD
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SetupPrepareQueueForRestoreA(
    QueueHandle As IntPtr,   ' void*
    <MarshalAs(UnmanagedType.LPStr)> BackupPath As String,   ' LPCSTR
    RestoreFlags As UInteger   ' DWORD
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' QueueHandle : void*
' BackupPath : LPCSTR
' RestoreFlags : DWORD
Declare PtrSafe Function SetupPrepareQueueForRestoreA Lib "setupapi" ( _
    ByVal QueueHandle As LongPtr, _
    ByVal BackupPath As String, _
    ByVal RestoreFlags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetupPrepareQueueForRestoreA = ctypes.windll.setupapi.SetupPrepareQueueForRestoreA
SetupPrepareQueueForRestoreA.restype = wintypes.BOOL
SetupPrepareQueueForRestoreA.argtypes = [
    ctypes.POINTER(None),  # QueueHandle : void*
    wintypes.LPCSTR,  # BackupPath : LPCSTR
    wintypes.DWORD,  # RestoreFlags : DWORD
]
require 'fiddle'
require 'fiddle/import'

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

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupPrepareQueueForRestoreA = setupapi.NewProc("SetupPrepareQueueForRestoreA")
)

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

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

foreign import stdcall safe "SetupPrepareQueueForRestoreA"
  c_SetupPrepareQueueForRestoreA :: Ptr () -> CString -> Word32 -> IO CInt
-- QueueHandle : void* -> Ptr ()
-- BackupPath : LPCSTR -> CString
-- RestoreFlags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setuppreparequeueforrestorea =
  foreign "SetupPrepareQueueForRestoreA"
    ((ptr void) @-> string @-> uint32_t @-> returning int32_t)
(* QueueHandle : void* -> (ptr void) *)
(* BackupPath : LPCSTR -> string *)
(* RestoreFlags : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)

(cffi:defcfun ("SetupPrepareQueueForRestoreA" setup-prepare-queue-for-restore-a :convention :stdcall) :int32
  (queue-handle :pointer)   ; void*
  (backup-path :string)   ; LPCSTR
  (restore-flags :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetupPrepareQueueForRestoreA = Win32::API::More->new('SETUPAPI',
    'BOOL SetupPrepareQueueForRestoreA(LPVOID QueueHandle, LPCSTR BackupPath, DWORD RestoreFlags)');
# my $ret = $SetupPrepareQueueForRestoreA->Call($QueueHandle, $BackupPath, $RestoreFlags);
# QueueHandle : void* -> LPVOID
# BackupPath : LPCSTR -> LPCSTR
# RestoreFlags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い