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

WinHttpRegisterProxyChangeNotification

関数
プロキシ設定変更の通知を登録する。
DLLWINHTTP.dll呼出規約winapi

シグネチャ

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

DWORD WinHttpRegisterProxyChangeNotification(
    ULONGLONG ullFlags,
    WINHTTP_PROXY_CHANGE_CALLBACK pfnCallback,
    void* pvContext,
    void** hRegistration
);

パラメーター

名前方向説明
ullFlagsULONGLONGinコールバックに渡すフラグ(例: WINHTTP_PROXY_NOTIFY_CHANGE)。
pfnCallbackWINHTTP_PROXY_CHANGE_CALLBACKin実効プロキシ設定が変更されたときに呼び出されるコールバック関数へのポインター。
pvContextvoid*inコールバックに渡すコンテキストオブジェクトへのポインター。
hRegistrationvoid**outコールバック関数の登録を識別するハンドル。登録を解除するには、この値を WinHttpUnregisterProxyChangeNotification に渡します。WINHTTP_PROXY_CHANGE_REGISTRATION_HANDLEPVOID と同等です。

戻り値の型: DWORD

公式ドキュメント

実効プロキシ設定が変更されたときに WinHTTP が呼び出すコールバック関数を登録します。

戻り値

操作の結果を示すステータスコードを格納する DWORD。次のコードが返される可能性があります(網羅的なリストではありません)。

コード 説明
ERROR_SUCCESS 操作が成功しました。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

DWORD WinHttpRegisterProxyChangeNotification(
    ULONGLONG ullFlags,
    WINHTTP_PROXY_CHANGE_CALLBACK pfnCallback,
    void* pvContext,
    void** hRegistration
);
[DllImport("WINHTTP.dll", ExactSpelling = true)]
static extern uint WinHttpRegisterProxyChangeNotification(
    ulong ullFlags,   // ULONGLONG
    IntPtr pfnCallback,   // WINHTTP_PROXY_CHANGE_CALLBACK
    IntPtr pvContext,   // void*
    IntPtr hRegistration   // void** out
);
<DllImport("WINHTTP.dll", ExactSpelling:=True)>
Public Shared Function WinHttpRegisterProxyChangeNotification(
    ullFlags As ULong,   ' ULONGLONG
    pfnCallback As IntPtr,   ' WINHTTP_PROXY_CHANGE_CALLBACK
    pvContext As IntPtr,   ' void*
    hRegistration As IntPtr   ' void** out
) As UInteger
End Function
' ullFlags : ULONGLONG
' pfnCallback : WINHTTP_PROXY_CHANGE_CALLBACK
' pvContext : void*
' hRegistration : void** out
Declare PtrSafe Function WinHttpRegisterProxyChangeNotification Lib "winhttp" ( _
    ByVal ullFlags As LongLong, _
    ByVal pfnCallback As LongPtr, _
    ByVal pvContext As LongPtr, _
    ByVal hRegistration As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WinHttpRegisterProxyChangeNotification = ctypes.windll.winhttp.WinHttpRegisterProxyChangeNotification
WinHttpRegisterProxyChangeNotification.restype = wintypes.DWORD
WinHttpRegisterProxyChangeNotification.argtypes = [
    ctypes.c_ulonglong,  # ullFlags : ULONGLONG
    ctypes.c_void_p,  # pfnCallback : WINHTTP_PROXY_CHANGE_CALLBACK
    ctypes.POINTER(None),  # pvContext : void*
    ctypes.c_void_p,  # hRegistration : void** out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WINHTTP.dll')
WinHttpRegisterProxyChangeNotification = Fiddle::Function.new(
  lib['WinHttpRegisterProxyChangeNotification'],
  [
    -Fiddle::TYPE_LONG_LONG,  # ullFlags : ULONGLONG
    Fiddle::TYPE_VOIDP,  # pfnCallback : WINHTTP_PROXY_CHANGE_CALLBACK
    Fiddle::TYPE_VOIDP,  # pvContext : void*
    Fiddle::TYPE_VOIDP,  # hRegistration : void** out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "winhttp")]
extern "system" {
    fn WinHttpRegisterProxyChangeNotification(
        ullFlags: u64,  // ULONGLONG
        pfnCallback: *const core::ffi::c_void,  // WINHTTP_PROXY_CHANGE_CALLBACK
        pvContext: *mut (),  // void*
        hRegistration: *mut *mut ()  // void** out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("WINHTTP.dll")]
public static extern uint WinHttpRegisterProxyChangeNotification(ulong ullFlags, IntPtr pfnCallback, IntPtr pvContext, IntPtr hRegistration);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WINHTTP_WinHttpRegisterProxyChangeNotification' -Namespace Win32 -PassThru
# $api::WinHttpRegisterProxyChangeNotification(ullFlags, pfnCallback, pvContext, hRegistration)
#uselib "WINHTTP.dll"
#func global WinHttpRegisterProxyChangeNotification "WinHttpRegisterProxyChangeNotification" sptr, sptr, sptr, sptr
; WinHttpRegisterProxyChangeNotification ullFlags, pfnCallback, pvContext, hRegistration   ; 戻り値は stat
; ullFlags : ULONGLONG -> "sptr"
; pfnCallback : WINHTTP_PROXY_CHANGE_CALLBACK -> "sptr"
; pvContext : void* -> "sptr"
; hRegistration : void** out -> "sptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "WINHTTP.dll"
#cfunc global WinHttpRegisterProxyChangeNotification "WinHttpRegisterProxyChangeNotification" int64, sptr, sptr, sptr
; res = WinHttpRegisterProxyChangeNotification(ullFlags, pfnCallback, pvContext, hRegistration)
; ullFlags : ULONGLONG -> "int64"
; pfnCallback : WINHTTP_PROXY_CHANGE_CALLBACK -> "sptr"
; pvContext : void* -> "sptr"
; hRegistration : void** out -> "sptr"
; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。
; DWORD WinHttpRegisterProxyChangeNotification(ULONGLONG ullFlags, WINHTTP_PROXY_CHANGE_CALLBACK pfnCallback, void* pvContext, void** hRegistration)
#uselib "WINHTTP.dll"
#cfunc global WinHttpRegisterProxyChangeNotification "WinHttpRegisterProxyChangeNotification" int64, intptr, intptr, intptr
; res = WinHttpRegisterProxyChangeNotification(ullFlags, pfnCallback, pvContext, hRegistration)
; ullFlags : ULONGLONG -> "int64"
; pfnCallback : WINHTTP_PROXY_CHANGE_CALLBACK -> "intptr"
; pvContext : void* -> "intptr"
; hRegistration : void** out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	winhttp = windows.NewLazySystemDLL("WINHTTP.dll")
	procWinHttpRegisterProxyChangeNotification = winhttp.NewProc("WinHttpRegisterProxyChangeNotification")
)

// ullFlags (ULONGLONG), pfnCallback (WINHTTP_PROXY_CHANGE_CALLBACK), pvContext (void*), hRegistration (void** out)
r1, _, err := procWinHttpRegisterProxyChangeNotification.Call(
	uintptr(ullFlags),
	uintptr(pfnCallback),
	uintptr(pvContext),
	uintptr(hRegistration),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function WinHttpRegisterProxyChangeNotification(
  ullFlags: UInt64;   // ULONGLONG
  pfnCallback: Pointer;   // WINHTTP_PROXY_CHANGE_CALLBACK
  pvContext: Pointer;   // void*
  hRegistration: Pointer   // void** out
): DWORD; stdcall;
  external 'WINHTTP.dll' name 'WinHttpRegisterProxyChangeNotification';
result := DllCall("WINHTTP\WinHttpRegisterProxyChangeNotification"
    , "Int64", ullFlags   ; ULONGLONG
    , "Ptr", pfnCallback   ; WINHTTP_PROXY_CHANGE_CALLBACK
    , "Ptr", pvContext   ; void*
    , "Ptr", hRegistration   ; void** out
    , "UInt")   ; return: DWORD
●WinHttpRegisterProxyChangeNotification(ullFlags, pfnCallback, pvContext, hRegistration) = DLL("WINHTTP.dll", "dword WinHttpRegisterProxyChangeNotification(qword, void*, void*, void*)")
# 呼び出し: WinHttpRegisterProxyChangeNotification(ullFlags, pfnCallback, pvContext, hRegistration)
# ullFlags : ULONGLONG -> "qword"
# pfnCallback : WINHTTP_PROXY_CHANGE_CALLBACK -> "void*"
# pvContext : void* -> "void*"
# hRegistration : void** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "winhttp" fn WinHttpRegisterProxyChangeNotification(
    ullFlags: u64, // ULONGLONG
    pfnCallback: ?*anyopaque, // WINHTTP_PROXY_CHANGE_CALLBACK
    pvContext: ?*anyopaque, // void*
    hRegistration: ?*anyopaque // void** out
) callconv(std.os.windows.WINAPI) u32;
proc WinHttpRegisterProxyChangeNotification(
    ullFlags: uint64,  # ULONGLONG
    pfnCallback: pointer,  # WINHTTP_PROXY_CHANGE_CALLBACK
    pvContext: pointer,  # void*
    hRegistration: pointer  # void** out
): uint32 {.importc: "WinHttpRegisterProxyChangeNotification", stdcall, dynlib: "WINHTTP.dll".}
pragma(lib, "winhttp");
extern(Windows)
uint WinHttpRegisterProxyChangeNotification(
    ulong ullFlags,   // ULONGLONG
    void* pfnCallback,   // WINHTTP_PROXY_CHANGE_CALLBACK
    void* pvContext,   // void*
    void** hRegistration   // void** out
);
ccall((:WinHttpRegisterProxyChangeNotification, "WINHTTP.dll"), stdcall, UInt32,
      (UInt64, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}),
      ullFlags, pfnCallback, pvContext, hRegistration)
# ullFlags : ULONGLONG -> UInt64
# pfnCallback : WINHTTP_PROXY_CHANGE_CALLBACK -> Ptr{Cvoid}
# pvContext : void* -> Ptr{Cvoid}
# hRegistration : void** out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t WinHttpRegisterProxyChangeNotification(
    uint64_t ullFlags,
    void* pfnCallback,
    void* pvContext,
    void** hRegistration);
]]
local winhttp = ffi.load("winhttp")
-- winhttp.WinHttpRegisterProxyChangeNotification(ullFlags, pfnCallback, pvContext, hRegistration)
-- ullFlags : ULONGLONG
-- pfnCallback : WINHTTP_PROXY_CHANGE_CALLBACK
-- pvContext : void*
-- hRegistration : void** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('WINHTTP.dll');
const WinHttpRegisterProxyChangeNotification = lib.func('__stdcall', 'WinHttpRegisterProxyChangeNotification', 'uint32_t', ['uint64_t', 'void *', 'void *', 'void *']);
// WinHttpRegisterProxyChangeNotification(ullFlags, pfnCallback, pvContext, hRegistration)
// ullFlags : ULONGLONG -> 'uint64_t'
// pfnCallback : WINHTTP_PROXY_CHANGE_CALLBACK -> 'void *'
// pvContext : void* -> 'void *'
// hRegistration : void** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。
const lib = Deno.dlopen("WINHTTP.dll", {
  WinHttpRegisterProxyChangeNotification: { parameters: ["u64", "pointer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.WinHttpRegisterProxyChangeNotification(ullFlags, pfnCallback, pvContext, hRegistration)
// ullFlags : ULONGLONG -> "u64"
// pfnCallback : WINHTTP_PROXY_CHANGE_CALLBACK -> "pointer"
// pvContext : void* -> "pointer"
// hRegistration : void** out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t WinHttpRegisterProxyChangeNotification(
    uint64_t ullFlags,
    void* pfnCallback,
    void* pvContext,
    void** hRegistration);
C, "WINHTTP.dll");
// $ffi->WinHttpRegisterProxyChangeNotification(ullFlags, pfnCallback, pvContext, hRegistration);
// ullFlags : ULONGLONG
// pfnCallback : WINHTTP_PROXY_CHANGE_CALLBACK
// pvContext : void*
// hRegistration : void** 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 Winhttp extends StdCallLibrary {
    Winhttp INSTANCE = Native.load("winhttp", Winhttp.class);
    int WinHttpRegisterProxyChangeNotification(
        long ullFlags,   // ULONGLONG
        Callback pfnCallback,   // WINHTTP_PROXY_CHANGE_CALLBACK
        Pointer pvContext,   // void*
        Pointer hRegistration   // void** out
    );
}
@[Link("winhttp")]
lib LibWINHTTP
  fun WinHttpRegisterProxyChangeNotification = WinHttpRegisterProxyChangeNotification(
    ullFlags : UInt64,   # ULONGLONG
    pfnCallback : Void*,   # WINHTTP_PROXY_CHANGE_CALLBACK
    pvContext : Void*,   # void*
    hRegistration : Void**   # void** out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef WinHttpRegisterProxyChangeNotificationNative = Uint32 Function(Uint64, Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef WinHttpRegisterProxyChangeNotificationDart = int Function(int, Pointer<Void>, Pointer<Void>, Pointer<Void>);
final WinHttpRegisterProxyChangeNotification = DynamicLibrary.open('WINHTTP.dll')
    .lookupFunction<WinHttpRegisterProxyChangeNotificationNative, WinHttpRegisterProxyChangeNotificationDart>('WinHttpRegisterProxyChangeNotification');
// ullFlags : ULONGLONG -> Uint64
// pfnCallback : WINHTTP_PROXY_CHANGE_CALLBACK -> Pointer<Void>
// pvContext : void* -> Pointer<Void>
// hRegistration : void** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function WinHttpRegisterProxyChangeNotification(
  ullFlags: UInt64;   // ULONGLONG
  pfnCallback: Pointer;   // WINHTTP_PROXY_CHANGE_CALLBACK
  pvContext: Pointer;   // void*
  hRegistration: Pointer   // void** out
): DWORD; stdcall;
  external 'WINHTTP.dll' name 'WinHttpRegisterProxyChangeNotification';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "WinHttpRegisterProxyChangeNotification"
  c_WinHttpRegisterProxyChangeNotification :: Word64 -> Ptr () -> Ptr () -> Ptr () -> IO Word32
-- ullFlags : ULONGLONG -> Word64
-- pfnCallback : WINHTTP_PROXY_CHANGE_CALLBACK -> Ptr ()
-- pvContext : void* -> Ptr ()
-- hRegistration : void** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let winhttpregisterproxychangenotification =
  foreign "WinHttpRegisterProxyChangeNotification"
    (uint64_t @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> returning uint32_t)
(* ullFlags : ULONGLONG -> uint64_t *)
(* pfnCallback : WINHTTP_PROXY_CHANGE_CALLBACK -> (ptr void) *)
(* pvContext : void* -> (ptr void) *)
(* hRegistration : void** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library winhttp (t "WINHTTP.dll"))
(cffi:use-foreign-library winhttp)

(cffi:defcfun ("WinHttpRegisterProxyChangeNotification" win-http-register-proxy-change-notification :convention :stdcall) :uint32
  (ull-flags :uint64)   ; ULONGLONG
  (pfn-callback :pointer)   ; WINHTTP_PROXY_CHANGE_CALLBACK
  (pv-context :pointer)   ; void*
  (h-registration :pointer))   ; void** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $WinHttpRegisterProxyChangeNotification = Win32::API::More->new('WINHTTP',
    'DWORD WinHttpRegisterProxyChangeNotification(UINT64 ullFlags, LPVOID pfnCallback, LPVOID pvContext, LPVOID hRegistration)');
# my $ret = $WinHttpRegisterProxyChangeNotification->Call($ullFlags, $pfnCallback, $pvContext, $hRegistration);
# ullFlags : ULONGLONG -> UINT64
# pfnCallback : WINHTTP_PROXY_CHANGE_CALLBACK -> LPVOID
# pvContext : void* -> LPVOID
# hRegistration : void** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。

関連項目

使用する型