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

MQCreateQueue

関数
メッセージキューを新規作成する。
DLLmqrt.dll呼出規約winapi

シグネチャ

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

HRESULT MQCreateQueue(
    PSECURITY_DESCRIPTOR pSecurityDescriptor,   // optional
    MQQUEUEPROPS* pQueueProps,
    LPWSTR lpwcsFormatName,   // optional
    DWORD* lpdwFormatNameLength
);

パラメーター

名前方向説明
pSecurityDescriptorPSECURITY_DESCRIPTORinoptional新規キューに設定するセキュリティ記述子へのポインタ。NULL可で既定のセキュリティとなる。
pQueuePropsMQQUEUEPROPS*inout作成するキューのプロパティ(パス名等)を格納したMQQUEUEPROPS構造体へのポインタを指定する。
lpwcsFormatNameLPWSTRoutoptional生成されたキューのフォーマット名を受け取るワイド文字列バッファを指定する。NULL可。
lpdwFormatNameLengthDWORD*inout入力でバッファ文字数、出力で実際の長さを受け渡すDWORDへのポインタを指定する。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT MQCreateQueue(
    PSECURITY_DESCRIPTOR pSecurityDescriptor,   // optional
    MQQUEUEPROPS* pQueueProps,
    LPWSTR lpwcsFormatName,   // optional
    DWORD* lpdwFormatNameLength
);
[DllImport("mqrt.dll", ExactSpelling = true)]
static extern int MQCreateQueue(
    IntPtr pSecurityDescriptor,   // PSECURITY_DESCRIPTOR optional
    IntPtr pQueueProps,   // MQQUEUEPROPS* in/out
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpwcsFormatName,   // LPWSTR optional, out
    ref uint lpdwFormatNameLength   // DWORD* in/out
);
<DllImport("mqrt.dll", ExactSpelling:=True)>
Public Shared Function MQCreateQueue(
    pSecurityDescriptor As IntPtr,   ' PSECURITY_DESCRIPTOR optional
    pQueueProps As IntPtr,   ' MQQUEUEPROPS* in/out
    <MarshalAs(UnmanagedType.LPWStr)> lpwcsFormatName As System.Text.StringBuilder,   ' LPWSTR optional, out
    ByRef lpdwFormatNameLength As UInteger   ' DWORD* in/out
) As Integer
End Function
' pSecurityDescriptor : PSECURITY_DESCRIPTOR optional
' pQueueProps : MQQUEUEPROPS* in/out
' lpwcsFormatName : LPWSTR optional, out
' lpdwFormatNameLength : DWORD* in/out
Declare PtrSafe Function MQCreateQueue Lib "mqrt" ( _
    ByVal pSecurityDescriptor As LongPtr, _
    ByVal pQueueProps As LongPtr, _
    ByVal lpwcsFormatName As LongPtr, _
    ByRef lpdwFormatNameLength As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

MQCreateQueue = ctypes.windll.mqrt.MQCreateQueue
MQCreateQueue.restype = ctypes.c_int
MQCreateQueue.argtypes = [
    wintypes.HANDLE,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR optional
    ctypes.c_void_p,  # pQueueProps : MQQUEUEPROPS* in/out
    wintypes.LPWSTR,  # lpwcsFormatName : LPWSTR optional, out
    ctypes.POINTER(wintypes.DWORD),  # lpdwFormatNameLength : DWORD* in/out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	mqrt = windows.NewLazySystemDLL("mqrt.dll")
	procMQCreateQueue = mqrt.NewProc("MQCreateQueue")
)

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

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

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

foreign import stdcall safe "MQCreateQueue"
  c_MQCreateQueue :: Ptr () -> Ptr () -> CWString -> Ptr Word32 -> IO Int32
-- pSecurityDescriptor : PSECURITY_DESCRIPTOR optional -> Ptr ()
-- pQueueProps : MQQUEUEPROPS* in/out -> Ptr ()
-- lpwcsFormatName : LPWSTR optional, out -> CWString
-- lpdwFormatNameLength : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let mqcreatequeue =
  foreign "MQCreateQueue"
    ((ptr void) @-> (ptr void) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> returning int32_t)
(* pSecurityDescriptor : PSECURITY_DESCRIPTOR optional -> (ptr void) *)
(* pQueueProps : MQQUEUEPROPS* in/out -> (ptr void) *)
(* lpwcsFormatName : LPWSTR optional, out -> (ptr uint16_t) *)
(* lpdwFormatNameLength : DWORD* in/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 ("MQCreateQueue" mqcreate-queue :convention :stdcall) :int32
  (p-security-descriptor :pointer)   ; PSECURITY_DESCRIPTOR optional
  (p-queue-props :pointer)   ; MQQUEUEPROPS* in/out
  (lpwcs-format-name :pointer)   ; LPWSTR optional, out
  (lpdw-format-name-length :pointer))   ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MQCreateQueue = Win32::API::More->new('mqrt',
    'int MQCreateQueue(HANDLE pSecurityDescriptor, LPVOID pQueueProps, LPWSTR lpwcsFormatName, LPVOID lpdwFormatNameLength)');
# my $ret = $MQCreateQueue->Call($pSecurityDescriptor, $pQueueProps, $lpwcsFormatName, $lpdwFormatNameLength);
# pSecurityDescriptor : PSECURITY_DESCRIPTOR optional -> HANDLE
# pQueueProps : MQQUEUEPROPS* in/out -> LPVOID
# lpwcsFormatName : LPWSTR optional, out -> LPWSTR
# lpdwFormatNameLength : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型