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

midiOutOpen

関数
再生用のMIDI出力デバイスを開く。
DLLWINMM.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

DWORD midiOutOpen(
    HMIDIOUT* phmo,
    DWORD uDeviceID,
    UINT_PTR dwCallback,   // optional
    UINT_PTR dwInstance,   // optional
    MIDI_WAVE_OPEN_TYPE fdwOpen
);

パラメーター

名前方向
phmoHMIDIOUT*out
uDeviceIDDWORDin
dwCallbackUINT_PTRinoptional
dwInstanceUINT_PTRinoptional
fdwOpenMIDI_WAVE_OPEN_TYPEin

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD midiOutOpen(
    HMIDIOUT* phmo,
    DWORD uDeviceID,
    UINT_PTR dwCallback,   // optional
    UINT_PTR dwInstance,   // optional
    MIDI_WAVE_OPEN_TYPE fdwOpen
);
[DllImport("WINMM.dll", ExactSpelling = true)]
static extern uint midiOutOpen(
    IntPtr phmo,   // HMIDIOUT* out
    uint uDeviceID,   // DWORD
    UIntPtr dwCallback,   // UINT_PTR optional
    UIntPtr dwInstance,   // UINT_PTR optional
    uint fdwOpen   // MIDI_WAVE_OPEN_TYPE
);
<DllImport("WINMM.dll", ExactSpelling:=True)>
Public Shared Function midiOutOpen(
    phmo As IntPtr,   ' HMIDIOUT* out
    uDeviceID As UInteger,   ' DWORD
    dwCallback As UIntPtr,   ' UINT_PTR optional
    dwInstance As UIntPtr,   ' UINT_PTR optional
    fdwOpen As UInteger   ' MIDI_WAVE_OPEN_TYPE
) As UInteger
End Function
' phmo : HMIDIOUT* out
' uDeviceID : DWORD
' dwCallback : UINT_PTR optional
' dwInstance : UINT_PTR optional
' fdwOpen : MIDI_WAVE_OPEN_TYPE
Declare PtrSafe Function midiOutOpen Lib "winmm" ( _
    ByVal phmo As LongPtr, _
    ByVal uDeviceID As Long, _
    ByVal dwCallback As LongPtr, _
    ByVal dwInstance As LongPtr, _
    ByVal fdwOpen As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

midiOutOpen = ctypes.windll.winmm.midiOutOpen
midiOutOpen.restype = wintypes.DWORD
midiOutOpen.argtypes = [
    ctypes.c_void_p,  # phmo : HMIDIOUT* out
    wintypes.DWORD,  # uDeviceID : DWORD
    ctypes.c_size_t,  # dwCallback : UINT_PTR optional
    ctypes.c_size_t,  # dwInstance : UINT_PTR optional
    wintypes.DWORD,  # fdwOpen : MIDI_WAVE_OPEN_TYPE
]
require 'fiddle'
require 'fiddle/import'

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

var (
	winmm = windows.NewLazySystemDLL("WINMM.dll")
	procmidiOutOpen = winmm.NewProc("midiOutOpen")
)

// phmo (HMIDIOUT* out), uDeviceID (DWORD), dwCallback (UINT_PTR optional), dwInstance (UINT_PTR optional), fdwOpen (MIDI_WAVE_OPEN_TYPE)
r1, _, err := procmidiOutOpen.Call(
	uintptr(phmo),
	uintptr(uDeviceID),
	uintptr(dwCallback),
	uintptr(dwInstance),
	uintptr(fdwOpen),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function midiOutOpen(
  phmo: Pointer;   // HMIDIOUT* out
  uDeviceID: DWORD;   // DWORD
  dwCallback: NativeUInt;   // UINT_PTR optional
  dwInstance: NativeUInt;   // UINT_PTR optional
  fdwOpen: DWORD   // MIDI_WAVE_OPEN_TYPE
): DWORD; stdcall;
  external 'WINMM.dll' name 'midiOutOpen';
result := DllCall("WINMM\midiOutOpen"
    , "Ptr", phmo   ; HMIDIOUT* out
    , "UInt", uDeviceID   ; DWORD
    , "UPtr", dwCallback   ; UINT_PTR optional
    , "UPtr", dwInstance   ; UINT_PTR optional
    , "UInt", fdwOpen   ; MIDI_WAVE_OPEN_TYPE
    , "UInt")   ; return: DWORD
●midiOutOpen(phmo, uDeviceID, dwCallback, dwInstance, fdwOpen) = DLL("WINMM.dll", "dword midiOutOpen(void*, dword, int, int, dword)")
# 呼び出し: midiOutOpen(phmo, uDeviceID, dwCallback, dwInstance, fdwOpen)
# phmo : HMIDIOUT* out -> "void*"
# uDeviceID : DWORD -> "dword"
# dwCallback : UINT_PTR optional -> "int"
# dwInstance : UINT_PTR optional -> "int"
# fdwOpen : MIDI_WAVE_OPEN_TYPE -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。