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

MQGetQueueSecurity

関数
キューのセキュリティ記述子を取得する。
DLLmqrt.dll呼出規約winapi

シグネチャ

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

HRESULT MQGetQueueSecurity(
    LPCWSTR lpwcsFormatName,
    DWORD RequestedInformation,
    PSECURITY_DESCRIPTOR pSecurityDescriptor,
    DWORD nLength,
    DWORD* lpnLengthNeeded
);

パラメーター

名前方向説明
lpwcsFormatNameLPCWSTRinセキュリティ情報を取得する対象キューのフォーマット名(ワイド文字列)を指定する。
RequestedInformationDWORDin取得するセキュリティ情報の種別。OWNER/GROUP/DACL/SACL_SECURITY_INFORMATION等を指定する。
pSecurityDescriptorPSECURITY_DESCRIPTORout取得したセキュリティ記述子を受け取るバッファへのポインタを指定する。
nLengthDWORDinpSecurityDescriptorバッファのバイト数を指定する。
lpnLengthNeededDWORD*out必要なバッファのバイト数を受け取るDWORDへのポインタを指定する。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT MQGetQueueSecurity(
    LPCWSTR lpwcsFormatName,
    DWORD RequestedInformation,
    PSECURITY_DESCRIPTOR pSecurityDescriptor,
    DWORD nLength,
    DWORD* lpnLengthNeeded
);
[DllImport("mqrt.dll", ExactSpelling = true)]
static extern int MQGetQueueSecurity(
    [MarshalAs(UnmanagedType.LPWStr)] string lpwcsFormatName,   // LPCWSTR
    uint RequestedInformation,   // DWORD
    IntPtr pSecurityDescriptor,   // PSECURITY_DESCRIPTOR out
    uint nLength,   // DWORD
    out uint lpnLengthNeeded   // DWORD* out
);
<DllImport("mqrt.dll", ExactSpelling:=True)>
Public Shared Function MQGetQueueSecurity(
    <MarshalAs(UnmanagedType.LPWStr)> lpwcsFormatName As String,   ' LPCWSTR
    RequestedInformation As UInteger,   ' DWORD
    pSecurityDescriptor As IntPtr,   ' PSECURITY_DESCRIPTOR out
    nLength As UInteger,   ' DWORD
    <Out> ByRef lpnLengthNeeded As UInteger   ' DWORD* out
) As Integer
End Function
' lpwcsFormatName : LPCWSTR
' RequestedInformation : DWORD
' pSecurityDescriptor : PSECURITY_DESCRIPTOR out
' nLength : DWORD
' lpnLengthNeeded : DWORD* out
Declare PtrSafe Function MQGetQueueSecurity Lib "mqrt" ( _
    ByVal lpwcsFormatName As LongPtr, _
    ByVal RequestedInformation As Long, _
    ByVal pSecurityDescriptor As LongPtr, _
    ByVal nLength As Long, _
    ByRef lpnLengthNeeded As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

MQGetQueueSecurity = ctypes.windll.mqrt.MQGetQueueSecurity
MQGetQueueSecurity.restype = ctypes.c_int
MQGetQueueSecurity.argtypes = [
    wintypes.LPCWSTR,  # lpwcsFormatName : LPCWSTR
    wintypes.DWORD,  # RequestedInformation : DWORD
    wintypes.HANDLE,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR out
    wintypes.DWORD,  # nLength : DWORD
    ctypes.POINTER(wintypes.DWORD),  # lpnLengthNeeded : DWORD* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('mqrt.dll')
MQGetQueueSecurity = Fiddle::Function.new(
  lib['MQGetQueueSecurity'],
  [
    Fiddle::TYPE_VOIDP,  # lpwcsFormatName : LPCWSTR
    -Fiddle::TYPE_INT,  # RequestedInformation : DWORD
    Fiddle::TYPE_VOIDP,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR out
    -Fiddle::TYPE_INT,  # nLength : DWORD
    Fiddle::TYPE_VOIDP,  # lpnLengthNeeded : DWORD* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "mqrt")]
extern "system" {
    fn MQGetQueueSecurity(
        lpwcsFormatName: *const u16,  // LPCWSTR
        RequestedInformation: u32,  // DWORD
        pSecurityDescriptor: *mut core::ffi::c_void,  // PSECURITY_DESCRIPTOR out
        nLength: u32,  // DWORD
        lpnLengthNeeded: *mut u32  // DWORD* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("mqrt.dll")]
public static extern int MQGetQueueSecurity([MarshalAs(UnmanagedType.LPWStr)] string lpwcsFormatName, uint RequestedInformation, IntPtr pSecurityDescriptor, uint nLength, out uint lpnLengthNeeded);
"@
$api = Add-Type -MemberDefinition $sig -Name 'mqrt_MQGetQueueSecurity' -Namespace Win32 -PassThru
# $api::MQGetQueueSecurity(lpwcsFormatName, RequestedInformation, pSecurityDescriptor, nLength, lpnLengthNeeded)
#uselib "mqrt.dll"
#func global MQGetQueueSecurity "MQGetQueueSecurity" sptr, sptr, sptr, sptr, sptr
; MQGetQueueSecurity lpwcsFormatName, RequestedInformation, pSecurityDescriptor, nLength, varptr(lpnLengthNeeded)   ; 戻り値は stat
; lpwcsFormatName : LPCWSTR -> "sptr"
; RequestedInformation : DWORD -> "sptr"
; pSecurityDescriptor : PSECURITY_DESCRIPTOR out -> "sptr"
; nLength : DWORD -> "sptr"
; lpnLengthNeeded : DWORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "mqrt.dll"
#cfunc global MQGetQueueSecurity "MQGetQueueSecurity" wstr, int, sptr, int, var
; res = MQGetQueueSecurity(lpwcsFormatName, RequestedInformation, pSecurityDescriptor, nLength, lpnLengthNeeded)
; lpwcsFormatName : LPCWSTR -> "wstr"
; RequestedInformation : DWORD -> "int"
; pSecurityDescriptor : PSECURITY_DESCRIPTOR out -> "sptr"
; nLength : DWORD -> "int"
; lpnLengthNeeded : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT MQGetQueueSecurity(LPCWSTR lpwcsFormatName, DWORD RequestedInformation, PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD nLength, DWORD* lpnLengthNeeded)
#uselib "mqrt.dll"
#cfunc global MQGetQueueSecurity "MQGetQueueSecurity" wstr, int, intptr, int, var
; res = MQGetQueueSecurity(lpwcsFormatName, RequestedInformation, pSecurityDescriptor, nLength, lpnLengthNeeded)
; lpwcsFormatName : LPCWSTR -> "wstr"
; RequestedInformation : DWORD -> "int"
; pSecurityDescriptor : PSECURITY_DESCRIPTOR out -> "intptr"
; nLength : DWORD -> "int"
; lpnLengthNeeded : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	mqrt = windows.NewLazySystemDLL("mqrt.dll")
	procMQGetQueueSecurity = mqrt.NewProc("MQGetQueueSecurity")
)

// lpwcsFormatName (LPCWSTR), RequestedInformation (DWORD), pSecurityDescriptor (PSECURITY_DESCRIPTOR out), nLength (DWORD), lpnLengthNeeded (DWORD* out)
r1, _, err := procMQGetQueueSecurity.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpwcsFormatName))),
	uintptr(RequestedInformation),
	uintptr(pSecurityDescriptor),
	uintptr(nLength),
	uintptr(lpnLengthNeeded),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function MQGetQueueSecurity(
  lpwcsFormatName: PWideChar;   // LPCWSTR
  RequestedInformation: DWORD;   // DWORD
  pSecurityDescriptor: THandle;   // PSECURITY_DESCRIPTOR out
  nLength: DWORD;   // DWORD
  lpnLengthNeeded: Pointer   // DWORD* out
): Integer; stdcall;
  external 'mqrt.dll' name 'MQGetQueueSecurity';
result := DllCall("mqrt\MQGetQueueSecurity"
    , "WStr", lpwcsFormatName   ; LPCWSTR
    , "UInt", RequestedInformation   ; DWORD
    , "Ptr", pSecurityDescriptor   ; PSECURITY_DESCRIPTOR out
    , "UInt", nLength   ; DWORD
    , "Ptr", lpnLengthNeeded   ; DWORD* out
    , "Int")   ; return: HRESULT
●MQGetQueueSecurity(lpwcsFormatName, RequestedInformation, pSecurityDescriptor, nLength, lpnLengthNeeded) = DLL("mqrt.dll", "int MQGetQueueSecurity(char*, dword, void*, dword, void*)")
# 呼び出し: MQGetQueueSecurity(lpwcsFormatName, RequestedInformation, pSecurityDescriptor, nLength, lpnLengthNeeded)
# lpwcsFormatName : LPCWSTR -> "char*"
# RequestedInformation : DWORD -> "dword"
# pSecurityDescriptor : PSECURITY_DESCRIPTOR out -> "void*"
# nLength : DWORD -> "dword"
# lpnLengthNeeded : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef MQGetQueueSecurityNative = Int32 Function(Pointer<Utf16>, Uint32, Pointer<Void>, Uint32, Pointer<Uint32>);
typedef MQGetQueueSecurityDart = int Function(Pointer<Utf16>, int, Pointer<Void>, int, Pointer<Uint32>);
final MQGetQueueSecurity = DynamicLibrary.open('mqrt.dll')
    .lookupFunction<MQGetQueueSecurityNative, MQGetQueueSecurityDart>('MQGetQueueSecurity');
// lpwcsFormatName : LPCWSTR -> Pointer<Utf16>
// RequestedInformation : DWORD -> Uint32
// pSecurityDescriptor : PSECURITY_DESCRIPTOR out -> Pointer<Void>
// nLength : DWORD -> Uint32
// lpnLengthNeeded : DWORD* out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function MQGetQueueSecurity(
  lpwcsFormatName: PWideChar;   // LPCWSTR
  RequestedInformation: DWORD;   // DWORD
  pSecurityDescriptor: THandle;   // PSECURITY_DESCRIPTOR out
  nLength: DWORD;   // DWORD
  lpnLengthNeeded: Pointer   // DWORD* out
): Integer; stdcall;
  external 'mqrt.dll' name 'MQGetQueueSecurity';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "MQGetQueueSecurity"
  c_MQGetQueueSecurity :: CWString -> Word32 -> Ptr () -> Word32 -> Ptr Word32 -> IO Int32
-- lpwcsFormatName : LPCWSTR -> CWString
-- RequestedInformation : DWORD -> Word32
-- pSecurityDescriptor : PSECURITY_DESCRIPTOR out -> Ptr ()
-- nLength : DWORD -> Word32
-- lpnLengthNeeded : DWORD* out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let mqgetqueuesecurity =
  foreign "MQGetQueueSecurity"
    ((ptr uint16_t) @-> uint32_t @-> (ptr void) @-> uint32_t @-> (ptr uint32_t) @-> returning int32_t)
(* lpwcsFormatName : LPCWSTR -> (ptr uint16_t) *)
(* RequestedInformation : DWORD -> uint32_t *)
(* pSecurityDescriptor : PSECURITY_DESCRIPTOR out -> (ptr void) *)
(* nLength : DWORD -> uint32_t *)
(* lpnLengthNeeded : DWORD* out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library mqrt (t "mqrt.dll"))
(cffi:use-foreign-library mqrt)

(cffi:defcfun ("MQGetQueueSecurity" mqget-queue-security :convention :stdcall) :int32
  (lpwcs-format-name (:string :encoding :utf-16le))   ; LPCWSTR
  (requested-information :uint32)   ; DWORD
  (p-security-descriptor :pointer)   ; PSECURITY_DESCRIPTOR out
  (n-length :uint32)   ; DWORD
  (lpn-length-needed :pointer))   ; DWORD* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MQGetQueueSecurity = Win32::API::More->new('mqrt',
    'int MQGetQueueSecurity(LPCWSTR lpwcsFormatName, DWORD RequestedInformation, HANDLE pSecurityDescriptor, DWORD nLength, LPVOID lpnLengthNeeded)');
# my $ret = $MQGetQueueSecurity->Call($lpwcsFormatName, $RequestedInformation, $pSecurityDescriptor, $nLength, $lpnLengthNeeded);
# lpwcsFormatName : LPCWSTR -> LPCWSTR
# RequestedInformation : DWORD -> DWORD
# pSecurityDescriptor : PSECURITY_DESCRIPTOR out -> HANDLE
# nLength : DWORD -> DWORD
# lpnLengthNeeded : DWORD* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。