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

GopherFindFirstFileW

関数
Gopherサーバーの項目検索を開始し最初の結果を得る(Unicode版)。
DLLWININET.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

void* GopherFindFirstFileW(
    void* hConnect,
    LPCWSTR lpszLocator,   // optional
    LPCWSTR lpszSearchString,   // optional
    GOPHER_FIND_DATAW* lpFindData,   // optional
    DWORD dwFlags,
    UINT_PTR dwContext   // optional
);

パラメーター

名前方向説明
hConnectvoid*inInternetConnect によって返された Gopher セッションのハンドル。
lpszLocatorLPCWSTRinoptional

検索する項目の名前を含む null 終端文字列へのポインター。次のいずれかを指定できます。

  • この関数または InternetFindNextFile 関数の前回の呼び出しによって返された Gopher ロケーター。
  • Gopher サーバーから最上位の情報が返されることを示す NULL ポインターまたは空文字列。
  • GopherCreateLocator 関数によって作成されたロケーター。
lpszSearchStringLPCWSTRinoptionalこの要求がインデックスサーバーに対するものである場合、検索する文字列を含むバッファーへのポインター。それ以外の場合、このパラメーターは NULL である必要があります。
lpFindDataGOPHER_FIND_DATAW*outoptionalこの関数によって取得された情報を受け取る GOPHER_FIND_DATA 構造体へのポインター。
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 ロケーターと検索条件を使用してサーバーとのセッションを作成し、要求されたドキュメント、バイナリファイル、インデックスサーバー、またはディレクトリツリーを検索します。(Unicode)

戻り値

成功した場合は有効な検索ハンドルを返し、それ以外の場合は NULL を返します。拡張エラー情報を取得するには、 GetLastError または InternetGetLastResponseInfo を呼び出します。

解説(Remarks)

GopherFindFirstFileFindFirstFile 関数とよく似ています。Gopher サーバーとの接続を作成し、ロケーター文字列によって参照される最初の Gopher オブジェクトに関する情報を含む単一の構造体を返します。

列挙内の最初の Gopher オブジェクトを取得するために GopherFindFirstFile を呼び出した後、アプリケーションは InternetFindNextFile 関数を使用して後続の Gopher オブジェクトを取得できます。

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

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

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

wininet.h ヘッダーは GopherFindFirstFile を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義しています。エンコーディング非依存のエイリアスの使用と、エンコーディング非依存でないコードを混在させると、コンパイルエラーや実行時エラーを引き起こす不一致につながる可能性があります。詳細については、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* GopherFindFirstFileW(
    void* hConnect,
    LPCWSTR lpszLocator,   // optional
    LPCWSTR lpszSearchString,   // optional
    GOPHER_FIND_DATAW* lpFindData,   // optional
    DWORD dwFlags,
    UINT_PTR dwContext   // optional
);
[DllImport("WININET.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern IntPtr GopherFindFirstFileW(
    IntPtr hConnect,   // void*
    [MarshalAs(UnmanagedType.LPWStr)] string lpszLocator,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string lpszSearchString,   // LPCWSTR optional
    IntPtr lpFindData,   // GOPHER_FIND_DATAW* optional, out
    uint dwFlags,   // DWORD
    UIntPtr dwContext   // UINT_PTR optional
);
<DllImport("WININET.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GopherFindFirstFileW(
    hConnect As IntPtr,   ' void*
    <MarshalAs(UnmanagedType.LPWStr)> lpszLocator As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> lpszSearchString As String,   ' LPCWSTR optional
    lpFindData As IntPtr,   ' GOPHER_FIND_DATAW* optional, out
    dwFlags As UInteger,   ' DWORD
    dwContext As UIntPtr   ' UINT_PTR optional
) As IntPtr
End Function
' hConnect : void*
' lpszLocator : LPCWSTR optional
' lpszSearchString : LPCWSTR optional
' lpFindData : GOPHER_FIND_DATAW* optional, out
' dwFlags : DWORD
' dwContext : UINT_PTR optional
Declare PtrSafe Function GopherFindFirstFileW Lib "wininet" ( _
    ByVal hConnect As LongPtr, _
    ByVal lpszLocator As LongPtr, _
    ByVal lpszSearchString As LongPtr, _
    ByVal lpFindData 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

GopherFindFirstFileW = ctypes.windll.wininet.GopherFindFirstFileW
GopherFindFirstFileW.restype = ctypes.c_void_p
GopherFindFirstFileW.argtypes = [
    ctypes.POINTER(None),  # hConnect : void*
    wintypes.LPCWSTR,  # lpszLocator : LPCWSTR optional
    wintypes.LPCWSTR,  # lpszSearchString : LPCWSTR optional
    ctypes.c_void_p,  # lpFindData : GOPHER_FIND_DATAW* optional, out
    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')
GopherFindFirstFileW = Fiddle::Function.new(
  lib['GopherFindFirstFileW'],
  [
    Fiddle::TYPE_VOIDP,  # hConnect : void*
    Fiddle::TYPE_VOIDP,  # lpszLocator : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # lpszSearchString : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # lpFindData : GOPHER_FIND_DATAW* optional, out
    -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 GopherFindFirstFileW(
        hConnect: *mut (),  // void*
        lpszLocator: *const u16,  // LPCWSTR optional
        lpszSearchString: *const u16,  // LPCWSTR optional
        lpFindData: *mut GOPHER_FIND_DATAW,  // GOPHER_FIND_DATAW* optional, out
        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 GopherFindFirstFileW(IntPtr hConnect, [MarshalAs(UnmanagedType.LPWStr)] string lpszLocator, [MarshalAs(UnmanagedType.LPWStr)] string lpszSearchString, IntPtr lpFindData, uint dwFlags, UIntPtr dwContext);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WININET_GopherFindFirstFileW' -Namespace Win32 -PassThru
# $api::GopherFindFirstFileW(hConnect, lpszLocator, lpszSearchString, lpFindData, dwFlags, dwContext)
#uselib "WININET.dll"
#func global GopherFindFirstFileW "GopherFindFirstFileW" wptr, wptr, wptr, wptr, wptr, wptr
; GopherFindFirstFileW hConnect, lpszLocator, lpszSearchString, varptr(lpFindData), dwFlags, dwContext   ; 戻り値は stat
; hConnect : void* -> "wptr"
; lpszLocator : LPCWSTR optional -> "wptr"
; lpszSearchString : LPCWSTR optional -> "wptr"
; lpFindData : GOPHER_FIND_DATAW* optional, out -> "wptr"
; dwFlags : DWORD -> "wptr"
; dwContext : UINT_PTR optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WININET.dll"
#cfunc global GopherFindFirstFileW "GopherFindFirstFileW" sptr, wstr, wstr, var, int, sptr
; res = GopherFindFirstFileW(hConnect, lpszLocator, lpszSearchString, lpFindData, dwFlags, dwContext)
; hConnect : void* -> "sptr"
; lpszLocator : LPCWSTR optional -> "wstr"
; lpszSearchString : LPCWSTR optional -> "wstr"
; lpFindData : GOPHER_FIND_DATAW* optional, out -> "var"
; dwFlags : DWORD -> "int"
; dwContext : UINT_PTR optional -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; void* GopherFindFirstFileW(void* hConnect, LPCWSTR lpszLocator, LPCWSTR lpszSearchString, GOPHER_FIND_DATAW* lpFindData, DWORD dwFlags, UINT_PTR dwContext)
#uselib "WININET.dll"
#cfunc global GopherFindFirstFileW "GopherFindFirstFileW" intptr, wstr, wstr, var, int, intptr
; res = GopherFindFirstFileW(hConnect, lpszLocator, lpszSearchString, lpFindData, dwFlags, dwContext)
; hConnect : void* -> "intptr"
; lpszLocator : LPCWSTR optional -> "wstr"
; lpszSearchString : LPCWSTR optional -> "wstr"
; lpFindData : GOPHER_FIND_DATAW* optional, out -> "var"
; dwFlags : DWORD -> "int"
; dwContext : UINT_PTR optional -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wininet = windows.NewLazySystemDLL("WININET.dll")
	procGopherFindFirstFileW = wininet.NewProc("GopherFindFirstFileW")
)

// hConnect (void*), lpszLocator (LPCWSTR optional), lpszSearchString (LPCWSTR optional), lpFindData (GOPHER_FIND_DATAW* optional, out), dwFlags (DWORD), dwContext (UINT_PTR optional)
r1, _, err := procGopherFindFirstFileW.Call(
	uintptr(hConnect),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszLocator))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszSearchString))),
	uintptr(lpFindData),
	uintptr(dwFlags),
	uintptr(dwContext),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // void*
function GopherFindFirstFileW(
  hConnect: Pointer;   // void*
  lpszLocator: PWideChar;   // LPCWSTR optional
  lpszSearchString: PWideChar;   // LPCWSTR optional
  lpFindData: Pointer;   // GOPHER_FIND_DATAW* optional, out
  dwFlags: DWORD;   // DWORD
  dwContext: NativeUInt   // UINT_PTR optional
): Pointer; stdcall;
  external 'WININET.dll' name 'GopherFindFirstFileW';
result := DllCall("WININET\GopherFindFirstFileW"
    , "Ptr", hConnect   ; void*
    , "WStr", lpszLocator   ; LPCWSTR optional
    , "WStr", lpszSearchString   ; LPCWSTR optional
    , "Ptr", lpFindData   ; GOPHER_FIND_DATAW* optional, out
    , "UInt", dwFlags   ; DWORD
    , "UPtr", dwContext   ; UINT_PTR optional
    , "Ptr")   ; return: void*
●GopherFindFirstFileW(hConnect, lpszLocator, lpszSearchString, lpFindData, dwFlags, dwContext) = DLL("WININET.dll", "void* GopherFindFirstFileW(void*, char*, char*, void*, dword, int)")
# 呼び出し: GopherFindFirstFileW(hConnect, lpszLocator, lpszSearchString, lpFindData, dwFlags, dwContext)
# hConnect : void* -> "void*"
# lpszLocator : LPCWSTR optional -> "char*"
# lpszSearchString : LPCWSTR optional -> "char*"
# lpFindData : GOPHER_FIND_DATAW* optional, out -> "void*"
# 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 GopherFindFirstFileW(
    hConnect: ?*anyopaque, // void*
    lpszLocator: [*c]const u16, // LPCWSTR optional
    lpszSearchString: [*c]const u16, // LPCWSTR optional
    lpFindData: [*c]GOPHER_FIND_DATAW, // GOPHER_FIND_DATAW* optional, out
    dwFlags: u32, // DWORD
    dwContext: usize // UINT_PTR optional
) callconv(std.os.windows.WINAPI) ?*anyopaque;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc GopherFindFirstFileW(
    hConnect: pointer,  # void*
    lpszLocator: WideCString,  # LPCWSTR optional
    lpszSearchString: WideCString,  # LPCWSTR optional
    lpFindData: ptr GOPHER_FIND_DATAW,  # GOPHER_FIND_DATAW* optional, out
    dwFlags: uint32,  # DWORD
    dwContext: uint  # UINT_PTR optional
): pointer {.importc: "GopherFindFirstFileW", stdcall, dynlib: "WININET.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "wininet");
extern(Windows)
void* GopherFindFirstFileW(
    void* hConnect,   // void*
    const(wchar)* lpszLocator,   // LPCWSTR optional
    const(wchar)* lpszSearchString,   // LPCWSTR optional
    GOPHER_FIND_DATAW* lpFindData,   // GOPHER_FIND_DATAW* optional, out
    uint dwFlags,   // DWORD
    size_t dwContext   // UINT_PTR optional
);
ccall((:GopherFindFirstFileW, "WININET.dll"), stdcall, Ptr{Cvoid},
      (Ptr{Cvoid}, Cwstring, Cwstring, Ptr{GOPHER_FIND_DATAW}, UInt32, Csize_t),
      hConnect, lpszLocator, lpszSearchString, lpFindData, dwFlags, dwContext)
# hConnect : void* -> Ptr{Cvoid}
# lpszLocator : LPCWSTR optional -> Cwstring
# lpszSearchString : LPCWSTR optional -> Cwstring
# lpFindData : GOPHER_FIND_DATAW* optional, out -> Ptr{GOPHER_FIND_DATAW}
# 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* GopherFindFirstFileW(
    void* hConnect,
    const uint16_t* lpszLocator,
    const uint16_t* lpszSearchString,
    void* lpFindData,
    uint32_t dwFlags,
    uintptr_t dwContext);
]]
local wininet = ffi.load("wininet")
-- wininet.GopherFindFirstFileW(hConnect, lpszLocator, lpszSearchString, lpFindData, dwFlags, dwContext)
-- hConnect : void*
-- lpszLocator : LPCWSTR optional
-- lpszSearchString : LPCWSTR optional
-- lpFindData : GOPHER_FIND_DATAW* optional, out
-- 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 GopherFindFirstFileW = lib.func('__stdcall', 'GopherFindFirstFileW', 'void *', ['void *', 'str16', 'str16', 'void *', 'uint32_t', 'uintptr_t']);
// GopherFindFirstFileW(hConnect, lpszLocator, lpszSearchString, lpFindData, dwFlags, dwContext)
// hConnect : void* -> 'void *'
// lpszLocator : LPCWSTR optional -> 'str16'
// lpszSearchString : LPCWSTR optional -> 'str16'
// lpFindData : GOPHER_FIND_DATAW* optional, out -> 'void *'
// dwFlags : DWORD -> 'uint32_t'
// dwContext : UINT_PTR optional -> 'uintptr_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("WININET.dll", {
  GopherFindFirstFileW: { parameters: ["pointer", "buffer", "buffer", "pointer", "u32", "usize"], result: "pointer" },
});
// lib.symbols.GopherFindFirstFileW(hConnect, lpszLocator, lpszSearchString, lpFindData, dwFlags, dwContext)
// hConnect : void* -> "pointer"
// lpszLocator : LPCWSTR optional -> "buffer"
// lpszSearchString : LPCWSTR optional -> "buffer"
// lpFindData : GOPHER_FIND_DATAW* optional, out -> "pointer"
// 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* GopherFindFirstFileW(
    void* hConnect,
    const uint16_t* lpszLocator,
    const uint16_t* lpszSearchString,
    void* lpFindData,
    uint32_t dwFlags,
    size_t dwContext);
C, "WININET.dll");
// $ffi->GopherFindFirstFileW(hConnect, lpszLocator, lpszSearchString, lpFindData, dwFlags, dwContext);
// hConnect : void*
// lpszLocator : LPCWSTR optional
// lpszSearchString : LPCWSTR optional
// lpFindData : GOPHER_FIND_DATAW* optional, out
// 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 GopherFindFirstFileW(
        Pointer hConnect,   // void*
        WString lpszLocator,   // LPCWSTR optional
        WString lpszSearchString,   // LPCWSTR optional
        Pointer lpFindData,   // GOPHER_FIND_DATAW* optional, out
        int dwFlags,   // DWORD
        long dwContext   // UINT_PTR optional
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("wininet")]
lib LibWININET
  fun GopherFindFirstFileW = GopherFindFirstFileW(
    hConnect : Void*,   # void*
    lpszLocator : UInt16*,   # LPCWSTR optional
    lpszSearchString : UInt16*,   # LPCWSTR optional
    lpFindData : GOPHER_FIND_DATAW*,   # GOPHER_FIND_DATAW* optional, out
    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 GopherFindFirstFileWNative = Pointer<Void> Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Void>, Uint32, UintPtr);
typedef GopherFindFirstFileWDart = Pointer<Void> Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Void>, int, int);
final GopherFindFirstFileW = DynamicLibrary.open('WININET.dll')
    .lookupFunction<GopherFindFirstFileWNative, GopherFindFirstFileWDart>('GopherFindFirstFileW');
// hConnect : void* -> Pointer<Void>
// lpszLocator : LPCWSTR optional -> Pointer<Utf16>
// lpszSearchString : LPCWSTR optional -> Pointer<Utf16>
// lpFindData : GOPHER_FIND_DATAW* optional, out -> Pointer<Void>
// dwFlags : DWORD -> Uint32
// dwContext : UINT_PTR optional -> UintPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GopherFindFirstFileW(
  hConnect: Pointer;   // void*
  lpszLocator: PWideChar;   // LPCWSTR optional
  lpszSearchString: PWideChar;   // LPCWSTR optional
  lpFindData: Pointer;   // GOPHER_FIND_DATAW* optional, out
  dwFlags: DWORD;   // DWORD
  dwContext: NativeUInt   // UINT_PTR optional
): Pointer; stdcall;
  external 'WININET.dll' name 'GopherFindFirstFileW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

let gopherfindfirstfilew =
  foreign "GopherFindFirstFileW"
    ((ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr void) @-> uint32_t @-> size_t @-> returning (ptr void))
(* hConnect : void* -> (ptr void) *)
(* lpszLocator : LPCWSTR optional -> (ptr uint16_t) *)
(* lpszSearchString : LPCWSTR optional -> (ptr uint16_t) *)
(* lpFindData : GOPHER_FIND_DATAW* optional, out -> (ptr void) *)
(* 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 ("GopherFindFirstFileW" gopher-find-first-file-w :convention :stdcall) :pointer
  (h-connect :pointer)   ; void*
  (lpsz-locator (:string :encoding :utf-16le))   ; LPCWSTR optional
  (lpsz-search-string (:string :encoding :utf-16le))   ; LPCWSTR optional
  (lp-find-data :pointer)   ; GOPHER_FIND_DATAW* optional, out
  (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 $GopherFindFirstFileW = Win32::API::More->new('WININET',
    'LPVOID GopherFindFirstFileW(LPVOID hConnect, LPCWSTR lpszLocator, LPCWSTR lpszSearchString, LPVOID lpFindData, DWORD dwFlags, WPARAM dwContext)');
# my $ret = $GopherFindFirstFileW->Call($hConnect, $lpszLocator, $lpszSearchString, $lpFindData, $dwFlags, $dwContext);
# hConnect : void* -> LPVOID
# lpszLocator : LPCWSTR optional -> LPCWSTR
# lpszSearchString : LPCWSTR optional -> LPCWSTR
# lpFindData : GOPHER_FIND_DATAW* optional, out -> LPVOID
# dwFlags : DWORD -> DWORD
# dwContext : UINT_PTR optional -> WPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
使用する型