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

GopherCreateLocatorA

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

シグネチャ

// WININET.dll  (ANSI / -A)
#include <windows.h>

BOOL GopherCreateLocatorA(
    LPCSTR lpszHost,
    WORD nServerPort,
    LPCSTR lpszDisplayString,   // optional
    LPCSTR lpszSelectorString,   // optional
    DWORD dwGopherType,
    LPSTR lpszLocator,   // optional
    DWORD* lpdwBufferLength
);

パラメーター

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

戻り値の型: BOOL

公式ドキュメント

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

戻り値

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

解説(Remarks)

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

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

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

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

wininet.h ヘッダーは GopherCreateLocator を、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  (ANSI / -A)
#include <windows.h>

BOOL GopherCreateLocatorA(
    LPCSTR lpszHost,
    WORD nServerPort,
    LPCSTR lpszDisplayString,   // optional
    LPCSTR lpszSelectorString,   // optional
    DWORD dwGopherType,
    LPSTR lpszLocator,   // optional
    DWORD* lpdwBufferLength
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WININET.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool GopherCreateLocatorA(
    [MarshalAs(UnmanagedType.LPStr)] string lpszHost,   // LPCSTR
    ushort nServerPort,   // WORD
    [MarshalAs(UnmanagedType.LPStr)] string lpszDisplayString,   // LPCSTR optional
    [MarshalAs(UnmanagedType.LPStr)] string lpszSelectorString,   // LPCSTR optional
    uint dwGopherType,   // DWORD
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpszLocator,   // LPSTR optional, out
    ref uint lpdwBufferLength   // DWORD* in/out
);
<DllImport("WININET.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GopherCreateLocatorA(
    <MarshalAs(UnmanagedType.LPStr)> lpszHost As String,   ' LPCSTR
    nServerPort As UShort,   ' WORD
    <MarshalAs(UnmanagedType.LPStr)> lpszDisplayString As String,   ' LPCSTR optional
    <MarshalAs(UnmanagedType.LPStr)> lpszSelectorString As String,   ' LPCSTR optional
    dwGopherType As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPStr)> lpszLocator As System.Text.StringBuilder,   ' LPSTR optional, out
    ByRef lpdwBufferLength As UInteger   ' DWORD* in/out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' lpszHost : LPCSTR
' nServerPort : WORD
' lpszDisplayString : LPCSTR optional
' lpszSelectorString : LPCSTR optional
' dwGopherType : DWORD
' lpszLocator : LPSTR optional, out
' lpdwBufferLength : DWORD* in/out
Declare PtrSafe Function GopherCreateLocatorA Lib "wininet" ( _
    ByVal lpszHost As String, _
    ByVal nServerPort As Integer, _
    ByVal lpszDisplayString As String, _
    ByVal lpszSelectorString As String, _
    ByVal dwGopherType As Long, _
    ByVal lpszLocator As String, _
    ByRef lpdwBufferLength As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GopherCreateLocatorA = ctypes.windll.wininet.GopherCreateLocatorA
GopherCreateLocatorA.restype = wintypes.BOOL
GopherCreateLocatorA.argtypes = [
    wintypes.LPCSTR,  # lpszHost : LPCSTR
    ctypes.c_ushort,  # nServerPort : WORD
    wintypes.LPCSTR,  # lpszDisplayString : LPCSTR optional
    wintypes.LPCSTR,  # lpszSelectorString : LPCSTR optional
    wintypes.DWORD,  # dwGopherType : DWORD
    wintypes.LPSTR,  # lpszLocator : LPSTR 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')
GopherCreateLocatorA = Fiddle::Function.new(
  lib['GopherCreateLocatorA'],
  [
    Fiddle::TYPE_VOIDP,  # lpszHost : LPCSTR
    -Fiddle::TYPE_SHORT,  # nServerPort : WORD
    Fiddle::TYPE_VOIDP,  # lpszDisplayString : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # lpszSelectorString : LPCSTR optional
    -Fiddle::TYPE_INT,  # dwGopherType : DWORD
    Fiddle::TYPE_VOIDP,  # lpszLocator : LPSTR optional, out
    Fiddle::TYPE_VOIDP,  # lpdwBufferLength : DWORD* in/out
  ],
  Fiddle::TYPE_INT)
#[link(name = "wininet")]
extern "system" {
    fn GopherCreateLocatorA(
        lpszHost: *const u8,  // LPCSTR
        nServerPort: u16,  // WORD
        lpszDisplayString: *const u8,  // LPCSTR optional
        lpszSelectorString: *const u8,  // LPCSTR optional
        dwGopherType: u32,  // DWORD
        lpszLocator: *mut u8,  // LPSTR 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.Ansi, SetLastError = true)]
public static extern bool GopherCreateLocatorA([MarshalAs(UnmanagedType.LPStr)] string lpszHost, ushort nServerPort, [MarshalAs(UnmanagedType.LPStr)] string lpszDisplayString, [MarshalAs(UnmanagedType.LPStr)] string lpszSelectorString, uint dwGopherType, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpszLocator, ref uint lpdwBufferLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WININET_GopherCreateLocatorA' -Namespace Win32 -PassThru
# $api::GopherCreateLocatorA(lpszHost, nServerPort, lpszDisplayString, lpszSelectorString, dwGopherType, lpszLocator, lpdwBufferLength)
#uselib "WININET.dll"
#func global GopherCreateLocatorA "GopherCreateLocatorA" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; GopherCreateLocatorA lpszHost, nServerPort, lpszDisplayString, lpszSelectorString, dwGopherType, varptr(lpszLocator), varptr(lpdwBufferLength)   ; 戻り値は stat
; lpszHost : LPCSTR -> "sptr"
; nServerPort : WORD -> "sptr"
; lpszDisplayString : LPCSTR optional -> "sptr"
; lpszSelectorString : LPCSTR optional -> "sptr"
; dwGopherType : DWORD -> "sptr"
; lpszLocator : LPSTR optional, out -> "sptr"
; lpdwBufferLength : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WININET.dll"
#cfunc global GopherCreateLocatorA "GopherCreateLocatorA" str, int, str, str, int, var, var
; res = GopherCreateLocatorA(lpszHost, nServerPort, lpszDisplayString, lpszSelectorString, dwGopherType, lpszLocator, lpdwBufferLength)
; lpszHost : LPCSTR -> "str"
; nServerPort : WORD -> "int"
; lpszDisplayString : LPCSTR optional -> "str"
; lpszSelectorString : LPCSTR optional -> "str"
; dwGopherType : DWORD -> "int"
; lpszLocator : LPSTR optional, out -> "var"
; lpdwBufferLength : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL GopherCreateLocatorA(LPCSTR lpszHost, WORD nServerPort, LPCSTR lpszDisplayString, LPCSTR lpszSelectorString, DWORD dwGopherType, LPSTR lpszLocator, DWORD* lpdwBufferLength)
#uselib "WININET.dll"
#cfunc global GopherCreateLocatorA "GopherCreateLocatorA" str, int, str, str, int, var, var
; res = GopherCreateLocatorA(lpszHost, nServerPort, lpszDisplayString, lpszSelectorString, dwGopherType, lpszLocator, lpdwBufferLength)
; lpszHost : LPCSTR -> "str"
; nServerPort : WORD -> "int"
; lpszDisplayString : LPCSTR optional -> "str"
; lpszSelectorString : LPCSTR optional -> "str"
; dwGopherType : DWORD -> "int"
; lpszLocator : LPSTR optional, out -> "var"
; lpdwBufferLength : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wininet = windows.NewLazySystemDLL("WININET.dll")
	procGopherCreateLocatorA = wininet.NewProc("GopherCreateLocatorA")
)

// lpszHost (LPCSTR), nServerPort (WORD), lpszDisplayString (LPCSTR optional), lpszSelectorString (LPCSTR optional), dwGopherType (DWORD), lpszLocator (LPSTR optional, out), lpdwBufferLength (DWORD* in/out)
r1, _, err := procGopherCreateLocatorA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpszHost))),
	uintptr(nServerPort),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpszDisplayString))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpszSelectorString))),
	uintptr(dwGopherType),
	uintptr(lpszLocator),
	uintptr(lpdwBufferLength),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function GopherCreateLocatorA(
  lpszHost: PAnsiChar;   // LPCSTR
  nServerPort: Word;   // WORD
  lpszDisplayString: PAnsiChar;   // LPCSTR optional
  lpszSelectorString: PAnsiChar;   // LPCSTR optional
  dwGopherType: DWORD;   // DWORD
  lpszLocator: PAnsiChar;   // LPSTR optional, out
  lpdwBufferLength: Pointer   // DWORD* in/out
): BOOL; stdcall;
  external 'WININET.dll' name 'GopherCreateLocatorA';
result := DllCall("WININET\GopherCreateLocatorA"
    , "AStr", lpszHost   ; LPCSTR
    , "UShort", nServerPort   ; WORD
    , "AStr", lpszDisplayString   ; LPCSTR optional
    , "AStr", lpszSelectorString   ; LPCSTR optional
    , "UInt", dwGopherType   ; DWORD
    , "Ptr", lpszLocator   ; LPSTR optional, out
    , "Ptr", lpdwBufferLength   ; DWORD* in/out
    , "Int")   ; return: BOOL
●GopherCreateLocatorA(lpszHost, nServerPort, lpszDisplayString, lpszSelectorString, dwGopherType, lpszLocator, lpdwBufferLength) = DLL("WININET.dll", "bool GopherCreateLocatorA(char*, int, char*, char*, dword, char*, void*)")
# 呼び出し: GopherCreateLocatorA(lpszHost, nServerPort, lpszDisplayString, lpszSelectorString, dwGopherType, lpszLocator, lpdwBufferLength)
# lpszHost : LPCSTR -> "char*"
# nServerPort : WORD -> "int"
# lpszDisplayString : LPCSTR optional -> "char*"
# lpszSelectorString : LPCSTR optional -> "char*"
# dwGopherType : DWORD -> "dword"
# lpszLocator : LPSTR optional, out -> "char*"
# lpdwBufferLength : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "wininet" fn GopherCreateLocatorA(
    lpszHost: [*c]const u8, // LPCSTR
    nServerPort: u16, // WORD
    lpszDisplayString: [*c]const u8, // LPCSTR optional
    lpszSelectorString: [*c]const u8, // LPCSTR optional
    dwGopherType: u32, // DWORD
    lpszLocator: [*c]u8, // LPSTR optional, out
    lpdwBufferLength: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) i32;
proc GopherCreateLocatorA(
    lpszHost: cstring,  # LPCSTR
    nServerPort: uint16,  # WORD
    lpszDisplayString: cstring,  # LPCSTR optional
    lpszSelectorString: cstring,  # LPCSTR optional
    dwGopherType: uint32,  # DWORD
    lpszLocator: ptr char,  # LPSTR optional, out
    lpdwBufferLength: ptr uint32  # DWORD* in/out
): int32 {.importc: "GopherCreateLocatorA", stdcall, dynlib: "WININET.dll".}
pragma(lib, "wininet");
extern(Windows)
int GopherCreateLocatorA(
    const(char)* lpszHost,   // LPCSTR
    ushort nServerPort,   // WORD
    const(char)* lpszDisplayString,   // LPCSTR optional
    const(char)* lpszSelectorString,   // LPCSTR optional
    uint dwGopherType,   // DWORD
    char* lpszLocator,   // LPSTR optional, out
    uint* lpdwBufferLength   // DWORD* in/out
);
ccall((:GopherCreateLocatorA, "WININET.dll"), stdcall, Int32,
      (Cstring, UInt16, Cstring, Cstring, UInt32, Ptr{UInt8}, Ptr{UInt32}),
      lpszHost, nServerPort, lpszDisplayString, lpszSelectorString, dwGopherType, lpszLocator, lpdwBufferLength)
# lpszHost : LPCSTR -> Cstring
# nServerPort : WORD -> UInt16
# lpszDisplayString : LPCSTR optional -> Cstring
# lpszSelectorString : LPCSTR optional -> Cstring
# dwGopherType : DWORD -> UInt32
# lpszLocator : LPSTR optional, out -> Ptr{UInt8}
# lpdwBufferLength : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t GopherCreateLocatorA(
    const char* lpszHost,
    uint16_t nServerPort,
    const char* lpszDisplayString,
    const char* lpszSelectorString,
    uint32_t dwGopherType,
    char* lpszLocator,
    uint32_t* lpdwBufferLength);
]]
local wininet = ffi.load("wininet")
-- wininet.GopherCreateLocatorA(lpszHost, nServerPort, lpszDisplayString, lpszSelectorString, dwGopherType, lpszLocator, lpdwBufferLength)
-- lpszHost : LPCSTR
-- nServerPort : WORD
-- lpszDisplayString : LPCSTR optional
-- lpszSelectorString : LPCSTR optional
-- dwGopherType : DWORD
-- lpszLocator : LPSTR optional, out
-- lpdwBufferLength : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('WININET.dll');
const GopherCreateLocatorA = lib.func('__stdcall', 'GopherCreateLocatorA', 'int32_t', ['str', 'uint16_t', 'str', 'str', 'uint32_t', 'char *', 'uint32_t *']);
// GopherCreateLocatorA(lpszHost, nServerPort, lpszDisplayString, lpszSelectorString, dwGopherType, lpszLocator, lpdwBufferLength)
// lpszHost : LPCSTR -> 'str'
// nServerPort : WORD -> 'uint16_t'
// lpszDisplayString : LPCSTR optional -> 'str'
// lpszSelectorString : LPCSTR optional -> 'str'
// dwGopherType : DWORD -> 'uint32_t'
// lpszLocator : LPSTR optional, out -> 'char *'
// lpdwBufferLength : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("WININET.dll", {
  GopherCreateLocatorA: { parameters: ["buffer", "u16", "buffer", "buffer", "u32", "buffer", "pointer"], result: "i32" },
});
// lib.symbols.GopherCreateLocatorA(lpszHost, nServerPort, lpszDisplayString, lpszSelectorString, dwGopherType, lpszLocator, lpdwBufferLength)
// lpszHost : LPCSTR -> "buffer"
// nServerPort : WORD -> "u16"
// lpszDisplayString : LPCSTR optional -> "buffer"
// lpszSelectorString : LPCSTR optional -> "buffer"
// dwGopherType : DWORD -> "u32"
// lpszLocator : LPSTR optional, out -> "buffer"
// lpdwBufferLength : DWORD* in/out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t GopherCreateLocatorA(
    const char* lpszHost,
    uint16_t nServerPort,
    const char* lpszDisplayString,
    const char* lpszSelectorString,
    uint32_t dwGopherType,
    char* lpszLocator,
    uint32_t* lpdwBufferLength);
C, "WININET.dll");
// $ffi->GopherCreateLocatorA(lpszHost, nServerPort, lpszDisplayString, lpszSelectorString, dwGopherType, lpszLocator, lpdwBufferLength);
// lpszHost : LPCSTR
// nServerPort : WORD
// lpszDisplayString : LPCSTR optional
// lpszSelectorString : LPCSTR optional
// dwGopherType : DWORD
// lpszLocator : LPSTR 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.ASCII_OPTIONS);
    boolean GopherCreateLocatorA(
        String lpszHost,   // LPCSTR
        short nServerPort,   // WORD
        String lpszDisplayString,   // LPCSTR optional
        String lpszSelectorString,   // LPCSTR optional
        int dwGopherType,   // DWORD
        byte[] lpszLocator,   // LPSTR optional, out
        IntByReference lpdwBufferLength   // DWORD* in/out
    );
}
@[Link("wininet")]
lib LibWININET
  fun GopherCreateLocatorA = GopherCreateLocatorA(
    lpszHost : UInt8*,   # LPCSTR
    nServerPort : UInt16,   # WORD
    lpszDisplayString : UInt8*,   # LPCSTR optional
    lpszSelectorString : UInt8*,   # LPCSTR optional
    dwGopherType : UInt32,   # DWORD
    lpszLocator : UInt8*,   # LPSTR 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 GopherCreateLocatorANative = Int32 Function(Pointer<Utf8>, Uint16, Pointer<Utf8>, Pointer<Utf8>, Uint32, Pointer<Utf8>, Pointer<Uint32>);
typedef GopherCreateLocatorADart = int Function(Pointer<Utf8>, int, Pointer<Utf8>, Pointer<Utf8>, int, Pointer<Utf8>, Pointer<Uint32>);
final GopherCreateLocatorA = DynamicLibrary.open('WININET.dll')
    .lookupFunction<GopherCreateLocatorANative, GopherCreateLocatorADart>('GopherCreateLocatorA');
// lpszHost : LPCSTR -> Pointer<Utf8>
// nServerPort : WORD -> Uint16
// lpszDisplayString : LPCSTR optional -> Pointer<Utf8>
// lpszSelectorString : LPCSTR optional -> Pointer<Utf8>
// dwGopherType : DWORD -> Uint32
// lpszLocator : LPSTR optional, out -> Pointer<Utf8>
// lpdwBufferLength : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GopherCreateLocatorA(
  lpszHost: PAnsiChar;   // LPCSTR
  nServerPort: Word;   // WORD
  lpszDisplayString: PAnsiChar;   // LPCSTR optional
  lpszSelectorString: PAnsiChar;   // LPCSTR optional
  dwGopherType: DWORD;   // DWORD
  lpszLocator: PAnsiChar;   // LPSTR optional, out
  lpdwBufferLength: Pointer   // DWORD* in/out
): BOOL; stdcall;
  external 'WININET.dll' name 'GopherCreateLocatorA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

let gophercreatelocatora =
  foreign "GopherCreateLocatorA"
    (string @-> uint16_t @-> string @-> string @-> uint32_t @-> string @-> (ptr uint32_t) @-> returning int32_t)
(* lpszHost : LPCSTR -> string *)
(* nServerPort : WORD -> uint16_t *)
(* lpszDisplayString : LPCSTR optional -> string *)
(* lpszSelectorString : LPCSTR optional -> string *)
(* dwGopherType : DWORD -> uint32_t *)
(* lpszLocator : LPSTR optional, out -> string *)
(* 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 ("GopherCreateLocatorA" gopher-create-locator-a :convention :stdcall) :int32
  (lpsz-host :string)   ; LPCSTR
  (n-server-port :uint16)   ; WORD
  (lpsz-display-string :string)   ; LPCSTR optional
  (lpsz-selector-string :string)   ; LPCSTR optional
  (dw-gopher-type :uint32)   ; DWORD
  (lpsz-locator :pointer)   ; LPSTR 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 $GopherCreateLocatorA = Win32::API::More->new('WININET',
    'BOOL GopherCreateLocatorA(LPCSTR lpszHost, WORD nServerPort, LPCSTR lpszDisplayString, LPCSTR lpszSelectorString, DWORD dwGopherType, LPSTR lpszLocator, LPVOID lpdwBufferLength)');
# my $ret = $GopherCreateLocatorA->Call($lpszHost, $nServerPort, $lpszDisplayString, $lpszSelectorString, $dwGopherType, $lpszLocator, $lpdwBufferLength);
# lpszHost : LPCSTR -> LPCSTR
# nServerPort : WORD -> WORD
# lpszDisplayString : LPCSTR optional -> LPCSTR
# lpszSelectorString : LPCSTR optional -> LPCSTR
# dwGopherType : DWORD -> DWORD
# lpszLocator : LPSTR optional, out -> LPSTR
# lpdwBufferLength : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い