ホーム › Devices.DeviceAndDriverInstallation › SetupRenameErrorW
SetupRenameErrorW
関数ファイル名変更エラーを通知するダイアログを表示する(Unicode)。
シグネチャ
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
DWORD SetupRenameErrorW(
HWND hwndParent,
LPCWSTR DialogTitle, // optional
LPCWSTR SourceFile,
LPCWSTR TargetFile,
DWORD Win32ErrorCode,
DWORD Style
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hwndParent | HWND | in | エラーダイアログの親ウィンドウハンドル。NULL可。 |
| DialogTitle | LPCWSTR | inoptional | ダイアログのタイトル文字列(Unicode)。NULLで既定値を使う。 |
| SourceFile | LPCWSTR | in | リネーム元ファイル名(Unicode)。 |
| TargetFile | LPCWSTR | in | リネーム先ファイル名(Unicode)。 |
| Win32ErrorCode | DWORD | in | 発生したWin32エラーコード。表示メッセージの決定に使う。 |
| Style | DWORD | in | ダイアログの表示動作を制御するスタイルフラグ。 |
戻り値の型: DWORD
各言語での呼び出し定義
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
DWORD SetupRenameErrorW(
HWND hwndParent,
LPCWSTR DialogTitle, // optional
LPCWSTR SourceFile,
LPCWSTR TargetFile,
DWORD Win32ErrorCode,
DWORD Style
);[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern uint SetupRenameErrorW(
IntPtr hwndParent, // HWND
[MarshalAs(UnmanagedType.LPWStr)] string DialogTitle, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string SourceFile, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string TargetFile, // LPCWSTR
uint Win32ErrorCode, // DWORD
uint Style // DWORD
);<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupRenameErrorW(
hwndParent As IntPtr, ' HWND
<MarshalAs(UnmanagedType.LPWStr)> DialogTitle As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> SourceFile As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> TargetFile As String, ' LPCWSTR
Win32ErrorCode As UInteger, ' DWORD
Style As UInteger ' DWORD
) As UInteger
End Function' hwndParent : HWND
' DialogTitle : LPCWSTR optional
' SourceFile : LPCWSTR
' TargetFile : LPCWSTR
' Win32ErrorCode : DWORD
' Style : DWORD
Declare PtrSafe Function SetupRenameErrorW Lib "setupapi" ( _
ByVal hwndParent As LongPtr, _
ByVal DialogTitle As LongPtr, _
ByVal SourceFile As LongPtr, _
ByVal TargetFile As LongPtr, _
ByVal Win32ErrorCode As Long, _
ByVal Style As Long) 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
SetupRenameErrorW = ctypes.windll.setupapi.SetupRenameErrorW
SetupRenameErrorW.restype = wintypes.DWORD
SetupRenameErrorW.argtypes = [
wintypes.HANDLE, # hwndParent : HWND
wintypes.LPCWSTR, # DialogTitle : LPCWSTR optional
wintypes.LPCWSTR, # SourceFile : LPCWSTR
wintypes.LPCWSTR, # TargetFile : LPCWSTR
wintypes.DWORD, # Win32ErrorCode : DWORD
wintypes.DWORD, # Style : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SETUPAPI.dll')
SetupRenameErrorW = Fiddle::Function.new(
lib['SetupRenameErrorW'],
[
Fiddle::TYPE_VOIDP, # hwndParent : HWND
Fiddle::TYPE_VOIDP, # DialogTitle : LPCWSTR optional
Fiddle::TYPE_VOIDP, # SourceFile : LPCWSTR
Fiddle::TYPE_VOIDP, # TargetFile : LPCWSTR
-Fiddle::TYPE_INT, # Win32ErrorCode : DWORD
-Fiddle::TYPE_INT, # Style : DWORD
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "setupapi")]
extern "system" {
fn SetupRenameErrorW(
hwndParent: *mut core::ffi::c_void, // HWND
DialogTitle: *const u16, // LPCWSTR optional
SourceFile: *const u16, // LPCWSTR
TargetFile: *const u16, // LPCWSTR
Win32ErrorCode: u32, // DWORD
Style: u32 // DWORD
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern uint SetupRenameErrorW(IntPtr hwndParent, [MarshalAs(UnmanagedType.LPWStr)] string DialogTitle, [MarshalAs(UnmanagedType.LPWStr)] string SourceFile, [MarshalAs(UnmanagedType.LPWStr)] string TargetFile, uint Win32ErrorCode, uint Style);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupRenameErrorW' -Namespace Win32 -PassThru
# $api::SetupRenameErrorW(hwndParent, DialogTitle, SourceFile, TargetFile, Win32ErrorCode, Style)#uselib "SETUPAPI.dll"
#func global SetupRenameErrorW "SetupRenameErrorW" wptr, wptr, wptr, wptr, wptr, wptr
; SetupRenameErrorW hwndParent, DialogTitle, SourceFile, TargetFile, Win32ErrorCode, Style ; 戻り値は stat
; hwndParent : HWND -> "wptr"
; DialogTitle : LPCWSTR optional -> "wptr"
; SourceFile : LPCWSTR -> "wptr"
; TargetFile : LPCWSTR -> "wptr"
; Win32ErrorCode : DWORD -> "wptr"
; Style : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SETUPAPI.dll"
#cfunc global SetupRenameErrorW "SetupRenameErrorW" sptr, wstr, wstr, wstr, int, int
; res = SetupRenameErrorW(hwndParent, DialogTitle, SourceFile, TargetFile, Win32ErrorCode, Style)
; hwndParent : HWND -> "sptr"
; DialogTitle : LPCWSTR optional -> "wstr"
; SourceFile : LPCWSTR -> "wstr"
; TargetFile : LPCWSTR -> "wstr"
; Win32ErrorCode : DWORD -> "int"
; Style : DWORD -> "int"; DWORD SetupRenameErrorW(HWND hwndParent, LPCWSTR DialogTitle, LPCWSTR SourceFile, LPCWSTR TargetFile, DWORD Win32ErrorCode, DWORD Style)
#uselib "SETUPAPI.dll"
#cfunc global SetupRenameErrorW "SetupRenameErrorW" intptr, wstr, wstr, wstr, int, int
; res = SetupRenameErrorW(hwndParent, DialogTitle, SourceFile, TargetFile, Win32ErrorCode, Style)
; hwndParent : HWND -> "intptr"
; DialogTitle : LPCWSTR optional -> "wstr"
; SourceFile : LPCWSTR -> "wstr"
; TargetFile : LPCWSTR -> "wstr"
; Win32ErrorCode : DWORD -> "int"
; Style : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
procSetupRenameErrorW = setupapi.NewProc("SetupRenameErrorW")
)
// hwndParent (HWND), DialogTitle (LPCWSTR optional), SourceFile (LPCWSTR), TargetFile (LPCWSTR), Win32ErrorCode (DWORD), Style (DWORD)
r1, _, err := procSetupRenameErrorW.Call(
uintptr(hwndParent),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(DialogTitle))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(SourceFile))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(TargetFile))),
uintptr(Win32ErrorCode),
uintptr(Style),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction SetupRenameErrorW(
hwndParent: THandle; // HWND
DialogTitle: PWideChar; // LPCWSTR optional
SourceFile: PWideChar; // LPCWSTR
TargetFile: PWideChar; // LPCWSTR
Win32ErrorCode: DWORD; // DWORD
Style: DWORD // DWORD
): DWORD; stdcall;
external 'SETUPAPI.dll' name 'SetupRenameErrorW';result := DllCall("SETUPAPI\SetupRenameErrorW"
, "Ptr", hwndParent ; HWND
, "WStr", DialogTitle ; LPCWSTR optional
, "WStr", SourceFile ; LPCWSTR
, "WStr", TargetFile ; LPCWSTR
, "UInt", Win32ErrorCode ; DWORD
, "UInt", Style ; DWORD
, "UInt") ; return: DWORD●SetupRenameErrorW(hwndParent, DialogTitle, SourceFile, TargetFile, Win32ErrorCode, Style) = DLL("SETUPAPI.dll", "dword SetupRenameErrorW(void*, char*, char*, char*, dword, dword)")
# 呼び出し: SetupRenameErrorW(hwndParent, DialogTitle, SourceFile, TargetFile, Win32ErrorCode, Style)
# hwndParent : HWND -> "void*"
# DialogTitle : LPCWSTR optional -> "char*"
# SourceFile : LPCWSTR -> "char*"
# TargetFile : LPCWSTR -> "char*"
# Win32ErrorCode : DWORD -> "dword"
# Style : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "setupapi" fn SetupRenameErrorW(
hwndParent: ?*anyopaque, // HWND
DialogTitle: [*c]const u16, // LPCWSTR optional
SourceFile: [*c]const u16, // LPCWSTR
TargetFile: [*c]const u16, // LPCWSTR
Win32ErrorCode: u32, // DWORD
Style: u32 // DWORD
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc SetupRenameErrorW(
hwndParent: pointer, # HWND
DialogTitle: WideCString, # LPCWSTR optional
SourceFile: WideCString, # LPCWSTR
TargetFile: WideCString, # LPCWSTR
Win32ErrorCode: uint32, # DWORD
Style: uint32 # DWORD
): uint32 {.importc: "SetupRenameErrorW", stdcall, dynlib: "SETUPAPI.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "setupapi");
extern(Windows)
uint SetupRenameErrorW(
void* hwndParent, // HWND
const(wchar)* DialogTitle, // LPCWSTR optional
const(wchar)* SourceFile, // LPCWSTR
const(wchar)* TargetFile, // LPCWSTR
uint Win32ErrorCode, // DWORD
uint Style // DWORD
);ccall((:SetupRenameErrorW, "SETUPAPI.dll"), stdcall, UInt32,
(Ptr{Cvoid}, Cwstring, Cwstring, Cwstring, UInt32, UInt32),
hwndParent, DialogTitle, SourceFile, TargetFile, Win32ErrorCode, Style)
# hwndParent : HWND -> Ptr{Cvoid}
# DialogTitle : LPCWSTR optional -> Cwstring
# SourceFile : LPCWSTR -> Cwstring
# TargetFile : LPCWSTR -> Cwstring
# Win32ErrorCode : DWORD -> UInt32
# Style : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t SetupRenameErrorW(
void* hwndParent,
const uint16_t* DialogTitle,
const uint16_t* SourceFile,
const uint16_t* TargetFile,
uint32_t Win32ErrorCode,
uint32_t Style);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupRenameErrorW(hwndParent, DialogTitle, SourceFile, TargetFile, Win32ErrorCode, Style)
-- hwndParent : HWND
-- DialogTitle : LPCWSTR optional
-- SourceFile : LPCWSTR
-- TargetFile : LPCWSTR
-- Win32ErrorCode : DWORD
-- Style : DWORD
-- 構造体/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 SetupRenameErrorW = lib.func('__stdcall', 'SetupRenameErrorW', 'uint32_t', ['void *', 'str16', 'str16', 'str16', 'uint32_t', 'uint32_t']);
// SetupRenameErrorW(hwndParent, DialogTitle, SourceFile, TargetFile, Win32ErrorCode, Style)
// hwndParent : HWND -> 'void *'
// DialogTitle : LPCWSTR optional -> 'str16'
// SourceFile : LPCWSTR -> 'str16'
// TargetFile : LPCWSTR -> 'str16'
// Win32ErrorCode : DWORD -> 'uint32_t'
// Style : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SETUPAPI.dll", {
SetupRenameErrorW: { parameters: ["pointer", "buffer", "buffer", "buffer", "u32", "u32"], result: "u32" },
});
// lib.symbols.SetupRenameErrorW(hwndParent, DialogTitle, SourceFile, TargetFile, Win32ErrorCode, Style)
// hwndParent : HWND -> "pointer"
// DialogTitle : LPCWSTR optional -> "buffer"
// SourceFile : LPCWSTR -> "buffer"
// TargetFile : LPCWSTR -> "buffer"
// Win32ErrorCode : DWORD -> "u32"
// Style : DWORD -> "u32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t SetupRenameErrorW(
void* hwndParent,
const uint16_t* DialogTitle,
const uint16_t* SourceFile,
const uint16_t* TargetFile,
uint32_t Win32ErrorCode,
uint32_t Style);
C, "SETUPAPI.dll");
// $ffi->SetupRenameErrorW(hwndParent, DialogTitle, SourceFile, TargetFile, Win32ErrorCode, Style);
// hwndParent : HWND
// DialogTitle : LPCWSTR optional
// SourceFile : LPCWSTR
// TargetFile : LPCWSTR
// Win32ErrorCode : DWORD
// Style : 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.UNICODE_OPTIONS);
int SetupRenameErrorW(
Pointer hwndParent, // HWND
WString DialogTitle, // LPCWSTR optional
WString SourceFile, // LPCWSTR
WString TargetFile, // LPCWSTR
int Win32ErrorCode, // DWORD
int Style // DWORD
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("setupapi")]
lib LibSETUPAPI
fun SetupRenameErrorW = SetupRenameErrorW(
hwndParent : Void*, # HWND
DialogTitle : UInt16*, # LPCWSTR optional
SourceFile : UInt16*, # LPCWSTR
TargetFile : UInt16*, # LPCWSTR
Win32ErrorCode : UInt32, # DWORD
Style : UInt32 # DWORD
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetupRenameErrorWNative = Uint32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Uint32, Uint32);
typedef SetupRenameErrorWDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, int, int);
final SetupRenameErrorW = DynamicLibrary.open('SETUPAPI.dll')
.lookupFunction<SetupRenameErrorWNative, SetupRenameErrorWDart>('SetupRenameErrorW');
// hwndParent : HWND -> Pointer<Void>
// DialogTitle : LPCWSTR optional -> Pointer<Utf16>
// SourceFile : LPCWSTR -> Pointer<Utf16>
// TargetFile : LPCWSTR -> Pointer<Utf16>
// Win32ErrorCode : DWORD -> Uint32
// Style : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetupRenameErrorW(
hwndParent: THandle; // HWND
DialogTitle: PWideChar; // LPCWSTR optional
SourceFile: PWideChar; // LPCWSTR
TargetFile: PWideChar; // LPCWSTR
Win32ErrorCode: DWORD; // DWORD
Style: DWORD // DWORD
): DWORD; stdcall;
external 'SETUPAPI.dll' name 'SetupRenameErrorW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetupRenameErrorW"
c_SetupRenameErrorW :: Ptr () -> CWString -> CWString -> CWString -> Word32 -> Word32 -> IO Word32
-- hwndParent : HWND -> Ptr ()
-- DialogTitle : LPCWSTR optional -> CWString
-- SourceFile : LPCWSTR -> CWString
-- TargetFile : LPCWSTR -> CWString
-- Win32ErrorCode : DWORD -> Word32
-- Style : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setuprenameerrorw =
foreign "SetupRenameErrorW"
((ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> uint32_t @-> returning uint32_t)
(* hwndParent : HWND -> (ptr void) *)
(* DialogTitle : LPCWSTR optional -> (ptr uint16_t) *)
(* SourceFile : LPCWSTR -> (ptr uint16_t) *)
(* TargetFile : LPCWSTR -> (ptr uint16_t) *)
(* Win32ErrorCode : DWORD -> uint32_t *)
(* Style : 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 ("SetupRenameErrorW" setup-rename-error-w :convention :stdcall) :uint32
(hwnd-parent :pointer) ; HWND
(dialog-title (:string :encoding :utf-16le)) ; LPCWSTR optional
(source-file (:string :encoding :utf-16le)) ; LPCWSTR
(target-file (:string :encoding :utf-16le)) ; LPCWSTR
(win32-error-code :uint32) ; DWORD
(style :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetupRenameErrorW = Win32::API::More->new('SETUPAPI',
'DWORD SetupRenameErrorW(HANDLE hwndParent, LPCWSTR DialogTitle, LPCWSTR SourceFile, LPCWSTR TargetFile, DWORD Win32ErrorCode, DWORD Style)');
# my $ret = $SetupRenameErrorW->Call($hwndParent, $DialogTitle, $SourceFile, $TargetFile, $Win32ErrorCode, $Style);
# hwndParent : HWND -> HANDLE
# DialogTitle : LPCWSTR optional -> LPCWSTR
# SourceFile : LPCWSTR -> LPCWSTR
# TargetFile : LPCWSTR -> LPCWSTR
# Win32ErrorCode : DWORD -> DWORD
# Style : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f SetupRenameErrorA (ANSI版) — ファイル名変更エラーを通知するダイアログを表示する(ANSI)。