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

MQGetSecurityContextEx

関数
証明書から拡張セキュリティコンテキストを取得する。
DLLmqrt.dll呼出規約winapi

シグネチャ

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

HRESULT MQGetSecurityContextEx(
    void* lpCertBuffer,   // optional
    DWORD dwCertBufferLength,
    HANDLE* phSecurityContext
);

パラメーター

名前方向説明
lpCertBuffervoid*inoptionalセキュリティコンテキスト生成に使う証明書データのバッファへのポインタ。NULL可で内部証明書を使用する。
dwCertBufferLengthDWORDinlpCertBufferのバイト数を指定する。
phSecurityContextHANDLE*out生成されたセキュリティコンテキストハンドルを受け取るポインタを指定する。

戻り値の型: HRESULT

各言語での呼び出し定義

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

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

MQGetSecurityContextEx = ctypes.windll.mqrt.MQGetSecurityContextEx
MQGetSecurityContextEx.restype = ctypes.c_int
MQGetSecurityContextEx.argtypes = [
    ctypes.POINTER(None),  # lpCertBuffer : void* optional
    wintypes.DWORD,  # dwCertBufferLength : DWORD
    ctypes.c_void_p,  # phSecurityContext : HANDLE* out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	mqrt = windows.NewLazySystemDLL("mqrt.dll")
	procMQGetSecurityContextEx = mqrt.NewProc("MQGetSecurityContextEx")
)

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

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

typedef MQGetSecurityContextExNative = Int32 Function(Pointer<Void>, Uint32, Pointer<Void>);
typedef MQGetSecurityContextExDart = int Function(Pointer<Void>, int, Pointer<Void>);
final MQGetSecurityContextEx = DynamicLibrary.open('mqrt.dll')
    .lookupFunction<MQGetSecurityContextExNative, MQGetSecurityContextExDart>('MQGetSecurityContextEx');
// lpCertBuffer : void* optional -> Pointer<Void>
// dwCertBufferLength : DWORD -> Uint32
// phSecurityContext : HANDLE* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function MQGetSecurityContextEx(
  lpCertBuffer: Pointer;   // void* optional
  dwCertBufferLength: DWORD;   // DWORD
  phSecurityContext: Pointer   // HANDLE* out
): Integer; stdcall;
  external 'mqrt.dll' name 'MQGetSecurityContextEx';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "MQGetSecurityContextEx"
  c_MQGetSecurityContextEx :: Ptr () -> Word32 -> Ptr () -> IO Int32
-- lpCertBuffer : void* optional -> Ptr ()
-- dwCertBufferLength : DWORD -> Word32
-- phSecurityContext : HANDLE* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let mqgetsecuritycontextex =
  foreign "MQGetSecurityContextEx"
    ((ptr void) @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* lpCertBuffer : void* optional -> (ptr void) *)
(* dwCertBufferLength : DWORD -> uint32_t *)
(* phSecurityContext : HANDLE* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library mqrt (t "mqrt.dll"))
(cffi:use-foreign-library mqrt)

(cffi:defcfun ("MQGetSecurityContextEx" mqget-security-context-ex :convention :stdcall) :int32
  (lp-cert-buffer :pointer)   ; void* optional
  (dw-cert-buffer-length :uint32)   ; DWORD
  (ph-security-context :pointer))   ; HANDLE* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MQGetSecurityContextEx = Win32::API::More->new('mqrt',
    'int MQGetSecurityContextEx(LPVOID lpCertBuffer, DWORD dwCertBufferLength, HANDLE phSecurityContext)');
# my $ret = $MQGetSecurityContextEx->Call($lpCertBuffer, $dwCertBufferLength, $phSecurityContext);
# lpCertBuffer : void* optional -> LPVOID
# dwCertBufferLength : DWORD -> DWORD
# phSecurityContext : HANDLE* out -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API