Win32 API 日本語リファレンス
ホームMedia.Audio › midiOutLongMsg

midiOutLongMsg

関数
システムエクスクルーシブ等のMIDIロングメッセージを送信する。
DLLWINMM.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

DWORD midiOutLongMsg(
    HMIDIOUT hmo,
    MIDIHDR* pmh,
    DWORD cbmh
);

パラメーター

名前方向説明
hmoHMIDIOUTinMIDI 出力デバイスのハンドルです。このパラメーターには、HMIDIOUT にキャストした MIDI ストリームのハンドルを指定することもできます。
pmhMIDIHDR*inMIDI バッファーを識別する MIDIHDR 構造体へのポインターです。
cbmhDWORDinMIDIHDR 構造体のサイズ(バイト単位)です。

戻り値の型: DWORD

公式ドキュメント

midiOutLongMsg 関数は、システムエクスクルーシブ MIDI メッセージを指定された MIDI 出力デバイスに送信します。

戻り値

成功した場合は MMSYSERR_NOERROR を返し、それ以外の場合はエラーを返します。発生し得るエラー値には、次のものがあります。

戻り値 説明
MIDIERR_NOTREADY
ハードウェアが他のデータの処理で使用中です。
MIDIERR_UNPREPARED
lpMidiOutHdr が指すバッファーが準備されていません。
MMSYSERR_INVALHANDLE
指定されたデバイスハンドルが無効です。
MMSYSERR_INVALPARAM
指定されたポインターまたは構造体が無効です。

解説(Remarks)

バッファーを midiOutLongMsg に渡す前に、midiOutPrepareHeader 関数を使用して準備しておく必要があります。データを同期的に送信するか非同期的に送信するかは、MIDI 出力デバイスドライバーが決定します。

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

各言語での呼び出し定義

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

DWORD midiOutLongMsg(
    HMIDIOUT hmo,
    MIDIHDR* pmh,
    DWORD cbmh
);
[DllImport("WINMM.dll", ExactSpelling = true)]
static extern uint midiOutLongMsg(
    IntPtr hmo,   // HMIDIOUT
    IntPtr pmh,   // MIDIHDR*
    uint cbmh   // DWORD
);
<DllImport("WINMM.dll", ExactSpelling:=True)>
Public Shared Function midiOutLongMsg(
    hmo As IntPtr,   ' HMIDIOUT
    pmh As IntPtr,   ' MIDIHDR*
    cbmh As UInteger   ' DWORD
) As UInteger
End Function
' hmo : HMIDIOUT
' pmh : MIDIHDR*
' cbmh : DWORD
Declare PtrSafe Function midiOutLongMsg Lib "winmm" ( _
    ByVal hmo As LongPtr, _
    ByVal pmh As LongPtr, _
    ByVal cbmh As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

midiOutLongMsg = ctypes.windll.winmm.midiOutLongMsg
midiOutLongMsg.restype = wintypes.DWORD
midiOutLongMsg.argtypes = [
    wintypes.HANDLE,  # hmo : HMIDIOUT
    ctypes.c_void_p,  # pmh : MIDIHDR*
    wintypes.DWORD,  # cbmh : DWORD
]
require 'fiddle'
require 'fiddle/import'

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

var (
	winmm = windows.NewLazySystemDLL("WINMM.dll")
	procmidiOutLongMsg = winmm.NewProc("midiOutLongMsg")
)

// hmo (HMIDIOUT), pmh (MIDIHDR*), cbmh (DWORD)
r1, _, err := procmidiOutLongMsg.Call(
	uintptr(hmo),
	uintptr(pmh),
	uintptr(cbmh),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function midiOutLongMsg(
  hmo: THandle;   // HMIDIOUT
  pmh: Pointer;   // MIDIHDR*
  cbmh: DWORD   // DWORD
): DWORD; stdcall;
  external 'WINMM.dll' name 'midiOutLongMsg';
result := DllCall("WINMM\midiOutLongMsg"
    , "Ptr", hmo   ; HMIDIOUT
    , "Ptr", pmh   ; MIDIHDR*
    , "UInt", cbmh   ; DWORD
    , "UInt")   ; return: DWORD
●midiOutLongMsg(hmo, pmh, cbmh) = DLL("WINMM.dll", "dword midiOutLongMsg(void*, void*, dword)")
# 呼び出し: midiOutLongMsg(hmo, pmh, cbmh)
# hmo : HMIDIOUT -> "void*"
# pmh : MIDIHDR* -> "void*"
# cbmh : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef midiOutLongMsgNative = Uint32 Function(Pointer<Void>, Pointer<Void>, Uint32);
typedef midiOutLongMsgDart = int Function(Pointer<Void>, Pointer<Void>, int);
final midiOutLongMsg = DynamicLibrary.open('WINMM.dll')
    .lookupFunction<midiOutLongMsgNative, midiOutLongMsgDart>('midiOutLongMsg');
// hmo : HMIDIOUT -> Pointer<Void>
// pmh : MIDIHDR* -> Pointer<Void>
// cbmh : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function midiOutLongMsg(
  hmo: THandle;   // HMIDIOUT
  pmh: Pointer;   // MIDIHDR*
  cbmh: DWORD   // DWORD
): DWORD; stdcall;
  external 'WINMM.dll' name 'midiOutLongMsg';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "midiOutLongMsg"
  c_midiOutLongMsg :: Ptr () -> Ptr () -> Word32 -> IO Word32
-- hmo : HMIDIOUT -> Ptr ()
-- pmh : MIDIHDR* -> Ptr ()
-- cbmh : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let midioutlongmsg =
  foreign "midiOutLongMsg"
    ((ptr void) @-> (ptr void) @-> uint32_t @-> returning uint32_t)
(* hmo : HMIDIOUT -> (ptr void) *)
(* pmh : MIDIHDR* -> (ptr void) *)
(* cbmh : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library winmm (t "WINMM.dll"))
(cffi:use-foreign-library winmm)

(cffi:defcfun ("midiOutLongMsg" midi-out-long-msg :convention :stdcall) :uint32
  (hmo :pointer)   ; HMIDIOUT
  (pmh :pointer)   ; MIDIHDR*
  (cbmh :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $midiOutLongMsg = Win32::API::More->new('WINMM',
    'DWORD midiOutLongMsg(HANDLE hmo, LPVOID pmh, DWORD cbmh)');
# my $ret = $midiOutLongMsg->Call($hmo, $pmh, $cbmh);
# hmo : HMIDIOUT -> HANDLE
# pmh : MIDIHDR* -> LPVOID
# cbmh : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型