waveOutGetVolume
関数シグネチャ
// WINMM.dll
#include <windows.h>
DWORD waveOutGetVolume(
HWAVEOUT hwo, // optional
DWORD* pdwVolume
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hwo | HWAVEOUT | inoptional | 開いている波形オーディオ出力デバイスへのハンドル。このパラメーターはデバイス識別子でも指定できます。 |
| pdwVolume | DWORD* | out | 現在の音量設定が格納される変数へのポインター。この場所の下位ワードには左チャンネルの音量設定が、上位ワードには右チャンネルの設定が格納されます。値 0xFFFF は最大音量を、値 0x0000 は無音を表します。 デバイスが左右両方の音量制御をサポートしていない場合、指定された場所の下位ワードにはモノラルの音量レベルが格納されます。 waveOutSetVolume 関数で設定された 16 ビット全体の設定値が、デバイスが 16 ビット全体の音量レベル制御をサポートしているかどうかに関係なく返されます。 |
戻り値の型: DWORD
公式ドキュメント
waveOutGetVolume 関数は、指定された波形オーディオ出力デバイスの現在の音量レベルを取得します。
戻り値
成功した場合は MMSYSERR_NOERROR を返し、それ以外の場合はエラーを返します。考えられるエラー値には次のものが含まれます。
| 戻り値 | 説明 |
|---|---|
| 指定されたデバイスハンドルが無効です。 | |
| デバイスドライバーが存在しません。 | |
| メモリの割り当てまたはロックができません。 | |
| 関数がサポートされていません。 |
解説(Remarks)
デバイス識別子を使用した場合、waveOutGetVolume 呼び出しの結果と pdwVolume で返される情報は、そのデバイスのすべてのインスタンスに適用されます。デバイスハンドルを使用した場合、結果と返される情報は、そのデバイスハンドルが参照するデバイスのインスタンスにのみ適用されます。
すべてのデバイスが音量変更をサポートしているわけではありません。デバイスが音量制御をサポートしているかどうかを確認するには、WAVECAPS_VOLUME フラグを使用して、WAVEOUTCAPS 構造体(waveOutGetDevCaps 関数によって設定される)の dwSupport メンバーをテストします。
デバイスが左右チャンネルの音量制御をサポートしているかどうかを確認するには、WAVECAPS_LRVOLUME フラグを使用して、WAVEOUTCAPS 構造体(waveOutGetDevCaps によって設定される)の dwSupport メンバーをテストします。
音量設定は対数的に解釈されます。これは、音量レベルを 0x4000 から 0x5000 に上げたときと、0x5000 から 0x6000 に上げたときとで、知覚される音量の増加が同じであることを意味します。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// WINMM.dll
#include <windows.h>
DWORD waveOutGetVolume(
HWAVEOUT hwo, // optional
DWORD* pdwVolume
);[DllImport("WINMM.dll", ExactSpelling = true)]
static extern uint waveOutGetVolume(
IntPtr hwo, // HWAVEOUT optional
out uint pdwVolume // DWORD* out
);<DllImport("WINMM.dll", ExactSpelling:=True)>
Public Shared Function waveOutGetVolume(
hwo As IntPtr, ' HWAVEOUT optional
<Out> ByRef pdwVolume As UInteger ' DWORD* out
) As UInteger
End Function' hwo : HWAVEOUT optional
' pdwVolume : DWORD* out
Declare PtrSafe Function waveOutGetVolume Lib "winmm" ( _
ByVal hwo As LongPtr, _
ByRef pdwVolume As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
waveOutGetVolume = ctypes.windll.winmm.waveOutGetVolume
waveOutGetVolume.restype = wintypes.DWORD
waveOutGetVolume.argtypes = [
wintypes.HANDLE, # hwo : HWAVEOUT optional
ctypes.POINTER(wintypes.DWORD), # pdwVolume : DWORD* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WINMM.dll')
waveOutGetVolume = Fiddle::Function.new(
lib['waveOutGetVolume'],
[
Fiddle::TYPE_VOIDP, # hwo : HWAVEOUT optional
Fiddle::TYPE_VOIDP, # pdwVolume : DWORD* out
],
-Fiddle::TYPE_INT)#[link(name = "winmm")]
extern "system" {
fn waveOutGetVolume(
hwo: *mut core::ffi::c_void, // HWAVEOUT optional
pdwVolume: *mut u32 // DWORD* out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("WINMM.dll")]
public static extern uint waveOutGetVolume(IntPtr hwo, out uint pdwVolume);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WINMM_waveOutGetVolume' -Namespace Win32 -PassThru
# $api::waveOutGetVolume(hwo, pdwVolume)#uselib "WINMM.dll"
#func global waveOutGetVolume "waveOutGetVolume" sptr, sptr
; waveOutGetVolume hwo, varptr(pdwVolume) ; 戻り値は stat
; hwo : HWAVEOUT optional -> "sptr"
; pdwVolume : DWORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WINMM.dll" #cfunc global waveOutGetVolume "waveOutGetVolume" sptr, var ; res = waveOutGetVolume(hwo, pdwVolume) ; hwo : HWAVEOUT optional -> "sptr" ; pdwVolume : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "WINMM.dll" #cfunc global waveOutGetVolume "waveOutGetVolume" sptr, sptr ; res = waveOutGetVolume(hwo, varptr(pdwVolume)) ; hwo : HWAVEOUT optional -> "sptr" ; pdwVolume : DWORD* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; DWORD waveOutGetVolume(HWAVEOUT hwo, DWORD* pdwVolume) #uselib "WINMM.dll" #cfunc global waveOutGetVolume "waveOutGetVolume" intptr, var ; res = waveOutGetVolume(hwo, pdwVolume) ; hwo : HWAVEOUT optional -> "intptr" ; pdwVolume : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD waveOutGetVolume(HWAVEOUT hwo, DWORD* pdwVolume) #uselib "WINMM.dll" #cfunc global waveOutGetVolume "waveOutGetVolume" intptr, intptr ; res = waveOutGetVolume(hwo, varptr(pdwVolume)) ; hwo : HWAVEOUT optional -> "intptr" ; pdwVolume : DWORD* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
winmm = windows.NewLazySystemDLL("WINMM.dll")
procwaveOutGetVolume = winmm.NewProc("waveOutGetVolume")
)
// hwo (HWAVEOUT optional), pdwVolume (DWORD* out)
r1, _, err := procwaveOutGetVolume.Call(
uintptr(hwo),
uintptr(pdwVolume),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction waveOutGetVolume(
hwo: THandle; // HWAVEOUT optional
pdwVolume: Pointer // DWORD* out
): DWORD; stdcall;
external 'WINMM.dll' name 'waveOutGetVolume';result := DllCall("WINMM\waveOutGetVolume"
, "Ptr", hwo ; HWAVEOUT optional
, "Ptr", pdwVolume ; DWORD* out
, "UInt") ; return: DWORD●waveOutGetVolume(hwo, pdwVolume) = DLL("WINMM.dll", "dword waveOutGetVolume(void*, void*)")
# 呼び出し: waveOutGetVolume(hwo, pdwVolume)
# hwo : HWAVEOUT optional -> "void*"
# pdwVolume : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "winmm" fn waveOutGetVolume(
hwo: ?*anyopaque, // HWAVEOUT optional
pdwVolume: [*c]u32 // DWORD* out
) callconv(std.os.windows.WINAPI) u32;proc waveOutGetVolume(
hwo: pointer, # HWAVEOUT optional
pdwVolume: ptr uint32 # DWORD* out
): uint32 {.importc: "waveOutGetVolume", stdcall, dynlib: "WINMM.dll".}pragma(lib, "winmm");
extern(Windows)
uint waveOutGetVolume(
void* hwo, // HWAVEOUT optional
uint* pdwVolume // DWORD* out
);ccall((:waveOutGetVolume, "WINMM.dll"), stdcall, UInt32,
(Ptr{Cvoid}, Ptr{UInt32}),
hwo, pdwVolume)
# hwo : HWAVEOUT optional -> Ptr{Cvoid}
# pdwVolume : DWORD* out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t waveOutGetVolume(
void* hwo,
uint32_t* pdwVolume);
]]
local winmm = ffi.load("winmm")
-- winmm.waveOutGetVolume(hwo, pdwVolume)
-- hwo : HWAVEOUT optional
-- pdwVolume : DWORD* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('WINMM.dll');
const waveOutGetVolume = lib.func('__stdcall', 'waveOutGetVolume', 'uint32_t', ['void *', 'uint32_t *']);
// waveOutGetVolume(hwo, pdwVolume)
// hwo : HWAVEOUT optional -> 'void *'
// pdwVolume : DWORD* out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WINMM.dll", {
waveOutGetVolume: { parameters: ["pointer", "pointer"], result: "u32" },
});
// lib.symbols.waveOutGetVolume(hwo, pdwVolume)
// hwo : HWAVEOUT optional -> "pointer"
// pdwVolume : DWORD* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t waveOutGetVolume(
void* hwo,
uint32_t* pdwVolume);
C, "WINMM.dll");
// $ffi->waveOutGetVolume(hwo, pdwVolume);
// hwo : HWAVEOUT optional
// pdwVolume : 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 Winmm extends StdCallLibrary {
Winmm INSTANCE = Native.load("winmm", Winmm.class);
int waveOutGetVolume(
Pointer hwo, // HWAVEOUT optional
IntByReference pdwVolume // DWORD* out
);
}@[Link("winmm")]
lib LibWINMM
fun waveOutGetVolume = waveOutGetVolume(
hwo : Void*, # HWAVEOUT optional
pdwVolume : UInt32* # DWORD* out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef waveOutGetVolumeNative = Uint32 Function(Pointer<Void>, Pointer<Uint32>);
typedef waveOutGetVolumeDart = int Function(Pointer<Void>, Pointer<Uint32>);
final waveOutGetVolume = DynamicLibrary.open('WINMM.dll')
.lookupFunction<waveOutGetVolumeNative, waveOutGetVolumeDart>('waveOutGetVolume');
// hwo : HWAVEOUT optional -> Pointer<Void>
// pdwVolume : DWORD* out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function waveOutGetVolume(
hwo: THandle; // HWAVEOUT optional
pdwVolume: Pointer // DWORD* out
): DWORD; stdcall;
external 'WINMM.dll' name 'waveOutGetVolume';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "waveOutGetVolume"
c_waveOutGetVolume :: Ptr () -> Ptr Word32 -> IO Word32
-- hwo : HWAVEOUT optional -> Ptr ()
-- pdwVolume : DWORD* out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let waveoutgetvolume =
foreign "waveOutGetVolume"
((ptr void) @-> (ptr uint32_t) @-> returning uint32_t)
(* hwo : HWAVEOUT optional -> (ptr void) *)
(* pdwVolume : DWORD* out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library winmm (t "WINMM.dll"))
(cffi:use-foreign-library winmm)
(cffi:defcfun ("waveOutGetVolume" wave-out-get-volume :convention :stdcall) :uint32
(hwo :pointer) ; HWAVEOUT optional
(pdw-volume :pointer)) ; DWORD* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $waveOutGetVolume = Win32::API::More->new('WINMM',
'DWORD waveOutGetVolume(HANDLE hwo, LPVOID pdwVolume)');
# my $ret = $waveOutGetVolume->Call($hwo, $pdwVolume);
# hwo : HWAVEOUT optional -> HANDLE
# pdwVolume : DWORD* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。