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

GopherOpenFileW

関数
Gopherサーバー上の項目を読み取り用に開く(Unicode版)。
DLLWININET.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

void* GopherOpenFileW(
    void* hConnect,
    LPCWSTR lpszLocator,
    LPCWSTR lpszView,   // optional
    DWORD dwFlags,
    UINT_PTR dwContext   // optional
);

パラメーター

名前方向説明
hConnectvoid*inInternetConnect が返した Gopher セッションへのハンドル。
lpszLocatorLPCWSTRin開くファイルを指定する null 終端文字列へのポインター。通常、このロケーターは GopherFindFirstFile または InternetFindNextFile の呼び出しから返されます。Gopher プロトコルにはカレントディレクトリの概念がないため、ロケーターは常に完全修飾されています。
lpszViewLPCWSTRinoptionalサーバー上にファイルの複数のビューが存在する場合に開くビューを記述する null 終端文字列へのポインター。 lpszViewNULL の場合、関数は既定のファイルビューを使用します。
dwFlagsDWORDin

後続の転送が行われる条件。このパラメーターには次のいずれかの値を指定できます。

意味
INTERNET_FLAG_HYPERLINK
項目をネットワークから再読み込みするかどうかを判断する際に、サーバーから Expires 時刻も LastModified 時刻も返されなかった場合に、強制的に再読み込みします。
INTERNET_FLAG_NEED_FILE
ファイルをキャッシュできない場合に一時ファイルを作成します。
INTERNET_FLAG_NO_CACHE_WRITE
返されたエンティティをキャッシュに追加しません。
INTERNET_FLAG_RELOAD
要求されたファイル、オブジェクト、またはディレクトリ一覧を、キャッシュからではなくオリジンサーバーから強制的にダウンロードします。
INTERNET_FLAG_RESYNCHRONIZE
前回ダウンロードしてからリソースが変更されている場合に、HTTP リソースを再読み込みします。すべての FTP および Gopher リソースは再読み込みされます。
dwContextUINT_PTRinoptionalこの操作を任意のアプリケーションデータと関連付ける、アプリケーション定義の値を格納する変数へのポインター。

戻り値の型: void*

公式ドキュメント

Gopher サーバーから Gopher データファイルの読み取りを開始します。(Unicode)

戻り値

成功した場合はハンドルを返し、ファイルを開けない場合は NULL を返します。拡張エラー情報を取得するには、 GetLastError または InternetGetLastResponseInfo を呼び出します。

解説(Remarks)

GopherOpenFile は Gopher サーバー上のファイルを開きます。サーバー上で実際にファイルを開いたりロックしたりすることはできないため、この関数は単に位置情報をハンドルに関連付けます。アプリケーションはそのハンドルを使用して、 InternetReadFileGopherGetAttribute などのファイルベースの操作を行えます。

呼び出し元のアプリケーションが GopherOpenFile によって返された HINTERNET ハンドルの使用を終えたら、 InternetCloseHandle 関数を使用してそれを閉じる必要があります。

WinINet API の他のすべての側面と同様に、この関数は DllMain やグローバルオブジェクトのコンストラクター・デストラクターの内部から安全に呼び出すことはできません。

注意 WinINet はサーバー実装をサポートしていません。また、サービスから使用すべきではありません。サーバー実装やサービスには Microsoft Windows HTTP Services (WinHTTP) を使用してください。
メモ

wininet.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして GopherOpenFile を定義しています。エンコーディング非依存のエイリアスの使用と、エンコーディング非依存でないコードを混在させると、不一致が生じ、コンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、Conventions for Function Prototypes を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

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

GopherOpenFileW = ctypes.windll.wininet.GopherOpenFileW
GopherOpenFileW.restype = ctypes.c_void_p
GopherOpenFileW.argtypes = [
    ctypes.POINTER(None),  # hConnect : void*
    wintypes.LPCWSTR,  # lpszLocator : LPCWSTR
    wintypes.LPCWSTR,  # lpszView : LPCWSTR optional
    wintypes.DWORD,  # dwFlags : DWORD
    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')
GopherOpenFileW = Fiddle::Function.new(
  lib['GopherOpenFileW'],
  [
    Fiddle::TYPE_VOIDP,  # hConnect : void*
    Fiddle::TYPE_VOIDP,  # lpszLocator : LPCWSTR
    Fiddle::TYPE_VOIDP,  # lpszView : LPCWSTR optional
    -Fiddle::TYPE_INT,  # dwFlags : DWORD
    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 GopherOpenFileW(
        hConnect: *mut (),  // void*
        lpszLocator: *const u16,  // LPCWSTR
        lpszView: *const u16,  // LPCWSTR optional
        dwFlags: u32,  // DWORD
        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 GopherOpenFileW(IntPtr hConnect, [MarshalAs(UnmanagedType.LPWStr)] string lpszLocator, [MarshalAs(UnmanagedType.LPWStr)] string lpszView, uint dwFlags, UIntPtr dwContext);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WININET_GopherOpenFileW' -Namespace Win32 -PassThru
# $api::GopherOpenFileW(hConnect, lpszLocator, lpszView, dwFlags, dwContext)
#uselib "WININET.dll"
#func global GopherOpenFileW "GopherOpenFileW" wptr, wptr, wptr, wptr, wptr
; GopherOpenFileW hConnect, lpszLocator, lpszView, dwFlags, dwContext   ; 戻り値は stat
; hConnect : void* -> "wptr"
; lpszLocator : LPCWSTR -> "wptr"
; lpszView : LPCWSTR optional -> "wptr"
; dwFlags : DWORD -> "wptr"
; dwContext : UINT_PTR optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "WININET.dll"
#cfunc global GopherOpenFileW "GopherOpenFileW" sptr, wstr, wstr, int, sptr
; res = GopherOpenFileW(hConnect, lpszLocator, lpszView, dwFlags, dwContext)
; hConnect : void* -> "sptr"
; lpszLocator : LPCWSTR -> "wstr"
; lpszView : LPCWSTR optional -> "wstr"
; dwFlags : DWORD -> "int"
; dwContext : UINT_PTR optional -> "sptr"
; void* GopherOpenFileW(void* hConnect, LPCWSTR lpszLocator, LPCWSTR lpszView, DWORD dwFlags, UINT_PTR dwContext)
#uselib "WININET.dll"
#cfunc global GopherOpenFileW "GopherOpenFileW" intptr, wstr, wstr, int, intptr
; res = GopherOpenFileW(hConnect, lpszLocator, lpszView, dwFlags, dwContext)
; hConnect : void* -> "intptr"
; lpszLocator : LPCWSTR -> "wstr"
; lpszView : LPCWSTR optional -> "wstr"
; dwFlags : DWORD -> "int"
; dwContext : UINT_PTR optional -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wininet = windows.NewLazySystemDLL("WININET.dll")
	procGopherOpenFileW = wininet.NewProc("GopherOpenFileW")
)

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

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

typedef GopherOpenFileWNative = Pointer<Void> Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Uint32, UintPtr);
typedef GopherOpenFileWDart = Pointer<Void> Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, int, int);
final GopherOpenFileW = DynamicLibrary.open('WININET.dll')
    .lookupFunction<GopherOpenFileWNative, GopherOpenFileWDart>('GopherOpenFileW');
// hConnect : void* -> Pointer<Void>
// lpszLocator : LPCWSTR -> Pointer<Utf16>
// lpszView : LPCWSTR optional -> Pointer<Utf16>
// dwFlags : DWORD -> Uint32
// dwContext : UINT_PTR optional -> UintPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GopherOpenFileW(
  hConnect: Pointer;   // void*
  lpszLocator: PWideChar;   // LPCWSTR
  lpszView: PWideChar;   // LPCWSTR optional
  dwFlags: DWORD;   // DWORD
  dwContext: NativeUInt   // UINT_PTR optional
): Pointer; stdcall;
  external 'WININET.dll' name 'GopherOpenFileW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GopherOpenFileW"
  c_GopherOpenFileW :: Ptr () -> CWString -> CWString -> Word32 -> CUIntPtr -> IO (Ptr ())
-- hConnect : void* -> Ptr ()
-- lpszLocator : LPCWSTR -> CWString
-- lpszView : LPCWSTR optional -> CWString
-- dwFlags : DWORD -> Word32
-- dwContext : UINT_PTR optional -> CUIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let gopheropenfilew =
  foreign "GopherOpenFileW"
    ((ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> size_t @-> returning (ptr void))
(* hConnect : void* -> (ptr void) *)
(* lpszLocator : LPCWSTR -> (ptr uint16_t) *)
(* lpszView : LPCWSTR optional -> (ptr uint16_t) *)
(* dwFlags : DWORD -> uint32_t *)
(* dwContext : UINT_PTR optional -> size_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library wininet (t "WININET.dll"))
(cffi:use-foreign-library wininet)

(cffi:defcfun ("GopherOpenFileW" gopher-open-file-w :convention :stdcall) :pointer
  (h-connect :pointer)   ; void*
  (lpsz-locator (:string :encoding :utf-16le))   ; LPCWSTR
  (lpsz-view (:string :encoding :utf-16le))   ; LPCWSTR optional
  (dw-flags :uint32)   ; DWORD
  (dw-context :uint64))   ; UINT_PTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GopherOpenFileW = Win32::API::More->new('WININET',
    'LPVOID GopherOpenFileW(LPVOID hConnect, LPCWSTR lpszLocator, LPCWSTR lpszView, DWORD dwFlags, WPARAM dwContext)');
# my $ret = $GopherOpenFileW->Call($hConnect, $lpszLocator, $lpszView, $dwFlags, $dwContext);
# hConnect : void* -> LPVOID
# lpszLocator : LPCWSTR -> LPCWSTR
# lpszView : LPCWSTR optional -> LPCWSTR
# dwFlags : DWORD -> DWORD
# dwContext : UINT_PTR optional -> WPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い