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

GopherCreateLocatorW

関数
指定要素からGopherロケーター文字列を生成する(Unicode版)。
DLLWININET.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL GopherCreateLocatorW(
    LPCWSTR lpszHost,
    WORD nServerPort,
    LPCWSTR lpszDisplayString,   // optional
    LPCWSTR lpszSelectorString,   // optional
    DWORD dwGopherType,
    LPWSTR lpszLocator,   // optional
    DWORD* lpdwBufferLength
);

パラメーター

名前方向説明
lpszHostLPCWSTRinホスト名、またはドット区切りの 10 進 IP アドレス(198.105.232.1 など)を含む null 終端文字列へのポインター。
nServerPortWORDinlpszHost 上の Gopher サーバーが待ち受けるポート番号(ホストバイトオーダー)。 nServerPortINTERNET_INVALID_PORT_NUMBER の場合は、既定の Gopher ポートが使用されます。
lpszDisplayStringLPCWSTRinoptional表示する Gopher ドキュメントまたはディレクトリを含む null 終端文字列へのポインター。このパラメーターが NULL の場合、関数は Gopher サーバーの既定のディレクトリを返します。
lpszSelectorStringLPCWSTRinoptional情報を取得するために Gopher サーバーへ送信するセレクター文字列へのポインター。このパラメーターには NULL を指定できます。
dwGopherTypeDWORDinlpszSelectorString がディレクトリとドキュメントのどちらを参照するか、また要求が Gopher+ と Gopher のどちらであるかを決定します。 dwGopherType の値が 0 の場合は、既定値の GOPHER_TYPE_DIRECTORY が使用されます。これには gopher type values のいずれかを指定できます。
lpszLocatorLPWSTRoutoptionalロケーター文字列を受け取るバッファーへのポインター。 lpszLocatorNULL の場合、 lpdwBufferLength に必要なバッファー長が格納されますが、関数はそれ以外の処理を行いません。
lpdwBufferLengthDWORD*inoutlpszLocator バッファーの長さ(文字数)を格納する変数へのポインター。関数が戻るとき、このパラメーターにはバッファーに書き込まれた文字数が格納されます。 GetLastErrorERROR_INSUFFICIENT_BUFFER を返した場合、このパラメーターには必要な文字数が格納されます。

戻り値の型: BOOL

公式ドキュメント

セレクター文字列の構成要素から Gopher または Gopher+ のロケーター文字列を作成します。(Unicode)

戻り値

成功した場合は TRUE を、それ以外の場合は FALSE を返します。拡張エラー情報を取得するには、 GetLastError または InternetGetLastResponseInfo を呼び出します。

解説(Remarks)

Gopher サーバーから情報を取得するには、アプリケーションはまず Gopher サーバーから Gopher の「ロケーター」を取得する必要があります。

ロケーターは、アプリケーションが不透明なトークンとして扱うべきものであり、通常、特定の情報を取得するために GopherFindFirstFile 関数の呼び出しで使用されます。

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

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

wininet.h ヘッダーは、UNICODE プリプロセッサー定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして GopherCreateLocator を定義します。エンコーディング中立のエイリアスと、エンコーディング中立でないコードを混在させて使用すると、不一致が生じてコンパイルエラーや実行時エラーの原因となることがあります。詳細については、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>

BOOL GopherCreateLocatorW(
    LPCWSTR lpszHost,
    WORD nServerPort,
    LPCWSTR lpszDisplayString,   // optional
    LPCWSTR lpszSelectorString,   // optional
    DWORD dwGopherType,
    LPWSTR lpszLocator,   // optional
    DWORD* lpdwBufferLength
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WININET.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool GopherCreateLocatorW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpszHost,   // LPCWSTR
    ushort nServerPort,   // WORD
    [MarshalAs(UnmanagedType.LPWStr)] string lpszDisplayString,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string lpszSelectorString,   // LPCWSTR optional
    uint dwGopherType,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpszLocator,   // LPWSTR optional, out
    ref uint lpdwBufferLength   // DWORD* in/out
);
<DllImport("WININET.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GopherCreateLocatorW(
    <MarshalAs(UnmanagedType.LPWStr)> lpszHost As String,   ' LPCWSTR
    nServerPort As UShort,   ' WORD
    <MarshalAs(UnmanagedType.LPWStr)> lpszDisplayString As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> lpszSelectorString As String,   ' LPCWSTR optional
    dwGopherType As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> lpszLocator As System.Text.StringBuilder,   ' LPWSTR optional, out
    ByRef lpdwBufferLength As UInteger   ' DWORD* in/out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' lpszHost : LPCWSTR
' nServerPort : WORD
' lpszDisplayString : LPCWSTR optional
' lpszSelectorString : LPCWSTR optional
' dwGopherType : DWORD
' lpszLocator : LPWSTR optional, out
' lpdwBufferLength : DWORD* in/out
Declare PtrSafe Function GopherCreateLocatorW Lib "wininet" ( _
    ByVal lpszHost As LongPtr, _
    ByVal nServerPort As Integer, _
    ByVal lpszDisplayString As LongPtr, _
    ByVal lpszSelectorString As LongPtr, _
    ByVal dwGopherType As Long, _
    ByVal lpszLocator As LongPtr, _
    ByRef lpdwBufferLength As Long) 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

GopherCreateLocatorW = ctypes.windll.wininet.GopherCreateLocatorW
GopherCreateLocatorW.restype = wintypes.BOOL
GopherCreateLocatorW.argtypes = [
    wintypes.LPCWSTR,  # lpszHost : LPCWSTR
    ctypes.c_ushort,  # nServerPort : WORD
    wintypes.LPCWSTR,  # lpszDisplayString : LPCWSTR optional
    wintypes.LPCWSTR,  # lpszSelectorString : LPCWSTR optional
    wintypes.DWORD,  # dwGopherType : DWORD
    wintypes.LPWSTR,  # lpszLocator : LPWSTR optional, out
    ctypes.POINTER(wintypes.DWORD),  # lpdwBufferLength : DWORD* in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WININET.dll')
GopherCreateLocatorW = Fiddle::Function.new(
  lib['GopherCreateLocatorW'],
  [
    Fiddle::TYPE_VOIDP,  # lpszHost : LPCWSTR
    -Fiddle::TYPE_SHORT,  # nServerPort : WORD
    Fiddle::TYPE_VOIDP,  # lpszDisplayString : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # lpszSelectorString : LPCWSTR optional
    -Fiddle::TYPE_INT,  # dwGopherType : DWORD
    Fiddle::TYPE_VOIDP,  # lpszLocator : LPWSTR optional, out
    Fiddle::TYPE_VOIDP,  # lpdwBufferLength : DWORD* in/out
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "wininet")]
extern "system" {
    fn GopherCreateLocatorW(
        lpszHost: *const u16,  // LPCWSTR
        nServerPort: u16,  // WORD
        lpszDisplayString: *const u16,  // LPCWSTR optional
        lpszSelectorString: *const u16,  // LPCWSTR optional
        dwGopherType: u32,  // DWORD
        lpszLocator: *mut u16,  // LPWSTR optional, out
        lpdwBufferLength: *mut u32  // DWORD* in/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 GopherCreateLocatorW([MarshalAs(UnmanagedType.LPWStr)] string lpszHost, ushort nServerPort, [MarshalAs(UnmanagedType.LPWStr)] string lpszDisplayString, [MarshalAs(UnmanagedType.LPWStr)] string lpszSelectorString, uint dwGopherType, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpszLocator, ref uint lpdwBufferLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WININET_GopherCreateLocatorW' -Namespace Win32 -PassThru
# $api::GopherCreateLocatorW(lpszHost, nServerPort, lpszDisplayString, lpszSelectorString, dwGopherType, lpszLocator, lpdwBufferLength)
#uselib "WININET.dll"
#func global GopherCreateLocatorW "GopherCreateLocatorW" wptr, wptr, wptr, wptr, wptr, wptr, wptr
; GopherCreateLocatorW lpszHost, nServerPort, lpszDisplayString, lpszSelectorString, dwGopherType, varptr(lpszLocator), varptr(lpdwBufferLength)   ; 戻り値は stat
; lpszHost : LPCWSTR -> "wptr"
; nServerPort : WORD -> "wptr"
; lpszDisplayString : LPCWSTR optional -> "wptr"
; lpszSelectorString : LPCWSTR optional -> "wptr"
; dwGopherType : DWORD -> "wptr"
; lpszLocator : LPWSTR optional, out -> "wptr"
; lpdwBufferLength : DWORD* in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WININET.dll"
#cfunc global GopherCreateLocatorW "GopherCreateLocatorW" wstr, int, wstr, wstr, int, var, var
; res = GopherCreateLocatorW(lpszHost, nServerPort, lpszDisplayString, lpszSelectorString, dwGopherType, lpszLocator, lpdwBufferLength)
; lpszHost : LPCWSTR -> "wstr"
; nServerPort : WORD -> "int"
; lpszDisplayString : LPCWSTR optional -> "wstr"
; lpszSelectorString : LPCWSTR optional -> "wstr"
; dwGopherType : DWORD -> "int"
; lpszLocator : LPWSTR optional, out -> "var"
; lpdwBufferLength : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL GopherCreateLocatorW(LPCWSTR lpszHost, WORD nServerPort, LPCWSTR lpszDisplayString, LPCWSTR lpszSelectorString, DWORD dwGopherType, LPWSTR lpszLocator, DWORD* lpdwBufferLength)
#uselib "WININET.dll"
#cfunc global GopherCreateLocatorW "GopherCreateLocatorW" wstr, int, wstr, wstr, int, var, var
; res = GopherCreateLocatorW(lpszHost, nServerPort, lpszDisplayString, lpszSelectorString, dwGopherType, lpszLocator, lpdwBufferLength)
; lpszHost : LPCWSTR -> "wstr"
; nServerPort : WORD -> "int"
; lpszDisplayString : LPCWSTR optional -> "wstr"
; lpszSelectorString : LPCWSTR optional -> "wstr"
; dwGopherType : DWORD -> "int"
; lpszLocator : LPWSTR optional, out -> "var"
; lpdwBufferLength : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wininet = windows.NewLazySystemDLL("WININET.dll")
	procGopherCreateLocatorW = wininet.NewProc("GopherCreateLocatorW")
)

// lpszHost (LPCWSTR), nServerPort (WORD), lpszDisplayString (LPCWSTR optional), lpszSelectorString (LPCWSTR optional), dwGopherType (DWORD), lpszLocator (LPWSTR optional, out), lpdwBufferLength (DWORD* in/out)
r1, _, err := procGopherCreateLocatorW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszHost))),
	uintptr(nServerPort),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszDisplayString))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszSelectorString))),
	uintptr(dwGopherType),
	uintptr(lpszLocator),
	uintptr(lpdwBufferLength),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function GopherCreateLocatorW(
  lpszHost: PWideChar;   // LPCWSTR
  nServerPort: Word;   // WORD
  lpszDisplayString: PWideChar;   // LPCWSTR optional
  lpszSelectorString: PWideChar;   // LPCWSTR optional
  dwGopherType: DWORD;   // DWORD
  lpszLocator: PWideChar;   // LPWSTR optional, out
  lpdwBufferLength: Pointer   // DWORD* in/out
): BOOL; stdcall;
  external 'WININET.dll' name 'GopherCreateLocatorW';
result := DllCall("WININET\GopherCreateLocatorW"
    , "WStr", lpszHost   ; LPCWSTR
    , "UShort", nServerPort   ; WORD
    , "WStr", lpszDisplayString   ; LPCWSTR optional
    , "WStr", lpszSelectorString   ; LPCWSTR optional
    , "UInt", dwGopherType   ; DWORD
    , "Ptr", lpszLocator   ; LPWSTR optional, out
    , "Ptr", lpdwBufferLength   ; DWORD* in/out
    , "Int")   ; return: BOOL
●GopherCreateLocatorW(lpszHost, nServerPort, lpszDisplayString, lpszSelectorString, dwGopherType, lpszLocator, lpdwBufferLength) = DLL("WININET.dll", "bool GopherCreateLocatorW(char*, int, char*, char*, dword, char*, void*)")
# 呼び出し: GopherCreateLocatorW(lpszHost, nServerPort, lpszDisplayString, lpszSelectorString, dwGopherType, lpszLocator, lpdwBufferLength)
# lpszHost : LPCWSTR -> "char*"
# nServerPort : WORD -> "int"
# lpszDisplayString : LPCWSTR optional -> "char*"
# lpszSelectorString : LPCWSTR optional -> "char*"
# dwGopherType : DWORD -> "dword"
# lpszLocator : LPWSTR optional, out -> "char*"
# lpdwBufferLength : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

extern "wininet" fn GopherCreateLocatorW(
    lpszHost: [*c]const u16, // LPCWSTR
    nServerPort: u16, // WORD
    lpszDisplayString: [*c]const u16, // LPCWSTR optional
    lpszSelectorString: [*c]const u16, // LPCWSTR optional
    dwGopherType: u32, // DWORD
    lpszLocator: [*c]u16, // LPWSTR optional, out
    lpdwBufferLength: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc GopherCreateLocatorW(
    lpszHost: WideCString,  # LPCWSTR
    nServerPort: uint16,  # WORD
    lpszDisplayString: WideCString,  # LPCWSTR optional
    lpszSelectorString: WideCString,  # LPCWSTR optional
    dwGopherType: uint32,  # DWORD
    lpszLocator: ptr uint16,  # LPWSTR optional, out
    lpdwBufferLength: ptr uint32  # DWORD* in/out
): int32 {.importc: "GopherCreateLocatorW", stdcall, dynlib: "WININET.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "wininet");
extern(Windows)
int GopherCreateLocatorW(
    const(wchar)* lpszHost,   // LPCWSTR
    ushort nServerPort,   // WORD
    const(wchar)* lpszDisplayString,   // LPCWSTR optional
    const(wchar)* lpszSelectorString,   // LPCWSTR optional
    uint dwGopherType,   // DWORD
    wchar* lpszLocator,   // LPWSTR optional, out
    uint* lpdwBufferLength   // DWORD* in/out
);
ccall((:GopherCreateLocatorW, "WININET.dll"), stdcall, Int32,
      (Cwstring, UInt16, Cwstring, Cwstring, UInt32, Ptr{UInt16}, Ptr{UInt32}),
      lpszHost, nServerPort, lpszDisplayString, lpszSelectorString, dwGopherType, lpszLocator, lpdwBufferLength)
# lpszHost : LPCWSTR -> Cwstring
# nServerPort : WORD -> UInt16
# lpszDisplayString : LPCWSTR optional -> Cwstring
# lpszSelectorString : LPCWSTR optional -> Cwstring
# dwGopherType : DWORD -> UInt32
# lpszLocator : LPWSTR optional, out -> Ptr{UInt16}
# lpdwBufferLength : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
int32_t GopherCreateLocatorW(
    const uint16_t* lpszHost,
    uint16_t nServerPort,
    const uint16_t* lpszDisplayString,
    const uint16_t* lpszSelectorString,
    uint32_t dwGopherType,
    uint16_t* lpszLocator,
    uint32_t* lpdwBufferLength);
]]
local wininet = ffi.load("wininet")
-- wininet.GopherCreateLocatorW(lpszHost, nServerPort, lpszDisplayString, lpszSelectorString, dwGopherType, lpszLocator, lpdwBufferLength)
-- lpszHost : LPCWSTR
-- nServerPort : WORD
-- lpszDisplayString : LPCWSTR optional
-- lpszSelectorString : LPCWSTR optional
-- dwGopherType : DWORD
-- lpszLocator : LPWSTR optional, out
-- lpdwBufferLength : DWORD* in/out
-- 構造体/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 GopherCreateLocatorW = lib.func('__stdcall', 'GopherCreateLocatorW', 'int32_t', ['str16', 'uint16_t', 'str16', 'str16', 'uint32_t', 'uint16_t *', 'uint32_t *']);
// GopherCreateLocatorW(lpszHost, nServerPort, lpszDisplayString, lpszSelectorString, dwGopherType, lpszLocator, lpdwBufferLength)
// lpszHost : LPCWSTR -> 'str16'
// nServerPort : WORD -> 'uint16_t'
// lpszDisplayString : LPCWSTR optional -> 'str16'
// lpszSelectorString : LPCWSTR optional -> 'str16'
// dwGopherType : DWORD -> 'uint32_t'
// lpszLocator : LPWSTR optional, out -> 'uint16_t *'
// lpdwBufferLength : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("WININET.dll", {
  GopherCreateLocatorW: { parameters: ["buffer", "u16", "buffer", "buffer", "u32", "buffer", "pointer"], result: "i32" },
});
// lib.symbols.GopherCreateLocatorW(lpszHost, nServerPort, lpszDisplayString, lpszSelectorString, dwGopherType, lpszLocator, lpdwBufferLength)
// lpszHost : LPCWSTR -> "buffer"
// nServerPort : WORD -> "u16"
// lpszDisplayString : LPCWSTR optional -> "buffer"
// lpszSelectorString : LPCWSTR optional -> "buffer"
// dwGopherType : DWORD -> "u32"
// lpszLocator : LPWSTR optional, out -> "buffer"
// lpdwBufferLength : DWORD* in/out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t GopherCreateLocatorW(
    const uint16_t* lpszHost,
    uint16_t nServerPort,
    const uint16_t* lpszDisplayString,
    const uint16_t* lpszSelectorString,
    uint32_t dwGopherType,
    uint16_t* lpszLocator,
    uint32_t* lpdwBufferLength);
C, "WININET.dll");
// $ffi->GopherCreateLocatorW(lpszHost, nServerPort, lpszDisplayString, lpszSelectorString, dwGopherType, lpszLocator, lpdwBufferLength);
// lpszHost : LPCWSTR
// nServerPort : WORD
// lpszDisplayString : LPCWSTR optional
// lpszSelectorString : LPCWSTR optional
// dwGopherType : DWORD
// lpszLocator : LPWSTR optional, out
// lpdwBufferLength : DWORD* in/out
// 構造体/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);
    boolean GopherCreateLocatorW(
        WString lpszHost,   // LPCWSTR
        short nServerPort,   // WORD
        WString lpszDisplayString,   // LPCWSTR optional
        WString lpszSelectorString,   // LPCWSTR optional
        int dwGopherType,   // DWORD
        char[] lpszLocator,   // LPWSTR optional, out
        IntByReference lpdwBufferLength   // DWORD* in/out
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("wininet")]
lib LibWININET
  fun GopherCreateLocatorW = GopherCreateLocatorW(
    lpszHost : UInt16*,   # LPCWSTR
    nServerPort : UInt16,   # WORD
    lpszDisplayString : UInt16*,   # LPCWSTR optional
    lpszSelectorString : UInt16*,   # LPCWSTR optional
    dwGopherType : UInt32,   # DWORD
    lpszLocator : UInt16*,   # LPWSTR optional, out
    lpdwBufferLength : UInt32*   # DWORD* in/out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef GopherCreateLocatorWNative = Int32 Function(Pointer<Utf16>, Uint16, Pointer<Utf16>, Pointer<Utf16>, Uint32, Pointer<Utf16>, Pointer<Uint32>);
typedef GopherCreateLocatorWDart = int Function(Pointer<Utf16>, int, Pointer<Utf16>, Pointer<Utf16>, int, Pointer<Utf16>, Pointer<Uint32>);
final GopherCreateLocatorW = DynamicLibrary.open('WININET.dll')
    .lookupFunction<GopherCreateLocatorWNative, GopherCreateLocatorWDart>('GopherCreateLocatorW');
// lpszHost : LPCWSTR -> Pointer<Utf16>
// nServerPort : WORD -> Uint16
// lpszDisplayString : LPCWSTR optional -> Pointer<Utf16>
// lpszSelectorString : LPCWSTR optional -> Pointer<Utf16>
// dwGopherType : DWORD -> Uint32
// lpszLocator : LPWSTR optional, out -> Pointer<Utf16>
// lpdwBufferLength : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GopherCreateLocatorW(
  lpszHost: PWideChar;   // LPCWSTR
  nServerPort: Word;   // WORD
  lpszDisplayString: PWideChar;   // LPCWSTR optional
  lpszSelectorString: PWideChar;   // LPCWSTR optional
  dwGopherType: DWORD;   // DWORD
  lpszLocator: PWideChar;   // LPWSTR optional, out
  lpdwBufferLength: Pointer   // DWORD* in/out
): BOOL; stdcall;
  external 'WININET.dll' name 'GopherCreateLocatorW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GopherCreateLocatorW"
  c_GopherCreateLocatorW :: CWString -> Word16 -> CWString -> CWString -> Word32 -> CWString -> Ptr Word32 -> IO CInt
-- lpszHost : LPCWSTR -> CWString
-- nServerPort : WORD -> Word16
-- lpszDisplayString : LPCWSTR optional -> CWString
-- lpszSelectorString : LPCWSTR optional -> CWString
-- dwGopherType : DWORD -> Word32
-- lpszLocator : LPWSTR optional, out -> CWString
-- lpdwBufferLength : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let gophercreatelocatorw =
  foreign "GopherCreateLocatorW"
    ((ptr uint16_t) @-> uint16_t @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> (ptr uint16_t) @-> (ptr uint32_t) @-> returning int32_t)
(* lpszHost : LPCWSTR -> (ptr uint16_t) *)
(* nServerPort : WORD -> uint16_t *)
(* lpszDisplayString : LPCWSTR optional -> (ptr uint16_t) *)
(* lpszSelectorString : LPCWSTR optional -> (ptr uint16_t) *)
(* dwGopherType : DWORD -> uint32_t *)
(* lpszLocator : LPWSTR optional, out -> (ptr uint16_t) *)
(* lpdwBufferLength : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library wininet (t "WININET.dll"))
(cffi:use-foreign-library wininet)

(cffi:defcfun ("GopherCreateLocatorW" gopher-create-locator-w :convention :stdcall) :int32
  (lpsz-host (:string :encoding :utf-16le))   ; LPCWSTR
  (n-server-port :uint16)   ; WORD
  (lpsz-display-string (:string :encoding :utf-16le))   ; LPCWSTR optional
  (lpsz-selector-string (:string :encoding :utf-16le))   ; LPCWSTR optional
  (dw-gopher-type :uint32)   ; DWORD
  (lpsz-locator :pointer)   ; LPWSTR optional, out
  (lpdw-buffer-length :pointer))   ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GopherCreateLocatorW = Win32::API::More->new('WININET',
    'BOOL GopherCreateLocatorW(LPCWSTR lpszHost, WORD nServerPort, LPCWSTR lpszDisplayString, LPCWSTR lpszSelectorString, DWORD dwGopherType, LPWSTR lpszLocator, LPVOID lpdwBufferLength)');
# my $ret = $GopherCreateLocatorW->Call($lpszHost, $nServerPort, $lpszDisplayString, $lpszSelectorString, $dwGopherType, $lpszLocator, $lpdwBufferLength);
# lpszHost : LPCWSTR -> LPCWSTR
# nServerPort : WORD -> WORD
# lpszDisplayString : LPCWSTR optional -> LPCWSTR
# lpszSelectorString : LPCWSTR optional -> LPCWSTR
# dwGopherType : DWORD -> DWORD
# lpszLocator : LPWSTR optional, out -> LPWSTR
# lpdwBufferLength : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い