GopherOpenFileA
関数シグネチャ
// WININET.dll (ANSI / -A)
#include <windows.h>
void* GopherOpenFileA(
void* hConnect,
LPCSTR lpszLocator,
LPCSTR lpszView, // optional
DWORD dwFlags,
UINT_PTR dwContext // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hConnect | void* | in | InternetConnect によって返された Gopher セッションへのハンドル。 | ||||||||||||
| lpszLocator | LPCSTR | in | 開くファイルを指定する null 終端文字列へのポインター。通常、このロケーターは GopherFindFirstFile または InternetFindNextFile の呼び出しから返されます。Gopher プロトコルにはカレントディレクトリの概念がないため、ロケーターは常に完全修飾されています。 | ||||||||||||
| lpszView | LPCSTR | inoptional | サーバー上にファイルの複数のビューが存在する場合に、開くビューを記述する null 終端文字列へのポインター。 lpszView が NULL の場合、関数は既定のファイルビューを使用します。 | ||||||||||||
| dwFlags | DWORD | in | 以降の転送が行われる条件。このパラメーターには次のいずれかの値を指定できます。
| ||||||||||||
| dwContext | UINT_PTR | inoptional | この操作を任意のアプリケーションデータに関連付ける、アプリケーション定義の値を含む変数へのポインター。 |
戻り値の型: void*
公式ドキュメント
Gopher サーバーから Gopher データファイルの読み取りを開始します。(ANSI)
戻り値
成功した場合はハンドルを返し、ファイルを開けない場合は NULL を返します。拡張エラー情報を取得するには、 GetLastError または InternetGetLastResponseInfo を呼び出します。
解説(Remarks)
GopherOpenFile は、Gopher サーバー上のファイルを開きます。サーバー上で実際にファイルを開いたりロックしたりすることはできないため、この関数は単に位置情報をハンドルに関連付けます。アプリケーションは、そのハンドルを InternetReadFile や GopherGetAttribute などのファイルベースの操作に使用できます。
呼び出し元のアプリケーションは、 GopherOpenFile によって返された HINTERNET ハンドルの使用を終えたら、 InternetCloseHandle 関数を使用してそれを閉じる必要があります。
WinINet API の他のすべての側面と同様に、この関数を DllMain やグローバルオブジェクトのコンストラクターおよびデストラクター内から安全に呼び出すことはできません。
wininet.h ヘッダーは、GopherOpenFile を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義します。エンコーディング中立のエイリアスの使用を、エンコーディング中立でないコードと混在させると、コンパイルエラーまたは実行時エラーを引き起こす不一致につながる可能性があります。詳細については、「関数プロトタイプの規則」を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// WININET.dll (ANSI / -A)
#include <windows.h>
void* GopherOpenFileA(
void* hConnect,
LPCSTR lpszLocator,
LPCSTR lpszView, // optional
DWORD dwFlags,
UINT_PTR dwContext // optional
);[DllImport("WININET.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern IntPtr GopherOpenFileA(
IntPtr hConnect, // void*
[MarshalAs(UnmanagedType.LPStr)] string lpszLocator, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] string lpszView, // LPCSTR optional
uint dwFlags, // DWORD
UIntPtr dwContext // UINT_PTR optional
);<DllImport("WININET.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GopherOpenFileA(
hConnect As IntPtr, ' void*
<MarshalAs(UnmanagedType.LPStr)> lpszLocator As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> lpszView As String, ' LPCSTR optional
dwFlags As UInteger, ' DWORD
dwContext As UIntPtr ' UINT_PTR optional
) As IntPtr
End Function' hConnect : void*
' lpszLocator : LPCSTR
' lpszView : LPCSTR optional
' dwFlags : DWORD
' dwContext : UINT_PTR optional
Declare PtrSafe Function GopherOpenFileA Lib "wininet" ( _
ByVal hConnect As LongPtr, _
ByVal lpszLocator As String, _
ByVal lpszView As String, _
ByVal dwFlags As Long, _
ByVal dwContext As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GopherOpenFileA = ctypes.windll.wininet.GopherOpenFileA
GopherOpenFileA.restype = ctypes.c_void_p
GopherOpenFileA.argtypes = [
ctypes.POINTER(None), # hConnect : void*
wintypes.LPCSTR, # lpszLocator : LPCSTR
wintypes.LPCSTR, # lpszView : LPCSTR 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')
GopherOpenFileA = Fiddle::Function.new(
lib['GopherOpenFileA'],
[
Fiddle::TYPE_VOIDP, # hConnect : void*
Fiddle::TYPE_VOIDP, # lpszLocator : LPCSTR
Fiddle::TYPE_VOIDP, # lpszView : LPCSTR optional
-Fiddle::TYPE_INT, # dwFlags : DWORD
Fiddle::TYPE_UINTPTR_T, # dwContext : UINT_PTR optional
],
Fiddle::TYPE_VOIDP)#[link(name = "wininet")]
extern "system" {
fn GopherOpenFileA(
hConnect: *mut (), // void*
lpszLocator: *const u8, // LPCSTR
lpszView: *const u8, // LPCSTR 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.Ansi, SetLastError = true)]
public static extern IntPtr GopherOpenFileA(IntPtr hConnect, [MarshalAs(UnmanagedType.LPStr)] string lpszLocator, [MarshalAs(UnmanagedType.LPStr)] string lpszView, uint dwFlags, UIntPtr dwContext);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WININET_GopherOpenFileA' -Namespace Win32 -PassThru
# $api::GopherOpenFileA(hConnect, lpszLocator, lpszView, dwFlags, dwContext)#uselib "WININET.dll"
#func global GopherOpenFileA "GopherOpenFileA" sptr, sptr, sptr, sptr, sptr
; GopherOpenFileA hConnect, lpszLocator, lpszView, dwFlags, dwContext ; 戻り値は stat
; hConnect : void* -> "sptr"
; lpszLocator : LPCSTR -> "sptr"
; lpszView : LPCSTR optional -> "sptr"
; dwFlags : DWORD -> "sptr"
; dwContext : UINT_PTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WININET.dll"
#cfunc global GopherOpenFileA "GopherOpenFileA" sptr, str, str, int, sptr
; res = GopherOpenFileA(hConnect, lpszLocator, lpszView, dwFlags, dwContext)
; hConnect : void* -> "sptr"
; lpszLocator : LPCSTR -> "str"
; lpszView : LPCSTR optional -> "str"
; dwFlags : DWORD -> "int"
; dwContext : UINT_PTR optional -> "sptr"; void* GopherOpenFileA(void* hConnect, LPCSTR lpszLocator, LPCSTR lpszView, DWORD dwFlags, UINT_PTR dwContext)
#uselib "WININET.dll"
#cfunc global GopherOpenFileA "GopherOpenFileA" intptr, str, str, int, intptr
; res = GopherOpenFileA(hConnect, lpszLocator, lpszView, dwFlags, dwContext)
; hConnect : void* -> "intptr"
; lpszLocator : LPCSTR -> "str"
; lpszView : LPCSTR optional -> "str"
; dwFlags : DWORD -> "int"
; dwContext : UINT_PTR optional -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wininet = windows.NewLazySystemDLL("WININET.dll")
procGopherOpenFileA = wininet.NewProc("GopherOpenFileA")
)
// hConnect (void*), lpszLocator (LPCSTR), lpszView (LPCSTR optional), dwFlags (DWORD), dwContext (UINT_PTR optional)
r1, _, err := procGopherOpenFileA.Call(
uintptr(hConnect),
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpszLocator))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpszView))),
uintptr(dwFlags),
uintptr(dwContext),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // void*function GopherOpenFileA(
hConnect: Pointer; // void*
lpszLocator: PAnsiChar; // LPCSTR
lpszView: PAnsiChar; // LPCSTR optional
dwFlags: DWORD; // DWORD
dwContext: NativeUInt // UINT_PTR optional
): Pointer; stdcall;
external 'WININET.dll' name 'GopherOpenFileA';result := DllCall("WININET\GopherOpenFileA"
, "Ptr", hConnect ; void*
, "AStr", lpszLocator ; LPCSTR
, "AStr", lpszView ; LPCSTR optional
, "UInt", dwFlags ; DWORD
, "UPtr", dwContext ; UINT_PTR optional
, "Ptr") ; return: void*●GopherOpenFileA(hConnect, lpszLocator, lpszView, dwFlags, dwContext) = DLL("WININET.dll", "void* GopherOpenFileA(void*, char*, char*, dword, int)")
# 呼び出し: GopherOpenFileA(hConnect, lpszLocator, lpszView, dwFlags, dwContext)
# hConnect : void* -> "void*"
# lpszLocator : LPCSTR -> "char*"
# lpszView : LPCSTR optional -> "char*"
# dwFlags : DWORD -> "dword"
# dwContext : UINT_PTR optional -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "wininet" fn GopherOpenFileA(
hConnect: ?*anyopaque, // void*
lpszLocator: [*c]const u8, // LPCSTR
lpszView: [*c]const u8, // LPCSTR optional
dwFlags: u32, // DWORD
dwContext: usize // UINT_PTR optional
) callconv(std.os.windows.WINAPI) ?*anyopaque;proc GopherOpenFileA(
hConnect: pointer, # void*
lpszLocator: cstring, # LPCSTR
lpszView: cstring, # LPCSTR optional
dwFlags: uint32, # DWORD
dwContext: uint # UINT_PTR optional
): pointer {.importc: "GopherOpenFileA", stdcall, dynlib: "WININET.dll".}pragma(lib, "wininet");
extern(Windows)
void* GopherOpenFileA(
void* hConnect, // void*
const(char)* lpszLocator, // LPCSTR
const(char)* lpszView, // LPCSTR optional
uint dwFlags, // DWORD
size_t dwContext // UINT_PTR optional
);ccall((:GopherOpenFileA, "WININET.dll"), stdcall, Ptr{Cvoid},
(Ptr{Cvoid}, Cstring, Cstring, UInt32, Csize_t),
hConnect, lpszLocator, lpszView, dwFlags, dwContext)
# hConnect : void* -> Ptr{Cvoid}
# lpszLocator : LPCSTR -> Cstring
# lpszView : LPCSTR optional -> Cstring
# dwFlags : DWORD -> UInt32
# dwContext : UINT_PTR optional -> Csize_t
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void* GopherOpenFileA(
void* hConnect,
const char* lpszLocator,
const char* lpszView,
uint32_t dwFlags,
uintptr_t dwContext);
]]
local wininet = ffi.load("wininet")
-- wininet.GopherOpenFileA(hConnect, lpszLocator, lpszView, dwFlags, dwContext)
-- hConnect : void*
-- lpszLocator : LPCSTR
-- lpszView : LPCSTR optional
-- dwFlags : DWORD
-- dwContext : UINT_PTR optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('WININET.dll');
const GopherOpenFileA = lib.func('__stdcall', 'GopherOpenFileA', 'void *', ['void *', 'str', 'str', 'uint32_t', 'uintptr_t']);
// GopherOpenFileA(hConnect, lpszLocator, lpszView, dwFlags, dwContext)
// hConnect : void* -> 'void *'
// lpszLocator : LPCSTR -> 'str'
// lpszView : LPCSTR optional -> 'str'
// dwFlags : DWORD -> 'uint32_t'
// dwContext : UINT_PTR optional -> 'uintptr_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WININET.dll", {
GopherOpenFileA: { parameters: ["pointer", "buffer", "buffer", "u32", "usize"], result: "pointer" },
});
// lib.symbols.GopherOpenFileA(hConnect, lpszLocator, lpszView, dwFlags, dwContext)
// hConnect : void* -> "pointer"
// lpszLocator : LPCSTR -> "buffer"
// lpszView : LPCSTR optional -> "buffer"
// dwFlags : DWORD -> "u32"
// dwContext : UINT_PTR optional -> "usize"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* GopherOpenFileA(
void* hConnect,
const char* lpszLocator,
const char* lpszView,
uint32_t dwFlags,
size_t dwContext);
C, "WININET.dll");
// $ffi->GopherOpenFileA(hConnect, lpszLocator, lpszView, dwFlags, dwContext);
// hConnect : void*
// lpszLocator : LPCSTR
// lpszView : LPCSTR 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.ASCII_OPTIONS);
Pointer GopherOpenFileA(
Pointer hConnect, // void*
String lpszLocator, // LPCSTR
String lpszView, // LPCSTR optional
int dwFlags, // DWORD
long dwContext // UINT_PTR optional
);
}@[Link("wininet")]
lib LibWININET
fun GopherOpenFileA = GopherOpenFileA(
hConnect : Void*, # void*
lpszLocator : UInt8*, # LPCSTR
lpszView : UInt8*, # LPCSTR 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 GopherOpenFileANative = Pointer<Void> Function(Pointer<Void>, Pointer<Utf8>, Pointer<Utf8>, Uint32, UintPtr);
typedef GopherOpenFileADart = Pointer<Void> Function(Pointer<Void>, Pointer<Utf8>, Pointer<Utf8>, int, int);
final GopherOpenFileA = DynamicLibrary.open('WININET.dll')
.lookupFunction<GopherOpenFileANative, GopherOpenFileADart>('GopherOpenFileA');
// hConnect : void* -> Pointer<Void>
// lpszLocator : LPCSTR -> Pointer<Utf8>
// lpszView : LPCSTR optional -> Pointer<Utf8>
// dwFlags : DWORD -> Uint32
// dwContext : UINT_PTR optional -> UintPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GopherOpenFileA(
hConnect: Pointer; // void*
lpszLocator: PAnsiChar; // LPCSTR
lpszView: PAnsiChar; // LPCSTR optional
dwFlags: DWORD; // DWORD
dwContext: NativeUInt // UINT_PTR optional
): Pointer; stdcall;
external 'WININET.dll' name 'GopherOpenFileA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GopherOpenFileA"
c_GopherOpenFileA :: Ptr () -> CString -> CString -> Word32 -> CUIntPtr -> IO (Ptr ())
-- hConnect : void* -> Ptr ()
-- lpszLocator : LPCSTR -> CString
-- lpszView : LPCSTR optional -> CString
-- dwFlags : DWORD -> Word32
-- dwContext : UINT_PTR optional -> CUIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let gopheropenfilea =
foreign "GopherOpenFileA"
((ptr void) @-> string @-> string @-> uint32_t @-> size_t @-> returning (ptr void))
(* hConnect : void* -> (ptr void) *)
(* lpszLocator : LPCSTR -> string *)
(* lpszView : LPCSTR optional -> string *)
(* 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 ("GopherOpenFileA" gopher-open-file-a :convention :stdcall) :pointer
(h-connect :pointer) ; void*
(lpsz-locator :string) ; LPCSTR
(lpsz-view :string) ; LPCSTR 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 $GopherOpenFileA = Win32::API::More->new('WININET',
'LPVOID GopherOpenFileA(LPVOID hConnect, LPCSTR lpszLocator, LPCSTR lpszView, DWORD dwFlags, WPARAM dwContext)');
# my $ret = $GopherOpenFileA->Call($hConnect, $lpszLocator, $lpszView, $dwFlags, $dwContext);
# hConnect : void* -> LPVOID
# lpszLocator : LPCSTR -> LPCSTR
# lpszView : LPCSTR optional -> LPCSTR
# dwFlags : DWORD -> DWORD
# dwContext : UINT_PTR optional -> WPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f GopherOpenFileW (Unicode版) — Gopherサーバー上の項目を読み取り用に開く(Unicode版)。