Win32 API 日本語リファレンス
ホームSystem.Com.Urlmon › CoInternetGetSession

CoInternetGetSession

関数
URLモニカーのインターネットセッションオブジェクトを取得する。
DLLurlmon.dll呼出規約winapi

シグネチャ

// urlmon.dll
#include <windows.h>

HRESULT CoInternetGetSession(
    DWORD dwSessionMode,
    IInternetSession** ppIInternetSession,
    DWORD dwReserved
);

パラメーター

名前方向
dwSessionModeDWORDin
ppIInternetSessionIInternetSession**out
dwReservedDWORDin

戻り値の型: HRESULT

各言語での呼び出し定義

// urlmon.dll
#include <windows.h>

HRESULT CoInternetGetSession(
    DWORD dwSessionMode,
    IInternetSession** ppIInternetSession,
    DWORD dwReserved
);
[DllImport("urlmon.dll", ExactSpelling = true)]
static extern int CoInternetGetSession(
    uint dwSessionMode,   // DWORD
    IntPtr ppIInternetSession,   // IInternetSession** out
    uint dwReserved   // DWORD
);
<DllImport("urlmon.dll", ExactSpelling:=True)>
Public Shared Function CoInternetGetSession(
    dwSessionMode As UInteger,   ' DWORD
    ppIInternetSession As IntPtr,   ' IInternetSession** out
    dwReserved As UInteger   ' DWORD
) As Integer
End Function
' dwSessionMode : DWORD
' ppIInternetSession : IInternetSession** out
' dwReserved : DWORD
Declare PtrSafe Function CoInternetGetSession Lib "urlmon" ( _
    ByVal dwSessionMode As Long, _
    ByVal ppIInternetSession As LongPtr, _
    ByVal dwReserved As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CoInternetGetSession = ctypes.windll.urlmon.CoInternetGetSession
CoInternetGetSession.restype = ctypes.c_int
CoInternetGetSession.argtypes = [
    wintypes.DWORD,  # dwSessionMode : DWORD
    ctypes.c_void_p,  # ppIInternetSession : IInternetSession** out
    wintypes.DWORD,  # dwReserved : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('urlmon.dll')
CoInternetGetSession = Fiddle::Function.new(
  lib['CoInternetGetSession'],
  [
    -Fiddle::TYPE_INT,  # dwSessionMode : DWORD
    Fiddle::TYPE_VOIDP,  # ppIInternetSession : IInternetSession** out
    -Fiddle::TYPE_INT,  # dwReserved : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "urlmon")]
extern "system" {
    fn CoInternetGetSession(
        dwSessionMode: u32,  // DWORD
        ppIInternetSession: *mut *mut core::ffi::c_void,  // IInternetSession** out
        dwReserved: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("urlmon.dll")]
public static extern int CoInternetGetSession(uint dwSessionMode, IntPtr ppIInternetSession, uint dwReserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'urlmon_CoInternetGetSession' -Namespace Win32 -PassThru
# $api::CoInternetGetSession(dwSessionMode, ppIInternetSession, dwReserved)
#uselib "urlmon.dll"
#func global CoInternetGetSession "CoInternetGetSession" sptr, sptr, sptr
; CoInternetGetSession dwSessionMode, ppIInternetSession, dwReserved   ; 戻り値は stat
; dwSessionMode : DWORD -> "sptr"
; ppIInternetSession : IInternetSession** out -> "sptr"
; dwReserved : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "urlmon.dll"
#cfunc global CoInternetGetSession "CoInternetGetSession" int, sptr, int
; res = CoInternetGetSession(dwSessionMode, ppIInternetSession, dwReserved)
; dwSessionMode : DWORD -> "int"
; ppIInternetSession : IInternetSession** out -> "sptr"
; dwReserved : DWORD -> "int"
; HRESULT CoInternetGetSession(DWORD dwSessionMode, IInternetSession** ppIInternetSession, DWORD dwReserved)
#uselib "urlmon.dll"
#cfunc global CoInternetGetSession "CoInternetGetSession" int, intptr, int
; res = CoInternetGetSession(dwSessionMode, ppIInternetSession, dwReserved)
; dwSessionMode : DWORD -> "int"
; ppIInternetSession : IInternetSession** out -> "intptr"
; dwReserved : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	urlmon = windows.NewLazySystemDLL("urlmon.dll")
	procCoInternetGetSession = urlmon.NewProc("CoInternetGetSession")
)

// dwSessionMode (DWORD), ppIInternetSession (IInternetSession** out), dwReserved (DWORD)
r1, _, err := procCoInternetGetSession.Call(
	uintptr(dwSessionMode),
	uintptr(ppIInternetSession),
	uintptr(dwReserved),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function CoInternetGetSession(
  dwSessionMode: DWORD;   // DWORD
  ppIInternetSession: Pointer;   // IInternetSession** out
  dwReserved: DWORD   // DWORD
): Integer; stdcall;
  external 'urlmon.dll' name 'CoInternetGetSession';
result := DllCall("urlmon\CoInternetGetSession"
    , "UInt", dwSessionMode   ; DWORD
    , "Ptr", ppIInternetSession   ; IInternetSession** out
    , "UInt", dwReserved   ; DWORD
    , "Int")   ; return: HRESULT
●CoInternetGetSession(dwSessionMode, ppIInternetSession, dwReserved) = DLL("urlmon.dll", "int CoInternetGetSession(dword, void*, dword)")
# 呼び出し: CoInternetGetSession(dwSessionMode, ppIInternetSession, dwReserved)
# dwSessionMode : DWORD -> "dword"
# ppIInternetSession : IInternetSession** out -> "void*"
# dwReserved : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。