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