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

InternetGetCookieW

関数
指定URLに関連付けられたCookieを取得する(Unicode版)。
DLLWININET.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL InternetGetCookieW(
    LPCWSTR lpszUrl,
    LPCWSTR lpszCookieName,   // optional
    LPWSTR lpszCookieData,   // optional
    DWORD* lpdwSize
);

パラメーター

名前方向
lpszUrlLPCWSTRin
lpszCookieNameLPCWSTRinoptional
lpszCookieDataLPWSTRoutoptional
lpdwSizeDWORD*inout

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL InternetGetCookieW(
    LPCWSTR lpszUrl,
    LPCWSTR lpszCookieName,   // optional
    LPWSTR lpszCookieData,   // optional
    DWORD* lpdwSize
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WININET.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool InternetGetCookieW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpszUrl,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string lpszCookieName,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpszCookieData,   // LPWSTR optional, out
    ref uint lpdwSize   // DWORD* in/out
);
<DllImport("WININET.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function InternetGetCookieW(
    <MarshalAs(UnmanagedType.LPWStr)> lpszUrl As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> lpszCookieName As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> lpszCookieData As System.Text.StringBuilder,   ' LPWSTR optional, out
    ByRef lpdwSize As UInteger   ' DWORD* in/out
) As Boolean
End Function
' lpszUrl : LPCWSTR
' lpszCookieName : LPCWSTR optional
' lpszCookieData : LPWSTR optional, out
' lpdwSize : DWORD* in/out
Declare PtrSafe Function InternetGetCookieW Lib "wininet" ( _
    ByVal lpszUrl As LongPtr, _
    ByVal lpszCookieName As LongPtr, _
    ByVal lpszCookieData As LongPtr, _
    ByRef lpdwSize 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

InternetGetCookieW = ctypes.windll.wininet.InternetGetCookieW
InternetGetCookieW.restype = wintypes.BOOL
InternetGetCookieW.argtypes = [
    wintypes.LPCWSTR,  # lpszUrl : LPCWSTR
    wintypes.LPCWSTR,  # lpszCookieName : LPCWSTR optional
    wintypes.LPWSTR,  # lpszCookieData : LPWSTR optional, out
    ctypes.POINTER(wintypes.DWORD),  # lpdwSize : DWORD* in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	wininet = windows.NewLazySystemDLL("WININET.dll")
	procInternetGetCookieW = wininet.NewProc("InternetGetCookieW")
)

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