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

CreateRenderAudioStateMonitorForCategoryAndDeviceId

関数
カテゴリとデバイスID指定でレンダリング状態監視を生成する。
DLLWindows.Media.MediaControl.dll呼出規約winapi

シグネチャ

// Windows.Media.MediaControl.dll
#include <windows.h>

HRESULT CreateRenderAudioStateMonitorForCategoryAndDeviceId(
    AUDIO_STREAM_CATEGORY category,
    LPCWSTR deviceId,
    IAudioStateMonitor** audioStateMonitor
);

パラメーター

名前方向説明
categoryAUDIO_STREAM_CATEGORYin監視対象とするオーディオストリームのカテゴリ(AUDIO_STREAM_CATEGORY列挙値)。
deviceIdLPCWSTRin監視対象とするオーディオエンドポイントのデバイスID文字列(Unicode)。
audioStateMonitorIAudioStateMonitor**out作成したレンダリング用オーディオ状態モニタIAudioStateMonitorを受け取るポインタ。

戻り値の型: HRESULT

各言語での呼び出し定義

// Windows.Media.MediaControl.dll
#include <windows.h>

HRESULT CreateRenderAudioStateMonitorForCategoryAndDeviceId(
    AUDIO_STREAM_CATEGORY category,
    LPCWSTR deviceId,
    IAudioStateMonitor** audioStateMonitor
);
[DllImport("Windows.Media.MediaControl.dll", ExactSpelling = true)]
static extern int CreateRenderAudioStateMonitorForCategoryAndDeviceId(
    int category,   // AUDIO_STREAM_CATEGORY
    [MarshalAs(UnmanagedType.LPWStr)] string deviceId,   // LPCWSTR
    IntPtr audioStateMonitor   // IAudioStateMonitor** out
);
<DllImport("Windows.Media.MediaControl.dll", ExactSpelling:=True)>
Public Shared Function CreateRenderAudioStateMonitorForCategoryAndDeviceId(
    category As Integer,   ' AUDIO_STREAM_CATEGORY
    <MarshalAs(UnmanagedType.LPWStr)> deviceId As String,   ' LPCWSTR
    audioStateMonitor As IntPtr   ' IAudioStateMonitor** out
) As Integer
End Function
' category : AUDIO_STREAM_CATEGORY
' deviceId : LPCWSTR
' audioStateMonitor : IAudioStateMonitor** out
Declare PtrSafe Function CreateRenderAudioStateMonitorForCategoryAndDeviceId Lib "windows.media.mediacontrol" ( _
    ByVal category As Long, _
    ByVal deviceId As LongPtr, _
    ByVal audioStateMonitor As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CreateRenderAudioStateMonitorForCategoryAndDeviceId = ctypes.windll.LoadLibrary("Windows.Media.MediaControl.dll").CreateRenderAudioStateMonitorForCategoryAndDeviceId
CreateRenderAudioStateMonitorForCategoryAndDeviceId.restype = ctypes.c_int
CreateRenderAudioStateMonitorForCategoryAndDeviceId.argtypes = [
    ctypes.c_int,  # category : AUDIO_STREAM_CATEGORY
    wintypes.LPCWSTR,  # deviceId : LPCWSTR
    ctypes.c_void_p,  # audioStateMonitor : IAudioStateMonitor** out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('Windows.Media.MediaControl.dll')
CreateRenderAudioStateMonitorForCategoryAndDeviceId = Fiddle::Function.new(
  lib['CreateRenderAudioStateMonitorForCategoryAndDeviceId'],
  [
    Fiddle::TYPE_INT,  # category : AUDIO_STREAM_CATEGORY
    Fiddle::TYPE_VOIDP,  # deviceId : LPCWSTR
    Fiddle::TYPE_VOIDP,  # audioStateMonitor : IAudioStateMonitor** out
  ],
  Fiddle::TYPE_INT)
#[link(name = "windows.media.mediacontrol")]
extern "system" {
    fn CreateRenderAudioStateMonitorForCategoryAndDeviceId(
        category: i32,  // AUDIO_STREAM_CATEGORY
        deviceId: *const u16,  // LPCWSTR
        audioStateMonitor: *mut *mut core::ffi::c_void  // IAudioStateMonitor** out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("Windows.Media.MediaControl.dll")]
public static extern int CreateRenderAudioStateMonitorForCategoryAndDeviceId(int category, [MarshalAs(UnmanagedType.LPWStr)] string deviceId, IntPtr audioStateMonitor);
"@
$api = Add-Type -MemberDefinition $sig -Name 'Windows.Media.MediaControl_CreateRenderAudioStateMonitorForCategoryAndDeviceId' -Namespace Win32 -PassThru
# $api::CreateRenderAudioStateMonitorForCategoryAndDeviceId(category, deviceId, audioStateMonitor)
#uselib "Windows.Media.MediaControl.dll"
#func global CreateRenderAudioStateMonitorForCategoryAndDeviceId "CreateRenderAudioStateMonitorForCategoryAndDeviceId" sptr, sptr, sptr
; CreateRenderAudioStateMonitorForCategoryAndDeviceId category, deviceId, audioStateMonitor   ; 戻り値は stat
; category : AUDIO_STREAM_CATEGORY -> "sptr"
; deviceId : LPCWSTR -> "sptr"
; audioStateMonitor : IAudioStateMonitor** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "Windows.Media.MediaControl.dll"
#cfunc global CreateRenderAudioStateMonitorForCategoryAndDeviceId "CreateRenderAudioStateMonitorForCategoryAndDeviceId" int, wstr, sptr
; res = CreateRenderAudioStateMonitorForCategoryAndDeviceId(category, deviceId, audioStateMonitor)
; category : AUDIO_STREAM_CATEGORY -> "int"
; deviceId : LPCWSTR -> "wstr"
; audioStateMonitor : IAudioStateMonitor** out -> "sptr"
; HRESULT CreateRenderAudioStateMonitorForCategoryAndDeviceId(AUDIO_STREAM_CATEGORY category, LPCWSTR deviceId, IAudioStateMonitor** audioStateMonitor)
#uselib "Windows.Media.MediaControl.dll"
#cfunc global CreateRenderAudioStateMonitorForCategoryAndDeviceId "CreateRenderAudioStateMonitorForCategoryAndDeviceId" int, wstr, intptr
; res = CreateRenderAudioStateMonitorForCategoryAndDeviceId(category, deviceId, audioStateMonitor)
; category : AUDIO_STREAM_CATEGORY -> "int"
; deviceId : LPCWSTR -> "wstr"
; audioStateMonitor : IAudioStateMonitor** out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	windows_media_mediacontrol = windows.NewLazySystemDLL("Windows.Media.MediaControl.dll")
	procCreateRenderAudioStateMonitorForCategoryAndDeviceId = windows_media_mediacontrol.NewProc("CreateRenderAudioStateMonitorForCategoryAndDeviceId")
)

// category (AUDIO_STREAM_CATEGORY), deviceId (LPCWSTR), audioStateMonitor (IAudioStateMonitor** out)
r1, _, err := procCreateRenderAudioStateMonitorForCategoryAndDeviceId.Call(
	uintptr(category),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(deviceId))),
	uintptr(audioStateMonitor),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function CreateRenderAudioStateMonitorForCategoryAndDeviceId(
  category: Integer;   // AUDIO_STREAM_CATEGORY
  deviceId: PWideChar;   // LPCWSTR
  audioStateMonitor: Pointer   // IAudioStateMonitor** out
): Integer; stdcall;
  external 'Windows.Media.MediaControl.dll' name 'CreateRenderAudioStateMonitorForCategoryAndDeviceId';
result := DllCall("Windows.Media.MediaControl\CreateRenderAudioStateMonitorForCategoryAndDeviceId"
    , "Int", category   ; AUDIO_STREAM_CATEGORY
    , "WStr", deviceId   ; LPCWSTR
    , "Ptr", audioStateMonitor   ; IAudioStateMonitor** out
    , "Int")   ; return: HRESULT
●CreateRenderAudioStateMonitorForCategoryAndDeviceId(category, deviceId, audioStateMonitor) = DLL("Windows.Media.MediaControl.dll", "int CreateRenderAudioStateMonitorForCategoryAndDeviceId(int, char*, void*)")
# 呼び出し: CreateRenderAudioStateMonitorForCategoryAndDeviceId(category, deviceId, audioStateMonitor)
# category : AUDIO_STREAM_CATEGORY -> "int"
# deviceId : LPCWSTR -> "char*"
# audioStateMonitor : IAudioStateMonitor** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef CreateRenderAudioStateMonitorForCategoryAndDeviceIdNative = Int32 Function(Int32, Pointer<Utf16>, Pointer<Void>);
typedef CreateRenderAudioStateMonitorForCategoryAndDeviceIdDart = int Function(int, Pointer<Utf16>, Pointer<Void>);
final CreateRenderAudioStateMonitorForCategoryAndDeviceId = DynamicLibrary.open('Windows.Media.MediaControl.dll')
    .lookupFunction<CreateRenderAudioStateMonitorForCategoryAndDeviceIdNative, CreateRenderAudioStateMonitorForCategoryAndDeviceIdDart>('CreateRenderAudioStateMonitorForCategoryAndDeviceId');
// category : AUDIO_STREAM_CATEGORY -> Int32
// deviceId : LPCWSTR -> Pointer<Utf16>
// audioStateMonitor : IAudioStateMonitor** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CreateRenderAudioStateMonitorForCategoryAndDeviceId(
  category: Integer;   // AUDIO_STREAM_CATEGORY
  deviceId: PWideChar;   // LPCWSTR
  audioStateMonitor: Pointer   // IAudioStateMonitor** out
): Integer; stdcall;
  external 'Windows.Media.MediaControl.dll' name 'CreateRenderAudioStateMonitorForCategoryAndDeviceId';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CreateRenderAudioStateMonitorForCategoryAndDeviceId"
  c_CreateRenderAudioStateMonitorForCategoryAndDeviceId :: Int32 -> CWString -> Ptr () -> IO Int32
-- category : AUDIO_STREAM_CATEGORY -> Int32
-- deviceId : LPCWSTR -> CWString
-- audioStateMonitor : IAudioStateMonitor** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let createrenderaudiostatemonitorforcategoryanddeviceid =
  foreign "CreateRenderAudioStateMonitorForCategoryAndDeviceId"
    (int32_t @-> (ptr uint16_t) @-> (ptr void) @-> returning int32_t)
(* category : AUDIO_STREAM_CATEGORY -> int32_t *)
(* deviceId : LPCWSTR -> (ptr uint16_t) *)
(* audioStateMonitor : IAudioStateMonitor** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library windows.media.mediacontrol (t "Windows.Media.MediaControl.dll"))
(cffi:use-foreign-library windows.media.mediacontrol)

(cffi:defcfun ("CreateRenderAudioStateMonitorForCategoryAndDeviceId" create-render-audio-state-monitor-for-category-and-device-id :convention :stdcall) :int32
  (category :int32)   ; AUDIO_STREAM_CATEGORY
  (device-id (:string :encoding :utf-16le))   ; LPCWSTR
  (audio-state-monitor :pointer))   ; IAudioStateMonitor** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CreateRenderAudioStateMonitorForCategoryAndDeviceId = Win32::API::More->new('Windows.Media.MediaControl',
    'int CreateRenderAudioStateMonitorForCategoryAndDeviceId(int category, LPCWSTR deviceId, LPVOID audioStateMonitor)');
# my $ret = $CreateRenderAudioStateMonitorForCategoryAndDeviceId->Call($category, $deviceId, $audioStateMonitor);
# category : AUDIO_STREAM_CATEGORY -> int
# deviceId : LPCWSTR -> LPCWSTR
# audioStateMonitor : IAudioStateMonitor** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型