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

RetrieveUrlCacheEntryStreamW

関数
URLキャッシュエントリをストリームとして開く(Unicode版)。
DLLWININET.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

HANDLE RetrieveUrlCacheEntryStreamW(
    LPCWSTR lpszUrlName,
    INTERNET_CACHE_ENTRY_INFOW* lpCacheEntryInfo,   // optional
    DWORD* lpcbCacheEntryInfo,
    BOOL fRandomRead,
    DWORD dwReserved   // optional
);

パラメーター

名前方向説明
lpszUrlNameLPCWSTRinキャッシュエントリのソース名を含む null 終端文字列へのポインター。これは一意な名前でなければなりません。名前文字列にエスケープ文字を含めてはいけません。
lpCacheEntryInfoINTERNET_CACHE_ENTRY_INFOW*inoutoptionalキャッシュエントリに関する情報を受け取る INTERNET_CACHE_ENTRY_INFO 構造体へのポインター。
lpcbCacheEntryInfoDWORD*inoutlpCacheEntryInfo バッファーのサイズ(バイト単位)を指定する変数へのポインター。関数が戻るとき、この変数はバッファーにコピーされたバイト数、または必要なバッファーサイズ(バイト単位)を受け取ります。このバッファーサイズは、INTERNET_CACHE_ENTRY_INFO 構造体と、その直後に格納される関連文字列の両方を収められる大きさである必要があります。
fRandomReadBOOLinストリームをランダムアクセス用に開くかどうかを指定します。ストリームをランダムアクセス用に開くには、このフラグを TRUE に設定します。
dwReservedDWORDoptionalこのパラメーターは予約されており、0 でなければなりません。

戻り値の型: HANDLE

公式ドキュメント

キャッシュデータにアクセスするための、最も効率的で実装に依存しない方法を提供します。(Unicode)

戻り値

関数が成功した場合、 ReadUrlCacheEntryStream および UnlockUrlCacheEntryStream 関数で使用する有効なハンドルを返します。

関数が失敗した場合、NULL を返します。拡張エラー情報を取得するには、 GetLastError を呼び出します。

発生し得るエラー値には次のものが含まれます。

戻り値 説明
ERROR_FILE_NOT_FOUND
ソース名で指定されたキャッシュエントリがキャッシュストレージ内に見つかりません。
ERROR_INSUFFICIENT_BUFFER

lpdwCacheEntryInfoBufferSize で指定された lpCacheEntryInfo のサイズが、すべての情報を格納するのに十分ではありません。 lpdwCacheEntryInfoBufferSize に返される値は、すべての情報を格納するために必要なバッファーサイズを示します。

解説(Remarks)

RetrieveUrlCacheEntryStream は URL の解析を一切行わないため、アンカー (#) を含む URL は、たとえそのリソースがキャッシュされていてもキャッシュ内で見つかりません。たとえば、URL http://adatum.com/example.htm#sample を渡した場合、http://adatum.com/example.htm がキャッシュ内にあったとしても、この関数は ERROR_FILE_NOT_FOUND を返します。

URL データをファイル形式で必要としないキャッシュクライアントは、特定の URL のデータにアクセスするためにこの関数を使用してください。

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

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

wininet.h ヘッダーは、RetrieveUrlCacheEntryStream を、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>

HANDLE RetrieveUrlCacheEntryStreamW(
    LPCWSTR lpszUrlName,
    INTERNET_CACHE_ENTRY_INFOW* lpCacheEntryInfo,   // optional
    DWORD* lpcbCacheEntryInfo,
    BOOL fRandomRead,
    DWORD dwReserved   // optional
);
[DllImport("WININET.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern IntPtr RetrieveUrlCacheEntryStreamW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpszUrlName,   // LPCWSTR
    IntPtr lpCacheEntryInfo,   // INTERNET_CACHE_ENTRY_INFOW* optional, in/out
    ref uint lpcbCacheEntryInfo,   // DWORD* in/out
    bool fRandomRead,   // BOOL
    uint dwReserved   // DWORD optional
);
<DllImport("WININET.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function RetrieveUrlCacheEntryStreamW(
    <MarshalAs(UnmanagedType.LPWStr)> lpszUrlName As String,   ' LPCWSTR
    lpCacheEntryInfo As IntPtr,   ' INTERNET_CACHE_ENTRY_INFOW* optional, in/out
    ByRef lpcbCacheEntryInfo As UInteger,   ' DWORD* in/out
    fRandomRead As Boolean,   ' BOOL
    dwReserved As UInteger   ' DWORD optional
) As IntPtr
End Function
' lpszUrlName : LPCWSTR
' lpCacheEntryInfo : INTERNET_CACHE_ENTRY_INFOW* optional, in/out
' lpcbCacheEntryInfo : DWORD* in/out
' fRandomRead : BOOL
' dwReserved : DWORD optional
Declare PtrSafe Function RetrieveUrlCacheEntryStreamW Lib "wininet" ( _
    ByVal lpszUrlName As LongPtr, _
    ByVal lpCacheEntryInfo As LongPtr, _
    ByRef lpcbCacheEntryInfo As Long, _
    ByVal fRandomRead As Long, _
    ByVal dwReserved As Long) 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

RetrieveUrlCacheEntryStreamW = ctypes.windll.wininet.RetrieveUrlCacheEntryStreamW
RetrieveUrlCacheEntryStreamW.restype = ctypes.c_void_p
RetrieveUrlCacheEntryStreamW.argtypes = [
    wintypes.LPCWSTR,  # lpszUrlName : LPCWSTR
    ctypes.c_void_p,  # lpCacheEntryInfo : INTERNET_CACHE_ENTRY_INFOW* optional, in/out
    ctypes.POINTER(wintypes.DWORD),  # lpcbCacheEntryInfo : DWORD* in/out
    wintypes.BOOL,  # fRandomRead : BOOL
    wintypes.DWORD,  # dwReserved : DWORD optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WININET.dll')
RetrieveUrlCacheEntryStreamW = Fiddle::Function.new(
  lib['RetrieveUrlCacheEntryStreamW'],
  [
    Fiddle::TYPE_VOIDP,  # lpszUrlName : LPCWSTR
    Fiddle::TYPE_VOIDP,  # lpCacheEntryInfo : INTERNET_CACHE_ENTRY_INFOW* optional, in/out
    Fiddle::TYPE_VOIDP,  # lpcbCacheEntryInfo : DWORD* in/out
    Fiddle::TYPE_INT,  # fRandomRead : BOOL
    -Fiddle::TYPE_INT,  # dwReserved : DWORD optional
  ],
  Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "wininet")]
extern "system" {
    fn RetrieveUrlCacheEntryStreamW(
        lpszUrlName: *const u16,  // LPCWSTR
        lpCacheEntryInfo: *mut INTERNET_CACHE_ENTRY_INFOW,  // INTERNET_CACHE_ENTRY_INFOW* optional, in/out
        lpcbCacheEntryInfo: *mut u32,  // DWORD* in/out
        fRandomRead: i32,  // BOOL
        dwReserved: u32  // DWORD optional
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("WININET.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr RetrieveUrlCacheEntryStreamW([MarshalAs(UnmanagedType.LPWStr)] string lpszUrlName, IntPtr lpCacheEntryInfo, ref uint lpcbCacheEntryInfo, bool fRandomRead, uint dwReserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WININET_RetrieveUrlCacheEntryStreamW' -Namespace Win32 -PassThru
# $api::RetrieveUrlCacheEntryStreamW(lpszUrlName, lpCacheEntryInfo, lpcbCacheEntryInfo, fRandomRead, dwReserved)
#uselib "WININET.dll"
#func global RetrieveUrlCacheEntryStreamW "RetrieveUrlCacheEntryStreamW" wptr, wptr, wptr, wptr, wptr
; RetrieveUrlCacheEntryStreamW lpszUrlName, varptr(lpCacheEntryInfo), varptr(lpcbCacheEntryInfo), fRandomRead, dwReserved   ; 戻り値は stat
; lpszUrlName : LPCWSTR -> "wptr"
; lpCacheEntryInfo : INTERNET_CACHE_ENTRY_INFOW* optional, in/out -> "wptr"
; lpcbCacheEntryInfo : DWORD* in/out -> "wptr"
; fRandomRead : BOOL -> "wptr"
; dwReserved : DWORD optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WININET.dll"
#cfunc global RetrieveUrlCacheEntryStreamW "RetrieveUrlCacheEntryStreamW" wstr, var, var, int, int
; res = RetrieveUrlCacheEntryStreamW(lpszUrlName, lpCacheEntryInfo, lpcbCacheEntryInfo, fRandomRead, dwReserved)
; lpszUrlName : LPCWSTR -> "wstr"
; lpCacheEntryInfo : INTERNET_CACHE_ENTRY_INFOW* optional, in/out -> "var"
; lpcbCacheEntryInfo : DWORD* in/out -> "var"
; fRandomRead : BOOL -> "int"
; dwReserved : DWORD optional -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HANDLE RetrieveUrlCacheEntryStreamW(LPCWSTR lpszUrlName, INTERNET_CACHE_ENTRY_INFOW* lpCacheEntryInfo, DWORD* lpcbCacheEntryInfo, BOOL fRandomRead, DWORD dwReserved)
#uselib "WININET.dll"
#cfunc global RetrieveUrlCacheEntryStreamW "RetrieveUrlCacheEntryStreamW" wstr, var, var, int, int
; res = RetrieveUrlCacheEntryStreamW(lpszUrlName, lpCacheEntryInfo, lpcbCacheEntryInfo, fRandomRead, dwReserved)
; lpszUrlName : LPCWSTR -> "wstr"
; lpCacheEntryInfo : INTERNET_CACHE_ENTRY_INFOW* optional, in/out -> "var"
; lpcbCacheEntryInfo : DWORD* in/out -> "var"
; fRandomRead : BOOL -> "int"
; dwReserved : DWORD optional -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wininet = windows.NewLazySystemDLL("WININET.dll")
	procRetrieveUrlCacheEntryStreamW = wininet.NewProc("RetrieveUrlCacheEntryStreamW")
)

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

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

typedef RetrieveUrlCacheEntryStreamWNative = Pointer<Void> Function(Pointer<Utf16>, Pointer<Void>, Pointer<Uint32>, Int32, Uint32);
typedef RetrieveUrlCacheEntryStreamWDart = Pointer<Void> Function(Pointer<Utf16>, Pointer<Void>, Pointer<Uint32>, int, int);
final RetrieveUrlCacheEntryStreamW = DynamicLibrary.open('WININET.dll')
    .lookupFunction<RetrieveUrlCacheEntryStreamWNative, RetrieveUrlCacheEntryStreamWDart>('RetrieveUrlCacheEntryStreamW');
// lpszUrlName : LPCWSTR -> Pointer<Utf16>
// lpCacheEntryInfo : INTERNET_CACHE_ENTRY_INFOW* optional, in/out -> Pointer<Void>
// lpcbCacheEntryInfo : DWORD* in/out -> Pointer<Uint32>
// fRandomRead : BOOL -> Int32
// dwReserved : DWORD optional -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function RetrieveUrlCacheEntryStreamW(
  lpszUrlName: PWideChar;   // LPCWSTR
  lpCacheEntryInfo: Pointer;   // INTERNET_CACHE_ENTRY_INFOW* optional, in/out
  lpcbCacheEntryInfo: Pointer;   // DWORD* in/out
  fRandomRead: BOOL;   // BOOL
  dwReserved: DWORD   // DWORD optional
): THandle; stdcall;
  external 'WININET.dll' name 'RetrieveUrlCacheEntryStreamW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "RetrieveUrlCacheEntryStreamW"
  c_RetrieveUrlCacheEntryStreamW :: CWString -> Ptr () -> Ptr Word32 -> CInt -> Word32 -> IO (Ptr ())
-- lpszUrlName : LPCWSTR -> CWString
-- lpCacheEntryInfo : INTERNET_CACHE_ENTRY_INFOW* optional, in/out -> Ptr ()
-- lpcbCacheEntryInfo : DWORD* in/out -> Ptr Word32
-- fRandomRead : BOOL -> CInt
-- dwReserved : DWORD optional -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let retrieveurlcacheentrystreamw =
  foreign "RetrieveUrlCacheEntryStreamW"
    ((ptr uint16_t) @-> (ptr void) @-> (ptr uint32_t) @-> int32_t @-> uint32_t @-> returning (ptr void))
(* lpszUrlName : LPCWSTR -> (ptr uint16_t) *)
(* lpCacheEntryInfo : INTERNET_CACHE_ENTRY_INFOW* optional, in/out -> (ptr void) *)
(* lpcbCacheEntryInfo : DWORD* in/out -> (ptr uint32_t) *)
(* fRandomRead : BOOL -> int32_t *)
(* dwReserved : DWORD optional -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library wininet (t "WININET.dll"))
(cffi:use-foreign-library wininet)

(cffi:defcfun ("RetrieveUrlCacheEntryStreamW" retrieve-url-cache-entry-stream-w :convention :stdcall) :pointer
  (lpsz-url-name (:string :encoding :utf-16le))   ; LPCWSTR
  (lp-cache-entry-info :pointer)   ; INTERNET_CACHE_ENTRY_INFOW* optional, in/out
  (lpcb-cache-entry-info :pointer)   ; DWORD* in/out
  (f-random-read :int32)   ; BOOL
  (dw-reserved :uint32))   ; DWORD optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $RetrieveUrlCacheEntryStreamW = Win32::API::More->new('WININET',
    'HANDLE RetrieveUrlCacheEntryStreamW(LPCWSTR lpszUrlName, LPVOID lpCacheEntryInfo, LPVOID lpcbCacheEntryInfo, BOOL fRandomRead, DWORD dwReserved)');
# my $ret = $RetrieveUrlCacheEntryStreamW->Call($lpszUrlName, $lpCacheEntryInfo, $lpcbCacheEntryInfo, $fRandomRead, $dwReserved);
# lpszUrlName : LPCWSTR -> LPCWSTR
# lpCacheEntryInfo : INTERNET_CACHE_ENTRY_INFOW* optional, in/out -> LPVOID
# lpcbCacheEntryInfo : DWORD* in/out -> LPVOID
# fRandomRead : BOOL -> BOOL
# dwReserved : DWORD optional -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

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