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

FtpOpenFileW

関数
FTPサーバー上のファイルを読み書き用に開く(Unicode版)。
DLLWININET.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

void* FtpOpenFileW(
    void* hConnect,
    LPCWSTR lpszFileName,
    DWORD dwAccess,
    FTP_FLAGS dwFlags,
    UINT_PTR dwContext   // optional
);

パラメーター

名前方向
hConnectvoid*in
lpszFileNameLPCWSTRin
dwAccessDWORDin
dwFlagsFTP_FLAGSin
dwContextUINT_PTRinoptional

戻り値の型: void*

各言語での呼び出し定義

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

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

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

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

var (
	wininet = windows.NewLazySystemDLL("WININET.dll")
	procFtpOpenFileW = wininet.NewProc("FtpOpenFileW")
)

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