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

FtpCommandW

関数
FTPサーバーへ任意のコマンドを直接送信する(Unicode版)。
DLLWININET.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL FtpCommandW(
    void* hConnect,
    BOOL fExpectResponse,
    FTP_FLAGS dwFlags,
    LPCWSTR lpszCommand,
    UINT_PTR dwContext,   // optional
    void** phFtpCommand   // optional
);

パラメーター

名前方向
hConnectvoid*in
fExpectResponseBOOLin
dwFlagsFTP_FLAGSin
lpszCommandLPCWSTRin
dwContextUINT_PTRinoptional
phFtpCommandvoid**outoptional

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL FtpCommandW(
    void* hConnect,
    BOOL fExpectResponse,
    FTP_FLAGS dwFlags,
    LPCWSTR lpszCommand,
    UINT_PTR dwContext,   // optional
    void** phFtpCommand   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WININET.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool FtpCommandW(
    IntPtr hConnect,   // void*
    bool fExpectResponse,   // BOOL
    uint dwFlags,   // FTP_FLAGS
    [MarshalAs(UnmanagedType.LPWStr)] string lpszCommand,   // LPCWSTR
    UIntPtr dwContext,   // UINT_PTR optional
    IntPtr phFtpCommand   // void** optional, out
);
<DllImport("WININET.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function FtpCommandW(
    hConnect As IntPtr,   ' void*
    fExpectResponse As Boolean,   ' BOOL
    dwFlags As UInteger,   ' FTP_FLAGS
    <MarshalAs(UnmanagedType.LPWStr)> lpszCommand As String,   ' LPCWSTR
    dwContext As UIntPtr,   ' UINT_PTR optional
    phFtpCommand As IntPtr   ' void** optional, out
) As Boolean
End Function
' hConnect : void*
' fExpectResponse : BOOL
' dwFlags : FTP_FLAGS
' lpszCommand : LPCWSTR
' dwContext : UINT_PTR optional
' phFtpCommand : void** optional, out
Declare PtrSafe Function FtpCommandW Lib "wininet" ( _
    ByVal hConnect As LongPtr, _
    ByVal fExpectResponse As Long, _
    ByVal dwFlags As Long, _
    ByVal lpszCommand As LongPtr, _
    ByVal dwContext As LongPtr, _
    ByVal phFtpCommand 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

FtpCommandW = ctypes.windll.wininet.FtpCommandW
FtpCommandW.restype = wintypes.BOOL
FtpCommandW.argtypes = [
    ctypes.POINTER(None),  # hConnect : void*
    wintypes.BOOL,  # fExpectResponse : BOOL
    wintypes.DWORD,  # dwFlags : FTP_FLAGS
    wintypes.LPCWSTR,  # lpszCommand : LPCWSTR
    ctypes.c_size_t,  # dwContext : UINT_PTR optional
    ctypes.c_void_p,  # phFtpCommand : void** optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WININET.dll')
FtpCommandW = Fiddle::Function.new(
  lib['FtpCommandW'],
  [
    Fiddle::TYPE_VOIDP,  # hConnect : void*
    Fiddle::TYPE_INT,  # fExpectResponse : BOOL
    -Fiddle::TYPE_INT,  # dwFlags : FTP_FLAGS
    Fiddle::TYPE_VOIDP,  # lpszCommand : LPCWSTR
    Fiddle::TYPE_UINTPTR_T,  # dwContext : UINT_PTR optional
    Fiddle::TYPE_VOIDP,  # phFtpCommand : void** optional, out
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "wininet")]
extern "system" {
    fn FtpCommandW(
        hConnect: *mut (),  // void*
        fExpectResponse: i32,  // BOOL
        dwFlags: u32,  // FTP_FLAGS
        lpszCommand: *const u16,  // LPCWSTR
        dwContext: usize,  // UINT_PTR optional
        phFtpCommand: *mut *mut ()  // void** optional, out
    ) -> 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 FtpCommandW(IntPtr hConnect, bool fExpectResponse, uint dwFlags, [MarshalAs(UnmanagedType.LPWStr)] string lpszCommand, UIntPtr dwContext, IntPtr phFtpCommand);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WININET_FtpCommandW' -Namespace Win32 -PassThru
# $api::FtpCommandW(hConnect, fExpectResponse, dwFlags, lpszCommand, dwContext, phFtpCommand)
#uselib "WININET.dll"
#func global FtpCommandW "FtpCommandW" wptr, wptr, wptr, wptr, wptr, wptr
; FtpCommandW hConnect, fExpectResponse, dwFlags, lpszCommand, dwContext, phFtpCommand   ; 戻り値は stat
; hConnect : void* -> "wptr"
; fExpectResponse : BOOL -> "wptr"
; dwFlags : FTP_FLAGS -> "wptr"
; lpszCommand : LPCWSTR -> "wptr"
; dwContext : UINT_PTR optional -> "wptr"
; phFtpCommand : void** optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "WININET.dll"
#cfunc global FtpCommandW "FtpCommandW" sptr, int, int, wstr, sptr, sptr
; res = FtpCommandW(hConnect, fExpectResponse, dwFlags, lpszCommand, dwContext, phFtpCommand)
; hConnect : void* -> "sptr"
; fExpectResponse : BOOL -> "int"
; dwFlags : FTP_FLAGS -> "int"
; lpszCommand : LPCWSTR -> "wstr"
; dwContext : UINT_PTR optional -> "sptr"
; phFtpCommand : void** optional, out -> "sptr"
; BOOL FtpCommandW(void* hConnect, BOOL fExpectResponse, FTP_FLAGS dwFlags, LPCWSTR lpszCommand, UINT_PTR dwContext, void** phFtpCommand)
#uselib "WININET.dll"
#cfunc global FtpCommandW "FtpCommandW" intptr, int, int, wstr, intptr, intptr
; res = FtpCommandW(hConnect, fExpectResponse, dwFlags, lpszCommand, dwContext, phFtpCommand)
; hConnect : void* -> "intptr"
; fExpectResponse : BOOL -> "int"
; dwFlags : FTP_FLAGS -> "int"
; lpszCommand : LPCWSTR -> "wstr"
; dwContext : UINT_PTR optional -> "intptr"
; phFtpCommand : void** optional, out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wininet = windows.NewLazySystemDLL("WININET.dll")
	procFtpCommandW = wininet.NewProc("FtpCommandW")
)

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