Win32 API 日本語リファレンス
ホームNetworking.WinInet › FtpRenameFileW

FtpRenameFileW

関数
FTPサーバー上のファイル名を変更する(Unicode版)。
DLLWININET.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL FtpRenameFileW(
    void* hConnect,
    LPCWSTR lpszExisting,
    LPCWSTR lpszNew
);

パラメーター

名前方向
hConnectvoid*in
lpszExistingLPCWSTRin
lpszNewLPCWSTRin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL FtpRenameFileW(
    void* hConnect,
    LPCWSTR lpszExisting,
    LPCWSTR lpszNew
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WININET.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool FtpRenameFileW(
    IntPtr hConnect,   // void*
    [MarshalAs(UnmanagedType.LPWStr)] string lpszExisting,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string lpszNew   // LPCWSTR
);
<DllImport("WININET.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function FtpRenameFileW(
    hConnect As IntPtr,   ' void*
    <MarshalAs(UnmanagedType.LPWStr)> lpszExisting As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> lpszNew As String   ' LPCWSTR
) As Boolean
End Function
' hConnect : void*
' lpszExisting : LPCWSTR
' lpszNew : LPCWSTR
Declare PtrSafe Function FtpRenameFileW Lib "wininet" ( _
    ByVal hConnect As LongPtr, _
    ByVal lpszExisting As LongPtr, _
    ByVal lpszNew 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

FtpRenameFileW = ctypes.windll.wininet.FtpRenameFileW
FtpRenameFileW.restype = wintypes.BOOL
FtpRenameFileW.argtypes = [
    ctypes.POINTER(None),  # hConnect : void*
    wintypes.LPCWSTR,  # lpszExisting : LPCWSTR
    wintypes.LPCWSTR,  # lpszNew : LPCWSTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	wininet = windows.NewLazySystemDLL("WININET.dll")
	procFtpRenameFileW = wininet.NewProc("FtpRenameFileW")
)

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