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

CoSetProxyBlanket

関数
プロキシの認証情報や偽装レベルなどを設定する。
DLLOLE32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HRESULT CoSetProxyBlanket(
    IUnknown* pProxy,
    DWORD dwAuthnSvc,
    DWORD dwAuthzSvc,
    LPWSTR pServerPrincName,   // optional
    RPC_C_AUTHN_LEVEL dwAuthnLevel,
    RPC_C_IMP_LEVEL dwImpLevel,
    void* pAuthInfo,   // optional
    DWORD dwCapabilities
);

パラメーター

名前方向説明
pProxyIUnknown*in設定対象のプロキシ。
dwAuthnSvcDWORDin使用する認証サービス。指定可能な値の一覧については、Authentication Service Constants を参照してください。認証が不要な場合は RPC_C_AUTHN_NONE を使用します。RPC_C_AUTHN_DEFAULT を指定した場合、DCOM は通常のセキュリティブランケットのネゴシエーションアルゴリズムに従って認証サービスを選択します。
dwAuthzSvcDWORDin使用する承認サービス。指定可能な値の一覧については、Authorization Constants を参照してください。RPC_C_AUTHZ_DEFAULT を指定した場合、DCOM は通常のセキュリティブランケットのネゴシエーションアルゴリズムに従って承認サービスを選択します。認証サービスとして NTLMSSP、Kerberos、または Schannel を使用する場合は、承認サービスとして RPC_C_AUTHZ_NONE を使用してください。
pServerPrincNameLPWSTRinoptional

認証サービスで使用するサーバープリンシパル名。COLE_DEFAULT_PRINCIPAL を指定した場合、DCOM はセキュリティブランケットのネゴシエーションアルゴリズムを使用してプリンシパル名を選択します。認証サービスとして Kerberos を使用する場合、この値を NULL にすることはできません。サーバーの正しいプリンシパル名を指定する必要があり、そうしないと呼び出しは失敗します。

認証サービスとして Schannel を使用する場合、この値は Principal Names で説明されている msstd 形式または fullsic 形式のいずれかであるか、相互認証が不要な場合は NULL でなければなりません。

一般に、NULL を指定してもプロキシのサーバープリンシパル名はリセットされず、以前の設定が保持されます。プロキシに対して異なる認証サービスを選択する際に NULLpServerPrincName として使用する場合は注意が必要です。以前に設定したプリンシパル名が、新しく選択した認証サービスで有効である保証はないためです。

dwAuthnLevelRPC_C_AUTHN_LEVELin使用する認証レベル。指定可能な値の一覧については、Authentication Level Constants を参照してください。RPC_C_AUTHN_LEVEL_DEFAULT を指定した場合、DCOM は通常のセキュリティブランケットのネゴシエーションアルゴリズムに従って認証レベルを選択します。この値が none の場合、認証サービスも none でなければなりません。
dwImpLevelRPC_C_IMP_LEVELin使用する偽装レベル。指定可能な値の一覧については、Impersonation Level Constants を参照してください。RPC_C_IMP_LEVEL_DEFAULT を指定した場合、DCOM は通常のセキュリティブランケットのネゴシエーションアルゴリズムに従って偽装レベルを選択します。認証サービスが NTLMSSP の場合、この値は RPC_C_IMP_LEVEL_IMPERSONATE または RPC_C_IMP_LEVEL_IDENTIFY でなければなりません。NTLMSSP は同一コンピューター上での委任レベルの偽装(RPC_C_IMP_LEVEL_DELEGATE)もサポートします。認証サービスが Schannel の場合、このパラメーターは RPC_C_IMP_LEVEL_IMPERSONATE でなければなりません。
pAuthInfovoid*inoptional

クライアントの ID を確立する RPC_AUTH_IDENTITY_HANDLE 値へのポインター。ハンドルが参照する構造体の形式は、認証サービスのプロバイダーによって異なります。

同一コンピューター上での呼び出しの場合、RPC は指定された資格情報でユーザーをログオンし、その結果得られたトークンをメソッド呼び出しに使用します。

NTLMSSP または Kerberos の場合、構造体は SEC_WINNT_AUTH_IDENTITY 構造体または SEC_WINNT_AUTH_IDENTITY_EX 構造体です。クライアントは API の呼び出し後に pAuthInfo を破棄できます。RPC は pAuthInfo ポインターのコピーを保持しないため、クライアントは後で CoQueryProxyBlanket メソッドでそれを取得することはできません。

このパラメーターが NULL の場合、DCOM は現在のプロキシ ID(プロセストークンまたは偽装トークンのいずれか)を使用します。ハンドルが構造体を参照している場合は、その ID が使用されます。

Schannel の場合、このパラメーターはクライアントの X.509 証明書を含む CERT_CONTEXT 構造体へのポインターであるか、クライアントがサーバーへの匿名接続を行いたい場合は NULL でなければなりません。証明書を指定した場合、現在のアパートメント内にそのオブジェクトへのプロキシが存在する限り、呼び出し元はそれを解放してはなりません。

Snego の場合、このメンバーは NULL であるか、SEC_WINNT_AUTH_IDENTITY 構造体を指すか、SEC_WINNT_AUTH_IDENTITY_EX 構造体を指します。NULL の場合、Snego はクライアントコンピューターで利用可能な認証サービスに基づいてリストを選択します。SEC_WINNT_AUTH_IDENTITY_EX 構造体を指す場合、構造体の PackageList メンバーは認証サービス名のコンマ区切りリストを含む文字列を指す必要があり、PackageListLength メンバーは PackageList 文字列のバイト数を指定する必要があります。PackageListNULL の場合、Snego を使用するすべての呼び出しは失敗します。

このパラメーターに COLE_DEFAULT_AUTHINFO を指定した場合、DCOM は通常のセキュリティブランケットのネゴシエーションアルゴリズムに従って認証情報を選択します。

pAuthInfo が設定されており、かつ dwCapabilities パラメーターでクローキングフラグのいずれかが設定されている場合、CoSetProxyBlanket は失敗します。

dwCapabilitiesDWORDinこのプロキシの機能。指定可能な値の一覧については、EOLE_AUTHENTICATION_CAPABILITIES 列挙型を参照してください。この関数で設定できるフラグは、EOAC_MUTUAL_AUTHEOAC_STATIC_CLOAKINGEOAC_DYNAMIC_CLOAKINGEOAC_ANY_AUTHORITY(このフラグは非推奨です)、EOAC_MAKE_FULLSIC、および EOAC_DEFAULT のみです。pAuthInfo が設定されておらず、かつ認証サービスが Schannel でない場合は、EOAC_STATIC_CLOAKING または EOAC_DYNAMIC_CLOAKING のいずれかを設定できます。(詳細については Cloaking を参照してください。)ここで挙げたもの以外の機能フラグが設定されている場合、CoSetProxyBlanket は失敗します。

戻り値の型: HRESULT

公式ドキュメント

指定したプロキシで呼び出しを行う際に使用される認証情報を設定します。

戻り値

この関数は次の値を返すことがあります。

戻り値 説明
S_OK
関数は成功しました。
E_INVALIDARG
1 つ以上の引数が無効です。

解説(Remarks)

CoSetProxyBlanket は、指定したプロキシで呼び出しを行う際に使用される認証情報を設定します。この関数は、次の一般的な呼び出しのシーケンス(エラー処理を除く)をカプセル化します。

    pProxy->QueryInterface(IID_IClientSecurity, (void**)&pcs);
    pcs->SetBlanket(pProxy, dwAuthnSvc, dwAuthzSvc, pServerPrincName, 
        dwAuthnLevel, dwImpLevel, pAuthInfo, dwCapabilities);
    pcs->Release();

このシーケンスは、プロキシに対して QueryInterface を呼び出して IClientSecurity へのポインターを取得し、得られたポインターを使用して IClientSecurity::SetBlanket を呼び出した後、ポインターを解放します。

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

各言語での呼び出し定義

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

HRESULT CoSetProxyBlanket(
    IUnknown* pProxy,
    DWORD dwAuthnSvc,
    DWORD dwAuthzSvc,
    LPWSTR pServerPrincName,   // optional
    RPC_C_AUTHN_LEVEL dwAuthnLevel,
    RPC_C_IMP_LEVEL dwImpLevel,
    void* pAuthInfo,   // optional
    DWORD dwCapabilities
);
[DllImport("OLE32.dll", ExactSpelling = true)]
static extern int CoSetProxyBlanket(
    IntPtr pProxy,   // IUnknown*
    uint dwAuthnSvc,   // DWORD
    uint dwAuthzSvc,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string pServerPrincName,   // LPWSTR optional
    uint dwAuthnLevel,   // RPC_C_AUTHN_LEVEL
    uint dwImpLevel,   // RPC_C_IMP_LEVEL
    IntPtr pAuthInfo,   // void* optional
    uint dwCapabilities   // DWORD
);
<DllImport("OLE32.dll", ExactSpelling:=True)>
Public Shared Function CoSetProxyBlanket(
    pProxy As IntPtr,   ' IUnknown*
    dwAuthnSvc As UInteger,   ' DWORD
    dwAuthzSvc As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> pServerPrincName As String,   ' LPWSTR optional
    dwAuthnLevel As UInteger,   ' RPC_C_AUTHN_LEVEL
    dwImpLevel As UInteger,   ' RPC_C_IMP_LEVEL
    pAuthInfo As IntPtr,   ' void* optional
    dwCapabilities As UInteger   ' DWORD
) As Integer
End Function
' pProxy : IUnknown*
' dwAuthnSvc : DWORD
' dwAuthzSvc : DWORD
' pServerPrincName : LPWSTR optional
' dwAuthnLevel : RPC_C_AUTHN_LEVEL
' dwImpLevel : RPC_C_IMP_LEVEL
' pAuthInfo : void* optional
' dwCapabilities : DWORD
Declare PtrSafe Function CoSetProxyBlanket Lib "ole32" ( _
    ByVal pProxy As LongPtr, _
    ByVal dwAuthnSvc As Long, _
    ByVal dwAuthzSvc As Long, _
    ByVal pServerPrincName As LongPtr, _
    ByVal dwAuthnLevel As Long, _
    ByVal dwImpLevel As Long, _
    ByVal pAuthInfo As LongPtr, _
    ByVal dwCapabilities As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CoSetProxyBlanket = ctypes.windll.ole32.CoSetProxyBlanket
CoSetProxyBlanket.restype = ctypes.c_int
CoSetProxyBlanket.argtypes = [
    ctypes.c_void_p,  # pProxy : IUnknown*
    wintypes.DWORD,  # dwAuthnSvc : DWORD
    wintypes.DWORD,  # dwAuthzSvc : DWORD
    wintypes.LPCWSTR,  # pServerPrincName : LPWSTR optional
    wintypes.DWORD,  # dwAuthnLevel : RPC_C_AUTHN_LEVEL
    wintypes.DWORD,  # dwImpLevel : RPC_C_IMP_LEVEL
    ctypes.POINTER(None),  # pAuthInfo : void* optional
    wintypes.DWORD,  # dwCapabilities : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('OLE32.dll')
CoSetProxyBlanket = Fiddle::Function.new(
  lib['CoSetProxyBlanket'],
  [
    Fiddle::TYPE_VOIDP,  # pProxy : IUnknown*
    -Fiddle::TYPE_INT,  # dwAuthnSvc : DWORD
    -Fiddle::TYPE_INT,  # dwAuthzSvc : DWORD
    Fiddle::TYPE_VOIDP,  # pServerPrincName : LPWSTR optional
    -Fiddle::TYPE_INT,  # dwAuthnLevel : RPC_C_AUTHN_LEVEL
    -Fiddle::TYPE_INT,  # dwImpLevel : RPC_C_IMP_LEVEL
    Fiddle::TYPE_VOIDP,  # pAuthInfo : void* optional
    -Fiddle::TYPE_INT,  # dwCapabilities : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "ole32")]
extern "system" {
    fn CoSetProxyBlanket(
        pProxy: *mut core::ffi::c_void,  // IUnknown*
        dwAuthnSvc: u32,  // DWORD
        dwAuthzSvc: u32,  // DWORD
        pServerPrincName: *mut u16,  // LPWSTR optional
        dwAuthnLevel: u32,  // RPC_C_AUTHN_LEVEL
        dwImpLevel: u32,  // RPC_C_IMP_LEVEL
        pAuthInfo: *mut (),  // void* optional
        dwCapabilities: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("OLE32.dll")]
public static extern int CoSetProxyBlanket(IntPtr pProxy, uint dwAuthnSvc, uint dwAuthzSvc, [MarshalAs(UnmanagedType.LPWStr)] string pServerPrincName, uint dwAuthnLevel, uint dwImpLevel, IntPtr pAuthInfo, uint dwCapabilities);
"@
$api = Add-Type -MemberDefinition $sig -Name 'OLE32_CoSetProxyBlanket' -Namespace Win32 -PassThru
# $api::CoSetProxyBlanket(pProxy, dwAuthnSvc, dwAuthzSvc, pServerPrincName, dwAuthnLevel, dwImpLevel, pAuthInfo, dwCapabilities)
#uselib "OLE32.dll"
#func global CoSetProxyBlanket "CoSetProxyBlanket" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; CoSetProxyBlanket pProxy, dwAuthnSvc, dwAuthzSvc, pServerPrincName, dwAuthnLevel, dwImpLevel, pAuthInfo, dwCapabilities   ; 戻り値は stat
; pProxy : IUnknown* -> "sptr"
; dwAuthnSvc : DWORD -> "sptr"
; dwAuthzSvc : DWORD -> "sptr"
; pServerPrincName : LPWSTR optional -> "sptr"
; dwAuthnLevel : RPC_C_AUTHN_LEVEL -> "sptr"
; dwImpLevel : RPC_C_IMP_LEVEL -> "sptr"
; pAuthInfo : void* optional -> "sptr"
; dwCapabilities : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "OLE32.dll"
#cfunc global CoSetProxyBlanket "CoSetProxyBlanket" sptr, int, int, wstr, int, int, sptr, int
; res = CoSetProxyBlanket(pProxy, dwAuthnSvc, dwAuthzSvc, pServerPrincName, dwAuthnLevel, dwImpLevel, pAuthInfo, dwCapabilities)
; pProxy : IUnknown* -> "sptr"
; dwAuthnSvc : DWORD -> "int"
; dwAuthzSvc : DWORD -> "int"
; pServerPrincName : LPWSTR optional -> "wstr"
; dwAuthnLevel : RPC_C_AUTHN_LEVEL -> "int"
; dwImpLevel : RPC_C_IMP_LEVEL -> "int"
; pAuthInfo : void* optional -> "sptr"
; dwCapabilities : DWORD -> "int"
; HRESULT CoSetProxyBlanket(IUnknown* pProxy, DWORD dwAuthnSvc, DWORD dwAuthzSvc, LPWSTR pServerPrincName, RPC_C_AUTHN_LEVEL dwAuthnLevel, RPC_C_IMP_LEVEL dwImpLevel, void* pAuthInfo, DWORD dwCapabilities)
#uselib "OLE32.dll"
#cfunc global CoSetProxyBlanket "CoSetProxyBlanket" intptr, int, int, wstr, int, int, intptr, int
; res = CoSetProxyBlanket(pProxy, dwAuthnSvc, dwAuthzSvc, pServerPrincName, dwAuthnLevel, dwImpLevel, pAuthInfo, dwCapabilities)
; pProxy : IUnknown* -> "intptr"
; dwAuthnSvc : DWORD -> "int"
; dwAuthzSvc : DWORD -> "int"
; pServerPrincName : LPWSTR optional -> "wstr"
; dwAuthnLevel : RPC_C_AUTHN_LEVEL -> "int"
; dwImpLevel : RPC_C_IMP_LEVEL -> "int"
; pAuthInfo : void* optional -> "intptr"
; dwCapabilities : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ole32 = windows.NewLazySystemDLL("OLE32.dll")
	procCoSetProxyBlanket = ole32.NewProc("CoSetProxyBlanket")
)

// pProxy (IUnknown*), dwAuthnSvc (DWORD), dwAuthzSvc (DWORD), pServerPrincName (LPWSTR optional), dwAuthnLevel (RPC_C_AUTHN_LEVEL), dwImpLevel (RPC_C_IMP_LEVEL), pAuthInfo (void* optional), dwCapabilities (DWORD)
r1, _, err := procCoSetProxyBlanket.Call(
	uintptr(pProxy),
	uintptr(dwAuthnSvc),
	uintptr(dwAuthzSvc),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pServerPrincName))),
	uintptr(dwAuthnLevel),
	uintptr(dwImpLevel),
	uintptr(pAuthInfo),
	uintptr(dwCapabilities),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function CoSetProxyBlanket(
  pProxy: Pointer;   // IUnknown*
  dwAuthnSvc: DWORD;   // DWORD
  dwAuthzSvc: DWORD;   // DWORD
  pServerPrincName: PWideChar;   // LPWSTR optional
  dwAuthnLevel: DWORD;   // RPC_C_AUTHN_LEVEL
  dwImpLevel: DWORD;   // RPC_C_IMP_LEVEL
  pAuthInfo: Pointer;   // void* optional
  dwCapabilities: DWORD   // DWORD
): Integer; stdcall;
  external 'OLE32.dll' name 'CoSetProxyBlanket';
result := DllCall("OLE32\CoSetProxyBlanket"
    , "Ptr", pProxy   ; IUnknown*
    , "UInt", dwAuthnSvc   ; DWORD
    , "UInt", dwAuthzSvc   ; DWORD
    , "WStr", pServerPrincName   ; LPWSTR optional
    , "UInt", dwAuthnLevel   ; RPC_C_AUTHN_LEVEL
    , "UInt", dwImpLevel   ; RPC_C_IMP_LEVEL
    , "Ptr", pAuthInfo   ; void* optional
    , "UInt", dwCapabilities   ; DWORD
    , "Int")   ; return: HRESULT
●CoSetProxyBlanket(pProxy, dwAuthnSvc, dwAuthzSvc, pServerPrincName, dwAuthnLevel, dwImpLevel, pAuthInfo, dwCapabilities) = DLL("OLE32.dll", "int CoSetProxyBlanket(void*, dword, dword, char*, dword, dword, void*, dword)")
# 呼び出し: CoSetProxyBlanket(pProxy, dwAuthnSvc, dwAuthzSvc, pServerPrincName, dwAuthnLevel, dwImpLevel, pAuthInfo, dwCapabilities)
# pProxy : IUnknown* -> "void*"
# dwAuthnSvc : DWORD -> "dword"
# dwAuthzSvc : DWORD -> "dword"
# pServerPrincName : LPWSTR optional -> "char*"
# dwAuthnLevel : RPC_C_AUTHN_LEVEL -> "dword"
# dwImpLevel : RPC_C_IMP_LEVEL -> "dword"
# pAuthInfo : void* optional -> "void*"
# dwCapabilities : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "ole32" fn CoSetProxyBlanket(
    pProxy: ?*anyopaque, // IUnknown*
    dwAuthnSvc: u32, // DWORD
    dwAuthzSvc: u32, // DWORD
    pServerPrincName: [*c]const u16, // LPWSTR optional
    dwAuthnLevel: u32, // RPC_C_AUTHN_LEVEL
    dwImpLevel: u32, // RPC_C_IMP_LEVEL
    pAuthInfo: ?*anyopaque, // void* optional
    dwCapabilities: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
proc CoSetProxyBlanket(
    pProxy: pointer,  # IUnknown*
    dwAuthnSvc: uint32,  # DWORD
    dwAuthzSvc: uint32,  # DWORD
    pServerPrincName: WideCString,  # LPWSTR optional
    dwAuthnLevel: uint32,  # RPC_C_AUTHN_LEVEL
    dwImpLevel: uint32,  # RPC_C_IMP_LEVEL
    pAuthInfo: pointer,  # void* optional
    dwCapabilities: uint32  # DWORD
): int32 {.importc: "CoSetProxyBlanket", stdcall, dynlib: "OLE32.dll".}
pragma(lib, "ole32");
extern(Windows)
int CoSetProxyBlanket(
    void* pProxy,   // IUnknown*
    uint dwAuthnSvc,   // DWORD
    uint dwAuthzSvc,   // DWORD
    const(wchar)* pServerPrincName,   // LPWSTR optional
    uint dwAuthnLevel,   // RPC_C_AUTHN_LEVEL
    uint dwImpLevel,   // RPC_C_IMP_LEVEL
    void* pAuthInfo,   // void* optional
    uint dwCapabilities   // DWORD
);
ccall((:CoSetProxyBlanket, "OLE32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, UInt32, UInt32, Cwstring, UInt32, UInt32, Ptr{Cvoid}, UInt32),
      pProxy, dwAuthnSvc, dwAuthzSvc, pServerPrincName, dwAuthnLevel, dwImpLevel, pAuthInfo, dwCapabilities)
# pProxy : IUnknown* -> Ptr{Cvoid}
# dwAuthnSvc : DWORD -> UInt32
# dwAuthzSvc : DWORD -> UInt32
# pServerPrincName : LPWSTR optional -> Cwstring
# dwAuthnLevel : RPC_C_AUTHN_LEVEL -> UInt32
# dwImpLevel : RPC_C_IMP_LEVEL -> UInt32
# pAuthInfo : void* optional -> Ptr{Cvoid}
# dwCapabilities : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t CoSetProxyBlanket(
    void* pProxy,
    uint32_t dwAuthnSvc,
    uint32_t dwAuthzSvc,
    const uint16_t* pServerPrincName,
    uint32_t dwAuthnLevel,
    uint32_t dwImpLevel,
    void* pAuthInfo,
    uint32_t dwCapabilities);
]]
local ole32 = ffi.load("ole32")
-- ole32.CoSetProxyBlanket(pProxy, dwAuthnSvc, dwAuthzSvc, pServerPrincName, dwAuthnLevel, dwImpLevel, pAuthInfo, dwCapabilities)
-- pProxy : IUnknown*
-- dwAuthnSvc : DWORD
-- dwAuthzSvc : DWORD
-- pServerPrincName : LPWSTR optional
-- dwAuthnLevel : RPC_C_AUTHN_LEVEL
-- dwImpLevel : RPC_C_IMP_LEVEL
-- pAuthInfo : void* optional
-- dwCapabilities : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('OLE32.dll');
const CoSetProxyBlanket = lib.func('__stdcall', 'CoSetProxyBlanket', 'int32_t', ['void *', 'uint32_t', 'uint32_t', 'str16', 'uint32_t', 'uint32_t', 'void *', 'uint32_t']);
// CoSetProxyBlanket(pProxy, dwAuthnSvc, dwAuthzSvc, pServerPrincName, dwAuthnLevel, dwImpLevel, pAuthInfo, dwCapabilities)
// pProxy : IUnknown* -> 'void *'
// dwAuthnSvc : DWORD -> 'uint32_t'
// dwAuthzSvc : DWORD -> 'uint32_t'
// pServerPrincName : LPWSTR optional -> 'str16'
// dwAuthnLevel : RPC_C_AUTHN_LEVEL -> 'uint32_t'
// dwImpLevel : RPC_C_IMP_LEVEL -> 'uint32_t'
// pAuthInfo : void* optional -> 'void *'
// dwCapabilities : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("OLE32.dll", {
  CoSetProxyBlanket: { parameters: ["pointer", "u32", "u32", "buffer", "u32", "u32", "pointer", "u32"], result: "i32" },
});
// lib.symbols.CoSetProxyBlanket(pProxy, dwAuthnSvc, dwAuthzSvc, pServerPrincName, dwAuthnLevel, dwImpLevel, pAuthInfo, dwCapabilities)
// pProxy : IUnknown* -> "pointer"
// dwAuthnSvc : DWORD -> "u32"
// dwAuthzSvc : DWORD -> "u32"
// pServerPrincName : LPWSTR optional -> "buffer"
// dwAuthnLevel : RPC_C_AUTHN_LEVEL -> "u32"
// dwImpLevel : RPC_C_IMP_LEVEL -> "u32"
// pAuthInfo : void* optional -> "pointer"
// dwCapabilities : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t CoSetProxyBlanket(
    void* pProxy,
    uint32_t dwAuthnSvc,
    uint32_t dwAuthzSvc,
    const uint16_t* pServerPrincName,
    uint32_t dwAuthnLevel,
    uint32_t dwImpLevel,
    void* pAuthInfo,
    uint32_t dwCapabilities);
C, "OLE32.dll");
// $ffi->CoSetProxyBlanket(pProxy, dwAuthnSvc, dwAuthzSvc, pServerPrincName, dwAuthnLevel, dwImpLevel, pAuthInfo, dwCapabilities);
// pProxy : IUnknown*
// dwAuthnSvc : DWORD
// dwAuthzSvc : DWORD
// pServerPrincName : LPWSTR optional
// dwAuthnLevel : RPC_C_AUTHN_LEVEL
// dwImpLevel : RPC_C_IMP_LEVEL
// pAuthInfo : void* optional
// dwCapabilities : DWORD
// 構造体/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 Ole32 extends StdCallLibrary {
    Ole32 INSTANCE = Native.load("ole32", Ole32.class);
    int CoSetProxyBlanket(
        Pointer pProxy,   // IUnknown*
        int dwAuthnSvc,   // DWORD
        int dwAuthzSvc,   // DWORD
        WString pServerPrincName,   // LPWSTR optional
        int dwAuthnLevel,   // RPC_C_AUTHN_LEVEL
        int dwImpLevel,   // RPC_C_IMP_LEVEL
        Pointer pAuthInfo,   // void* optional
        int dwCapabilities   // DWORD
    );
}
@[Link("ole32")]
lib LibOLE32
  fun CoSetProxyBlanket = CoSetProxyBlanket(
    pProxy : Void*,   # IUnknown*
    dwAuthnSvc : UInt32,   # DWORD
    dwAuthzSvc : UInt32,   # DWORD
    pServerPrincName : UInt16*,   # LPWSTR optional
    dwAuthnLevel : UInt32,   # RPC_C_AUTHN_LEVEL
    dwImpLevel : UInt32,   # RPC_C_IMP_LEVEL
    pAuthInfo : Void*,   # void* optional
    dwCapabilities : UInt32   # DWORD
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef CoSetProxyBlanketNative = Int32 Function(Pointer<Void>, Uint32, Uint32, Pointer<Utf16>, Uint32, Uint32, Pointer<Void>, Uint32);
typedef CoSetProxyBlanketDart = int Function(Pointer<Void>, int, int, Pointer<Utf16>, int, int, Pointer<Void>, int);
final CoSetProxyBlanket = DynamicLibrary.open('OLE32.dll')
    .lookupFunction<CoSetProxyBlanketNative, CoSetProxyBlanketDart>('CoSetProxyBlanket');
// pProxy : IUnknown* -> Pointer<Void>
// dwAuthnSvc : DWORD -> Uint32
// dwAuthzSvc : DWORD -> Uint32
// pServerPrincName : LPWSTR optional -> Pointer<Utf16>
// dwAuthnLevel : RPC_C_AUTHN_LEVEL -> Uint32
// dwImpLevel : RPC_C_IMP_LEVEL -> Uint32
// pAuthInfo : void* optional -> Pointer<Void>
// dwCapabilities : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CoSetProxyBlanket(
  pProxy: Pointer;   // IUnknown*
  dwAuthnSvc: DWORD;   // DWORD
  dwAuthzSvc: DWORD;   // DWORD
  pServerPrincName: PWideChar;   // LPWSTR optional
  dwAuthnLevel: DWORD;   // RPC_C_AUTHN_LEVEL
  dwImpLevel: DWORD;   // RPC_C_IMP_LEVEL
  pAuthInfo: Pointer;   // void* optional
  dwCapabilities: DWORD   // DWORD
): Integer; stdcall;
  external 'OLE32.dll' name 'CoSetProxyBlanket';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CoSetProxyBlanket"
  c_CoSetProxyBlanket :: Ptr () -> Word32 -> Word32 -> CWString -> Word32 -> Word32 -> Ptr () -> Word32 -> IO Int32
-- pProxy : IUnknown* -> Ptr ()
-- dwAuthnSvc : DWORD -> Word32
-- dwAuthzSvc : DWORD -> Word32
-- pServerPrincName : LPWSTR optional -> CWString
-- dwAuthnLevel : RPC_C_AUTHN_LEVEL -> Word32
-- dwImpLevel : RPC_C_IMP_LEVEL -> Word32
-- pAuthInfo : void* optional -> Ptr ()
-- dwCapabilities : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let cosetproxyblanket =
  foreign "CoSetProxyBlanket"
    ((ptr void) @-> uint32_t @-> uint32_t @-> (ptr uint16_t) @-> uint32_t @-> uint32_t @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* pProxy : IUnknown* -> (ptr void) *)
(* dwAuthnSvc : DWORD -> uint32_t *)
(* dwAuthzSvc : DWORD -> uint32_t *)
(* pServerPrincName : LPWSTR optional -> (ptr uint16_t) *)
(* dwAuthnLevel : RPC_C_AUTHN_LEVEL -> uint32_t *)
(* dwImpLevel : RPC_C_IMP_LEVEL -> uint32_t *)
(* pAuthInfo : void* optional -> (ptr void) *)
(* dwCapabilities : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library ole32 (t "OLE32.dll"))
(cffi:use-foreign-library ole32)

(cffi:defcfun ("CoSetProxyBlanket" co-set-proxy-blanket :convention :stdcall) :int32
  (p-proxy :pointer)   ; IUnknown*
  (dw-authn-svc :uint32)   ; DWORD
  (dw-authz-svc :uint32)   ; DWORD
  (p-server-princ-name (:string :encoding :utf-16le))   ; LPWSTR optional
  (dw-authn-level :uint32)   ; RPC_C_AUTHN_LEVEL
  (dw-imp-level :uint32)   ; RPC_C_IMP_LEVEL
  (p-auth-info :pointer)   ; void* optional
  (dw-capabilities :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CoSetProxyBlanket = Win32::API::More->new('OLE32',
    'int CoSetProxyBlanket(LPVOID pProxy, DWORD dwAuthnSvc, DWORD dwAuthzSvc, LPCWSTR pServerPrincName, DWORD dwAuthnLevel, DWORD dwImpLevel, LPVOID pAuthInfo, DWORD dwCapabilities)');
# my $ret = $CoSetProxyBlanket->Call($pProxy, $dwAuthnSvc, $dwAuthzSvc, $pServerPrincName, $dwAuthnLevel, $dwImpLevel, $pAuthInfo, $dwCapabilities);
# pProxy : IUnknown* -> LPVOID
# dwAuthnSvc : DWORD -> DWORD
# dwAuthzSvc : DWORD -> DWORD
# pServerPrincName : LPWSTR optional -> LPCWSTR
# dwAuthnLevel : RPC_C_AUTHN_LEVEL -> DWORD
# dwImpLevel : RPC_C_IMP_LEVEL -> DWORD
# pAuthInfo : void* optional -> LPVOID
# dwCapabilities : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目
使用する型