ホーム › Media.Audio › sndPlaySoundW
sndPlaySoundW
関数指定したWAVEサウンドを再生する(Unicode版)。
シグネチャ
// WINMM.dll (Unicode / -W)
#include <windows.h>
BOOL sndPlaySoundW(
LPCWSTR pszSound, // optional
DWORD fuSound
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pszSound | LPCWSTR | inoptional |
| fuSound | DWORD | in |
戻り値の型: BOOL
各言語での呼び出し定義
// WINMM.dll (Unicode / -W)
#include <windows.h>
BOOL sndPlaySoundW(
LPCWSTR pszSound, // optional
DWORD fuSound
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WINMM.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool sndPlaySoundW(
[MarshalAs(UnmanagedType.LPWStr)] string pszSound, // LPCWSTR optional
uint fuSound // DWORD
);<DllImport("WINMM.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function sndPlaySoundW(
<MarshalAs(UnmanagedType.LPWStr)> pszSound As String, ' LPCWSTR optional
fuSound As UInteger ' DWORD
) As Boolean
End Function' pszSound : LPCWSTR optional
' fuSound : DWORD
Declare PtrSafe Function sndPlaySoundW Lib "winmm" ( _
ByVal pszSound As LongPtr, _
ByVal fuSound As Long) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
sndPlaySoundW = ctypes.windll.winmm.sndPlaySoundW
sndPlaySoundW.restype = wintypes.BOOL
sndPlaySoundW.argtypes = [
wintypes.LPCWSTR, # pszSound : LPCWSTR optional
wintypes.DWORD, # fuSound : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WINMM.dll')
sndPlaySoundW = Fiddle::Function.new(
lib['sndPlaySoundW'],
[
Fiddle::TYPE_VOIDP, # pszSound : LPCWSTR optional
-Fiddle::TYPE_INT, # fuSound : DWORD
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "winmm")]
extern "system" {
fn sndPlaySoundW(
pszSound: *const u16, // LPCWSTR optional
fuSound: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WINMM.dll", CharSet = CharSet.Unicode)]
public static extern bool sndPlaySoundW([MarshalAs(UnmanagedType.LPWStr)] string pszSound, uint fuSound);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WINMM_sndPlaySoundW' -Namespace Win32 -PassThru
# $api::sndPlaySoundW(pszSound, fuSound)#uselib "WINMM.dll"
#func global sndPlaySoundW "sndPlaySoundW" wptr, wptr
; sndPlaySoundW pszSound, fuSound ; 戻り値は stat
; pszSound : LPCWSTR optional -> "wptr"
; fuSound : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WINMM.dll"
#cfunc global sndPlaySoundW "sndPlaySoundW" wstr, int
; res = sndPlaySoundW(pszSound, fuSound)
; pszSound : LPCWSTR optional -> "wstr"
; fuSound : DWORD -> "int"; BOOL sndPlaySoundW(LPCWSTR pszSound, DWORD fuSound)
#uselib "WINMM.dll"
#cfunc global sndPlaySoundW "sndPlaySoundW" wstr, int
; res = sndPlaySoundW(pszSound, fuSound)
; pszSound : LPCWSTR optional -> "wstr"
; fuSound : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
winmm = windows.NewLazySystemDLL("WINMM.dll")
procsndPlaySoundW = winmm.NewProc("sndPlaySoundW")
)
// pszSound (LPCWSTR optional), fuSound (DWORD)
r1, _, err := procsndPlaySoundW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszSound))),
uintptr(fuSound),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction sndPlaySoundW(
pszSound: PWideChar; // LPCWSTR optional
fuSound: DWORD // DWORD
): BOOL; stdcall;
external 'WINMM.dll' name 'sndPlaySoundW';result := DllCall("WINMM\sndPlaySoundW"
, "WStr", pszSound ; LPCWSTR optional
, "UInt", fuSound ; DWORD
, "Int") ; return: BOOL●sndPlaySoundW(pszSound, fuSound) = DLL("WINMM.dll", "bool sndPlaySoundW(char*, dword)")
# 呼び出し: sndPlaySoundW(pszSound, fuSound)
# pszSound : LPCWSTR optional -> "char*"
# fuSound : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。