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

SetupQueueRenameW

関数
ファイルキューに名前変更操作を追加する(Unicode)。
DLLSETUPAPI.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// SETUPAPI.dll  (Unicode / -W)
#include <windows.h>

BOOL SetupQueueRenameW(
    void* QueueHandle,
    LPCWSTR SourcePath,
    LPCWSTR SourceFilename,   // optional
    LPCWSTR TargetPath,   // optional
    LPCWSTR TargetFilename
);

パラメーター

名前方向説明
QueueHandlevoid*in名前変更操作を登録するファイルキューのハンドル。
SourcePathLPCWSTRin変更元ファイルのディレクトリパス(Unicode)。
SourceFilenameLPCWSTRinoptional変更元のファイル名。NULLならSourcePath全体を対象とする。
TargetPathLPCWSTRinoptional変更先のディレクトリパス。NULLならSourcePathと同一とする。
TargetFilenameLPCWSTRin変更後のファイル名(Unicode)。

戻り値の型: BOOL

各言語での呼び出し定義

// SETUPAPI.dll  (Unicode / -W)
#include <windows.h>

BOOL SetupQueueRenameW(
    void* QueueHandle,
    LPCWSTR SourcePath,
    LPCWSTR SourceFilename,   // optional
    LPCWSTR TargetPath,   // optional
    LPCWSTR TargetFilename
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetupQueueRenameW(
    IntPtr QueueHandle,   // void*
    [MarshalAs(UnmanagedType.LPWStr)] string SourcePath,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string SourceFilename,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string TargetPath,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string TargetFilename   // LPCWSTR
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupQueueRenameW(
    QueueHandle As IntPtr,   ' void*
    <MarshalAs(UnmanagedType.LPWStr)> SourcePath As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> SourceFilename As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> TargetPath As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> TargetFilename As String   ' LPCWSTR
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' QueueHandle : void*
' SourcePath : LPCWSTR
' SourceFilename : LPCWSTR optional
' TargetPath : LPCWSTR optional
' TargetFilename : LPCWSTR
Declare PtrSafe Function SetupQueueRenameW Lib "setupapi" ( _
    ByVal QueueHandle As LongPtr, _
    ByVal SourcePath As LongPtr, _
    ByVal SourceFilename As LongPtr, _
    ByVal TargetPath As LongPtr, _
    ByVal TargetFilename As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetupQueueRenameW = ctypes.windll.setupapi.SetupQueueRenameW
SetupQueueRenameW.restype = wintypes.BOOL
SetupQueueRenameW.argtypes = [
    ctypes.POINTER(None),  # QueueHandle : void*
    wintypes.LPCWSTR,  # SourcePath : LPCWSTR
    wintypes.LPCWSTR,  # SourceFilename : LPCWSTR optional
    wintypes.LPCWSTR,  # TargetPath : LPCWSTR optional
    wintypes.LPCWSTR,  # TargetFilename : LPCWSTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SETUPAPI.dll')
SetupQueueRenameW = Fiddle::Function.new(
  lib['SetupQueueRenameW'],
  [
    Fiddle::TYPE_VOIDP,  # QueueHandle : void*
    Fiddle::TYPE_VOIDP,  # SourcePath : LPCWSTR
    Fiddle::TYPE_VOIDP,  # SourceFilename : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # TargetPath : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # TargetFilename : LPCWSTR
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "setupapi")]
extern "system" {
    fn SetupQueueRenameW(
        QueueHandle: *mut (),  // void*
        SourcePath: *const u16,  // LPCWSTR
        SourceFilename: *const u16,  // LPCWSTR optional
        TargetPath: *const u16,  // LPCWSTR optional
        TargetFilename: *const u16  // LPCWSTR
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool SetupQueueRenameW(IntPtr QueueHandle, [MarshalAs(UnmanagedType.LPWStr)] string SourcePath, [MarshalAs(UnmanagedType.LPWStr)] string SourceFilename, [MarshalAs(UnmanagedType.LPWStr)] string TargetPath, [MarshalAs(UnmanagedType.LPWStr)] string TargetFilename);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupQueueRenameW' -Namespace Win32 -PassThru
# $api::SetupQueueRenameW(QueueHandle, SourcePath, SourceFilename, TargetPath, TargetFilename)
#uselib "SETUPAPI.dll"
#func global SetupQueueRenameW "SetupQueueRenameW" wptr, wptr, wptr, wptr, wptr
; SetupQueueRenameW QueueHandle, SourcePath, SourceFilename, TargetPath, TargetFilename   ; 戻り値は stat
; QueueHandle : void* -> "wptr"
; SourcePath : LPCWSTR -> "wptr"
; SourceFilename : LPCWSTR optional -> "wptr"
; TargetPath : LPCWSTR optional -> "wptr"
; TargetFilename : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SETUPAPI.dll"
#cfunc global SetupQueueRenameW "SetupQueueRenameW" sptr, wstr, wstr, wstr, wstr
; res = SetupQueueRenameW(QueueHandle, SourcePath, SourceFilename, TargetPath, TargetFilename)
; QueueHandle : void* -> "sptr"
; SourcePath : LPCWSTR -> "wstr"
; SourceFilename : LPCWSTR optional -> "wstr"
; TargetPath : LPCWSTR optional -> "wstr"
; TargetFilename : LPCWSTR -> "wstr"
; BOOL SetupQueueRenameW(void* QueueHandle, LPCWSTR SourcePath, LPCWSTR SourceFilename, LPCWSTR TargetPath, LPCWSTR TargetFilename)
#uselib "SETUPAPI.dll"
#cfunc global SetupQueueRenameW "SetupQueueRenameW" intptr, wstr, wstr, wstr, wstr
; res = SetupQueueRenameW(QueueHandle, SourcePath, SourceFilename, TargetPath, TargetFilename)
; QueueHandle : void* -> "intptr"
; SourcePath : LPCWSTR -> "wstr"
; SourceFilename : LPCWSTR optional -> "wstr"
; TargetPath : LPCWSTR optional -> "wstr"
; TargetFilename : LPCWSTR -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupQueueRenameW = setupapi.NewProc("SetupQueueRenameW")
)

// QueueHandle (void*), SourcePath (LPCWSTR), SourceFilename (LPCWSTR optional), TargetPath (LPCWSTR optional), TargetFilename (LPCWSTR)
r1, _, err := procSetupQueueRenameW.Call(
	uintptr(QueueHandle),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(SourcePath))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(SourceFilename))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(TargetPath))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(TargetFilename))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupQueueRenameW(
  QueueHandle: Pointer;   // void*
  SourcePath: PWideChar;   // LPCWSTR
  SourceFilename: PWideChar;   // LPCWSTR optional
  TargetPath: PWideChar;   // LPCWSTR optional
  TargetFilename: PWideChar   // LPCWSTR
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupQueueRenameW';
result := DllCall("SETUPAPI\SetupQueueRenameW"
    , "Ptr", QueueHandle   ; void*
    , "WStr", SourcePath   ; LPCWSTR
    , "WStr", SourceFilename   ; LPCWSTR optional
    , "WStr", TargetPath   ; LPCWSTR optional
    , "WStr", TargetFilename   ; LPCWSTR
    , "Int")   ; return: BOOL
●SetupQueueRenameW(QueueHandle, SourcePath, SourceFilename, TargetPath, TargetFilename) = DLL("SETUPAPI.dll", "bool SetupQueueRenameW(void*, char*, char*, char*, char*)")
# 呼び出し: SetupQueueRenameW(QueueHandle, SourcePath, SourceFilename, TargetPath, TargetFilename)
# QueueHandle : void* -> "void*"
# SourcePath : LPCWSTR -> "char*"
# SourceFilename : LPCWSTR optional -> "char*"
# TargetPath : LPCWSTR optional -> "char*"
# TargetFilename : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

extern "setupapi" fn SetupQueueRenameW(
    QueueHandle: ?*anyopaque, // void*
    SourcePath: [*c]const u16, // LPCWSTR
    SourceFilename: [*c]const u16, // LPCWSTR optional
    TargetPath: [*c]const u16, // LPCWSTR optional
    TargetFilename: [*c]const u16 // LPCWSTR
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc SetupQueueRenameW(
    QueueHandle: pointer,  # void*
    SourcePath: WideCString,  # LPCWSTR
    SourceFilename: WideCString,  # LPCWSTR optional
    TargetPath: WideCString,  # LPCWSTR optional
    TargetFilename: WideCString  # LPCWSTR
): int32 {.importc: "SetupQueueRenameW", stdcall, dynlib: "SETUPAPI.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "setupapi");
extern(Windows)
int SetupQueueRenameW(
    void* QueueHandle,   // void*
    const(wchar)* SourcePath,   // LPCWSTR
    const(wchar)* SourceFilename,   // LPCWSTR optional
    const(wchar)* TargetPath,   // LPCWSTR optional
    const(wchar)* TargetFilename   // LPCWSTR
);
ccall((:SetupQueueRenameW, "SETUPAPI.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Cwstring, Cwstring, Cwstring, Cwstring),
      QueueHandle, SourcePath, SourceFilename, TargetPath, TargetFilename)
# QueueHandle : void* -> Ptr{Cvoid}
# SourcePath : LPCWSTR -> Cwstring
# SourceFilename : LPCWSTR optional -> Cwstring
# TargetPath : LPCWSTR optional -> Cwstring
# TargetFilename : LPCWSTR -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetupQueueRenameW(
    void* QueueHandle,
    const uint16_t* SourcePath,
    const uint16_t* SourceFilename,
    const uint16_t* TargetPath,
    const uint16_t* TargetFilename);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupQueueRenameW(QueueHandle, SourcePath, SourceFilename, TargetPath, TargetFilename)
-- QueueHandle : void*
-- SourcePath : LPCWSTR
-- SourceFilename : LPCWSTR optional
-- TargetPath : LPCWSTR optional
-- TargetFilename : LPCWSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupQueueRenameW = lib.func('__stdcall', 'SetupQueueRenameW', 'int32_t', ['void *', 'str16', 'str16', 'str16', 'str16']);
// SetupQueueRenameW(QueueHandle, SourcePath, SourceFilename, TargetPath, TargetFilename)
// QueueHandle : void* -> 'void *'
// SourcePath : LPCWSTR -> 'str16'
// SourceFilename : LPCWSTR optional -> 'str16'
// TargetPath : LPCWSTR optional -> 'str16'
// TargetFilename : LPCWSTR -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SETUPAPI.dll", {
  SetupQueueRenameW: { parameters: ["pointer", "buffer", "buffer", "buffer", "buffer"], result: "i32" },
});
// lib.symbols.SetupQueueRenameW(QueueHandle, SourcePath, SourceFilename, TargetPath, TargetFilename)
// QueueHandle : void* -> "pointer"
// SourcePath : LPCWSTR -> "buffer"
// SourceFilename : LPCWSTR optional -> "buffer"
// TargetPath : LPCWSTR optional -> "buffer"
// TargetFilename : LPCWSTR -> "buffer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetupQueueRenameW(
    void* QueueHandle,
    const uint16_t* SourcePath,
    const uint16_t* SourceFilename,
    const uint16_t* TargetPath,
    const uint16_t* TargetFilename);
C, "SETUPAPI.dll");
// $ffi->SetupQueueRenameW(QueueHandle, SourcePath, SourceFilename, TargetPath, TargetFilename);
// QueueHandle : void*
// SourcePath : LPCWSTR
// SourceFilename : LPCWSTR optional
// TargetPath : LPCWSTR optional
// TargetFilename : LPCWSTR
// 構造体/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.UNICODE_OPTIONS);
    boolean SetupQueueRenameW(
        Pointer QueueHandle,   // void*
        WString SourcePath,   // LPCWSTR
        WString SourceFilename,   // LPCWSTR optional
        WString TargetPath,   // LPCWSTR optional
        WString TargetFilename   // LPCWSTR
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("setupapi")]
lib LibSETUPAPI
  fun SetupQueueRenameW = SetupQueueRenameW(
    QueueHandle : Void*,   # void*
    SourcePath : UInt16*,   # LPCWSTR
    SourceFilename : UInt16*,   # LPCWSTR optional
    TargetPath : UInt16*,   # LPCWSTR optional
    TargetFilename : UInt16*   # LPCWSTR
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SetupQueueRenameWNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>);
typedef SetupQueueRenameWDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>);
final SetupQueueRenameW = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupQueueRenameWNative, SetupQueueRenameWDart>('SetupQueueRenameW');
// QueueHandle : void* -> Pointer<Void>
// SourcePath : LPCWSTR -> Pointer<Utf16>
// SourceFilename : LPCWSTR optional -> Pointer<Utf16>
// TargetPath : LPCWSTR optional -> Pointer<Utf16>
// TargetFilename : LPCWSTR -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetupQueueRenameW(
  QueueHandle: Pointer;   // void*
  SourcePath: PWideChar;   // LPCWSTR
  SourceFilename: PWideChar;   // LPCWSTR optional
  TargetPath: PWideChar;   // LPCWSTR optional
  TargetFilename: PWideChar   // LPCWSTR
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupQueueRenameW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetupQueueRenameW"
  c_SetupQueueRenameW :: Ptr () -> CWString -> CWString -> CWString -> CWString -> IO CInt
-- QueueHandle : void* -> Ptr ()
-- SourcePath : LPCWSTR -> CWString
-- SourceFilename : LPCWSTR optional -> CWString
-- TargetPath : LPCWSTR optional -> CWString
-- TargetFilename : LPCWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setupqueuerenamew =
  foreign "SetupQueueRenameW"
    ((ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> returning int32_t)
(* QueueHandle : void* -> (ptr void) *)
(* SourcePath : LPCWSTR -> (ptr uint16_t) *)
(* SourceFilename : LPCWSTR optional -> (ptr uint16_t) *)
(* TargetPath : LPCWSTR optional -> (ptr uint16_t) *)
(* TargetFilename : LPCWSTR -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)

(cffi:defcfun ("SetupQueueRenameW" setup-queue-rename-w :convention :stdcall) :int32
  (queue-handle :pointer)   ; void*
  (source-path (:string :encoding :utf-16le))   ; LPCWSTR
  (source-filename (:string :encoding :utf-16le))   ; LPCWSTR optional
  (target-path (:string :encoding :utf-16le))   ; LPCWSTR optional
  (target-filename (:string :encoding :utf-16le)))   ; LPCWSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetupQueueRenameW = Win32::API::More->new('SETUPAPI',
    'BOOL SetupQueueRenameW(LPVOID QueueHandle, LPCWSTR SourcePath, LPCWSTR SourceFilename, LPCWSTR TargetPath, LPCWSTR TargetFilename)');
# my $ret = $SetupQueueRenameW->Call($QueueHandle, $SourcePath, $SourceFilename, $TargetPath, $TargetFilename);
# QueueHandle : void* -> LPVOID
# SourcePath : LPCWSTR -> LPCWSTR
# SourceFilename : LPCWSTR optional -> LPCWSTR
# TargetPath : LPCWSTR optional -> LPCWSTR
# TargetFilename : LPCWSTR -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い