PrivacySetZonePreferenceW
関数シグネチャ
// WININET.dll
#include <windows.h>
DWORD PrivacySetZonePreferenceW(
DWORD dwZone,
DWORD dwType,
DWORD dwTemplate,
LPCWSTR pszPreference // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| dwZone | DWORD | in | プライバシー設定を行う対象の URLZONE を指定する DWORD 型の値です。 |
| dwType | DWORD | in | プライバシー設定を行う対象の PrivacyType を指定する DWORD 型の値です。 |
| dwTemplate | DWORD | in | プライバシー設定に使用するプライバシー テンプレートを指定する DWORD 型の値です。 |
| pszPreference | LPCWSTR | inoptional | dwTemplate が PRIVACY_TEMPLATE_CUSTOM に設定されている場合、このパラメーターはカスタム設定の文字列表現です。それ以外の場合は NULL に設定する必要があります。この文字列表現の説明は「解説」セクションに記載されています。 |
戻り値の型: DWORD
公式ドキュメント
PrivacySetZonePreferenceW (Unicode) 関数 (wininet.h) は、指定された URLZONE および PrivacyType に対するプライバシー設定を行います。
戻り値
成功した場合は 0 を返します。それ以外の場合は、winerr.h で定義されているエラーのいずれかを返します。
解説(Remarks)
インターネット ゾーンに対するこれらのプライバシー設定は、インターネット オプションダイアログ ボックスのプライバシータブにあります。
URLZONE_INTERNET のプライバシー オプションを設定するには、両方の PrivacyType に対してプライバシー テンプレートを設定する必要があります。インターネット オプションのプライバシーメニューにあるスライダーは、両方の PrivacyType に対してプライバシーが設定された場合にのみ移動します。
指定した URLZONE と PrivacyType に対するカスタム プライバシー設定は、pszPreference パラメーターを通じて設定できます。pszPreference パラメーターには、プライバシー設定を記述する一連のルールを空白で区切って含めることができます。ルール自体には空白を含めることができない点に注意してください。pszPreference は次の構造を持ち、複数の論理ルールを含めることができます。<signature> <logical-rule> <special-rule>。
現在、signature は IE6-P3PSettings/V1: に設定する必要があります。
論理ルールは次の形式を持ちます。/<expression>=<decision>/。
expression は、演算子 & (論理 AND) および ! (論理 NOT) を使用してコンパクト ポリシー トークンを組み合わせたブール式です。コンパクト ポリシー トークンは大文字と小文字を区別します。(Platform for Privacy Preferences (P3P) プライバシー ポリシーおよびコンパクト ポリシー トークンの詳細については、W3C: Platform for Privacy Preferences (P3P) Project の仕様を参照してください。) decision は、指定したトークンを含むコンパクト ポリシーを持つ Cookie に対して実行するアクションを定義する 1 文字の小文字です。次の表に、有効な decision 文字を示します。
| 文字 | 定義 |
|---|---|
| a | Cookie を受け入れます。 |
| p | Cookie を受け入れるか拒否するかをユーザーに確認します。 |
| r | Cookie を拒否します。 |
| l | Cookie をリーシュします (ファースト パーティのコンテキストでのみ送信します)。 |
| d | Cookie が永続的な Cookie である場合、それをセッション Cookie にダウングレードします。 |
論理ルールは記載された順序で評価されます。最初に一致した論理ルール (存在する場合) が Cookie のアクションを決定します。
空の expression も許可されます。expression が空の場合、左辺は true と評価されます。この形式の論理ルールは、他のカテゴリに該当しなかったすべての状況をとらえるために、ルール セットの末尾で使用できます。
次の例は有効な論理ルールを示しています。
/DEM=d/
Deny a cookie whose compact policy contains the DEM token
/CON&!TEL=a/
Accept a cookie whose compact policy contains the CON token
and does not contain the TEL token
/=a/
Accept all cookies
特殊ルールは、nopolicy、session、always のシンボルを使用して指定します。nopolicy シンボルは、コンパクト ポリシーが存在しない場合に実行するアクションを指定するために使用します。たとえば nopolicy=d は、コンパクト ポリシーを持たないすべての Cookie をセッション Cookie にダウングレードすることを指定します。session シンボルは、セッション Cookie に対して実行するアクションを指定するために使用し、a にのみ設定できます。session=a が指定されると、コンパクト ポリシーの内容に関係なく、すべてのセッション Cookie が受け入れられます。このルールが指定されない場合、セッション Cookie は永続的な Cookie と同じルールの対象となります。最後に、always シンボルは、すべてに対して同じアクションを実行することを指定するために使用します。たとえば always=d は、コンパクト ポリシーの有無に関係なくすべての Cookie を拒否することを指定します。always=d は /=d/ と同等である点に注意してください。
次の例は、コンパクト ポリシーに FIN/CONi トークン ペアを含む Cookie を受け入れ、FIN/CON、FIN/CONo、FIN/CONa、GOV/PUB トークン ペアまたは TEL トークンを含むコンパクト ポリシーを持つ Cookie を拒否し、Cookie のコンパクト ポリシーに UNR トークンが含まれる場合にユーザーに確認することを指定するプライバシー設定文字列を示しています。さらに、コンパクト ポリシーを持たない Cookie をセッション Cookie にダウングレードし、指定されたルールのいずれにも一致しないすべての Cookie を受け入れることを指定しています。最初に true と評価されたルールが Cookie のアクションを決定する点に注意してください。
IE6-P3PSettings/V1: /FIN&CONi=a/ /FIN&CONo=r/ /FIN&CONa=r/ /FIN&CON=r/
/GOV&PUB=r/ /TEL=r/ /UNR=p/ nopolicy=d /=a/
WinINet API の他のすべての側面と同様に、この関数は DllMain やグローバル オブジェクトのコンストラクター/デストラクター内から安全に呼び出すことはできません。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// WININET.dll
#include <windows.h>
DWORD PrivacySetZonePreferenceW(
DWORD dwZone,
DWORD dwType,
DWORD dwTemplate,
LPCWSTR pszPreference // optional
);[DllImport("WININET.dll", ExactSpelling = true)]
static extern uint PrivacySetZonePreferenceW(
uint dwZone, // DWORD
uint dwType, // DWORD
uint dwTemplate, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] string pszPreference // LPCWSTR optional
);<DllImport("WININET.dll", ExactSpelling:=True)>
Public Shared Function PrivacySetZonePreferenceW(
dwZone As UInteger, ' DWORD
dwType As UInteger, ' DWORD
dwTemplate As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> pszPreference As String ' LPCWSTR optional
) As UInteger
End Function' dwZone : DWORD
' dwType : DWORD
' dwTemplate : DWORD
' pszPreference : LPCWSTR optional
Declare PtrSafe Function PrivacySetZonePreferenceW Lib "wininet" ( _
ByVal dwZone As Long, _
ByVal dwType As Long, _
ByVal dwTemplate As Long, _
ByVal pszPreference As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
PrivacySetZonePreferenceW = ctypes.windll.wininet.PrivacySetZonePreferenceW
PrivacySetZonePreferenceW.restype = wintypes.DWORD
PrivacySetZonePreferenceW.argtypes = [
wintypes.DWORD, # dwZone : DWORD
wintypes.DWORD, # dwType : DWORD
wintypes.DWORD, # dwTemplate : DWORD
wintypes.LPCWSTR, # pszPreference : LPCWSTR optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WININET.dll')
PrivacySetZonePreferenceW = Fiddle::Function.new(
lib['PrivacySetZonePreferenceW'],
[
-Fiddle::TYPE_INT, # dwZone : DWORD
-Fiddle::TYPE_INT, # dwType : DWORD
-Fiddle::TYPE_INT, # dwTemplate : DWORD
Fiddle::TYPE_VOIDP, # pszPreference : LPCWSTR optional
],
-Fiddle::TYPE_INT)#[link(name = "wininet")]
extern "system" {
fn PrivacySetZonePreferenceW(
dwZone: u32, // DWORD
dwType: u32, // DWORD
dwTemplate: u32, // DWORD
pszPreference: *const u16 // LPCWSTR optional
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("WININET.dll")]
public static extern uint PrivacySetZonePreferenceW(uint dwZone, uint dwType, uint dwTemplate, [MarshalAs(UnmanagedType.LPWStr)] string pszPreference);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WININET_PrivacySetZonePreferenceW' -Namespace Win32 -PassThru
# $api::PrivacySetZonePreferenceW(dwZone, dwType, dwTemplate, pszPreference)#uselib "WININET.dll"
#func global PrivacySetZonePreferenceW "PrivacySetZonePreferenceW" sptr, sptr, sptr, sptr
; PrivacySetZonePreferenceW dwZone, dwType, dwTemplate, pszPreference ; 戻り値は stat
; dwZone : DWORD -> "sptr"
; dwType : DWORD -> "sptr"
; dwTemplate : DWORD -> "sptr"
; pszPreference : LPCWSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WININET.dll"
#cfunc global PrivacySetZonePreferenceW "PrivacySetZonePreferenceW" int, int, int, wstr
; res = PrivacySetZonePreferenceW(dwZone, dwType, dwTemplate, pszPreference)
; dwZone : DWORD -> "int"
; dwType : DWORD -> "int"
; dwTemplate : DWORD -> "int"
; pszPreference : LPCWSTR optional -> "wstr"; DWORD PrivacySetZonePreferenceW(DWORD dwZone, DWORD dwType, DWORD dwTemplate, LPCWSTR pszPreference)
#uselib "WININET.dll"
#cfunc global PrivacySetZonePreferenceW "PrivacySetZonePreferenceW" int, int, int, wstr
; res = PrivacySetZonePreferenceW(dwZone, dwType, dwTemplate, pszPreference)
; dwZone : DWORD -> "int"
; dwType : DWORD -> "int"
; dwTemplate : DWORD -> "int"
; pszPreference : LPCWSTR optional -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wininet = windows.NewLazySystemDLL("WININET.dll")
procPrivacySetZonePreferenceW = wininet.NewProc("PrivacySetZonePreferenceW")
)
// dwZone (DWORD), dwType (DWORD), dwTemplate (DWORD), pszPreference (LPCWSTR optional)
r1, _, err := procPrivacySetZonePreferenceW.Call(
uintptr(dwZone),
uintptr(dwType),
uintptr(dwTemplate),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszPreference))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction PrivacySetZonePreferenceW(
dwZone: DWORD; // DWORD
dwType: DWORD; // DWORD
dwTemplate: DWORD; // DWORD
pszPreference: PWideChar // LPCWSTR optional
): DWORD; stdcall;
external 'WININET.dll' name 'PrivacySetZonePreferenceW';result := DllCall("WININET\PrivacySetZonePreferenceW"
, "UInt", dwZone ; DWORD
, "UInt", dwType ; DWORD
, "UInt", dwTemplate ; DWORD
, "WStr", pszPreference ; LPCWSTR optional
, "UInt") ; return: DWORD●PrivacySetZonePreferenceW(dwZone, dwType, dwTemplate, pszPreference) = DLL("WININET.dll", "dword PrivacySetZonePreferenceW(dword, dword, dword, char*)")
# 呼び出し: PrivacySetZonePreferenceW(dwZone, dwType, dwTemplate, pszPreference)
# dwZone : DWORD -> "dword"
# dwType : DWORD -> "dword"
# dwTemplate : DWORD -> "dword"
# pszPreference : LPCWSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "wininet" fn PrivacySetZonePreferenceW(
dwZone: u32, // DWORD
dwType: u32, // DWORD
dwTemplate: u32, // DWORD
pszPreference: [*c]const u16 // LPCWSTR optional
) callconv(std.os.windows.WINAPI) u32;proc PrivacySetZonePreferenceW(
dwZone: uint32, # DWORD
dwType: uint32, # DWORD
dwTemplate: uint32, # DWORD
pszPreference: WideCString # LPCWSTR optional
): uint32 {.importc: "PrivacySetZonePreferenceW", stdcall, dynlib: "WININET.dll".}pragma(lib, "wininet");
extern(Windows)
uint PrivacySetZonePreferenceW(
uint dwZone, // DWORD
uint dwType, // DWORD
uint dwTemplate, // DWORD
const(wchar)* pszPreference // LPCWSTR optional
);ccall((:PrivacySetZonePreferenceW, "WININET.dll"), stdcall, UInt32,
(UInt32, UInt32, UInt32, Cwstring),
dwZone, dwType, dwTemplate, pszPreference)
# dwZone : DWORD -> UInt32
# dwType : DWORD -> UInt32
# dwTemplate : DWORD -> UInt32
# pszPreference : LPCWSTR optional -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t PrivacySetZonePreferenceW(
uint32_t dwZone,
uint32_t dwType,
uint32_t dwTemplate,
const uint16_t* pszPreference);
]]
local wininet = ffi.load("wininet")
-- wininet.PrivacySetZonePreferenceW(dwZone, dwType, dwTemplate, pszPreference)
-- dwZone : DWORD
-- dwType : DWORD
-- dwTemplate : DWORD
-- pszPreference : LPCWSTR optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('WININET.dll');
const PrivacySetZonePreferenceW = lib.func('__stdcall', 'PrivacySetZonePreferenceW', 'uint32_t', ['uint32_t', 'uint32_t', 'uint32_t', 'str16']);
// PrivacySetZonePreferenceW(dwZone, dwType, dwTemplate, pszPreference)
// dwZone : DWORD -> 'uint32_t'
// dwType : DWORD -> 'uint32_t'
// dwTemplate : DWORD -> 'uint32_t'
// pszPreference : LPCWSTR optional -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WININET.dll", {
PrivacySetZonePreferenceW: { parameters: ["u32", "u32", "u32", "buffer"], result: "u32" },
});
// lib.symbols.PrivacySetZonePreferenceW(dwZone, dwType, dwTemplate, pszPreference)
// dwZone : DWORD -> "u32"
// dwType : DWORD -> "u32"
// dwTemplate : DWORD -> "u32"
// pszPreference : LPCWSTR optional -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t PrivacySetZonePreferenceW(
uint32_t dwZone,
uint32_t dwType,
uint32_t dwTemplate,
const uint16_t* pszPreference);
C, "WININET.dll");
// $ffi->PrivacySetZonePreferenceW(dwZone, dwType, dwTemplate, pszPreference);
// dwZone : DWORD
// dwType : DWORD
// dwTemplate : DWORD
// pszPreference : LPCWSTR 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);
int PrivacySetZonePreferenceW(
int dwZone, // DWORD
int dwType, // DWORD
int dwTemplate, // DWORD
WString pszPreference // LPCWSTR optional
);
}@[Link("wininet")]
lib LibWININET
fun PrivacySetZonePreferenceW = PrivacySetZonePreferenceW(
dwZone : UInt32, # DWORD
dwType : UInt32, # DWORD
dwTemplate : UInt32, # DWORD
pszPreference : UInt16* # LPCWSTR optional
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef PrivacySetZonePreferenceWNative = Uint32 Function(Uint32, Uint32, Uint32, Pointer<Utf16>);
typedef PrivacySetZonePreferenceWDart = int Function(int, int, int, Pointer<Utf16>);
final PrivacySetZonePreferenceW = DynamicLibrary.open('WININET.dll')
.lookupFunction<PrivacySetZonePreferenceWNative, PrivacySetZonePreferenceWDart>('PrivacySetZonePreferenceW');
// dwZone : DWORD -> Uint32
// dwType : DWORD -> Uint32
// dwTemplate : DWORD -> Uint32
// pszPreference : LPCWSTR optional -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function PrivacySetZonePreferenceW(
dwZone: DWORD; // DWORD
dwType: DWORD; // DWORD
dwTemplate: DWORD; // DWORD
pszPreference: PWideChar // LPCWSTR optional
): DWORD; stdcall;
external 'WININET.dll' name 'PrivacySetZonePreferenceW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PrivacySetZonePreferenceW"
c_PrivacySetZonePreferenceW :: Word32 -> Word32 -> Word32 -> CWString -> IO Word32
-- dwZone : DWORD -> Word32
-- dwType : DWORD -> Word32
-- dwTemplate : DWORD -> Word32
-- pszPreference : LPCWSTR optional -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let privacysetzonepreferencew =
foreign "PrivacySetZonePreferenceW"
(uint32_t @-> uint32_t @-> uint32_t @-> (ptr uint16_t) @-> returning uint32_t)
(* dwZone : DWORD -> uint32_t *)
(* dwType : DWORD -> uint32_t *)
(* dwTemplate : DWORD -> uint32_t *)
(* pszPreference : LPCWSTR optional -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library wininet (t "WININET.dll"))
(cffi:use-foreign-library wininet)
(cffi:defcfun ("PrivacySetZonePreferenceW" privacy-set-zone-preference-w :convention :stdcall) :uint32
(dw-zone :uint32) ; DWORD
(dw-type :uint32) ; DWORD
(dw-template :uint32) ; DWORD
(psz-preference (:string :encoding :utf-16le))) ; LPCWSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $PrivacySetZonePreferenceW = Win32::API::More->new('WININET',
'DWORD PrivacySetZonePreferenceW(DWORD dwZone, DWORD dwType, DWORD dwTemplate, LPCWSTR pszPreference)');
# my $ret = $PrivacySetZonePreferenceW->Call($dwZone, $dwType, $dwTemplate, $pszPreference);
# dwZone : DWORD -> DWORD
# dwType : DWORD -> DWORD
# dwTemplate : DWORD -> DWORD
# pszPreference : LPCWSTR optional -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f InternetClearAllPerSiteCookieDecisions — 全サイトのCookie許可設定をクリアする。
- f InternetEnumPerSiteCookieDecisionW — サイト別Cookie許可設定を順に列挙する(Unicode版)。
- f InternetGetPerSiteCookieDecisionW — サイト別のCookie許可設定を取得する(Unicode版)。
- f InternetSetPerSiteCookieDecisionW — サイト別のCookie許可設定を行う(Unicode版)。
- f PrivacyGetZonePreferenceW — セキュリティゾーンのプライバシー設定を取得する(Unicode版)。