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

sndPlaySoundA

関数
指定したWAVEサウンドを再生する(ANSI版)。
DLLWINMM.dll文字セットANSI (-A)呼出規約winapi

シグネチャ

// WINMM.dll  (ANSI / -A)
#include <windows.h>

BOOL sndPlaySoundA(
    LPCSTR pszSound,   // optional
    DWORD fuSound
);

パラメーター

名前方向
pszSoundLPCSTRinoptional
fuSoundDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

// WINMM.dll  (ANSI / -A)
#include <windows.h>

BOOL sndPlaySoundA(
    LPCSTR pszSound,   // optional
    DWORD fuSound
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WINMM.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern bool sndPlaySoundA(
    [MarshalAs(UnmanagedType.LPStr)] string pszSound,   // LPCSTR optional
    uint fuSound   // DWORD
);
<DllImport("WINMM.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function sndPlaySoundA(
    <MarshalAs(UnmanagedType.LPStr)> pszSound As String,   ' LPCSTR optional
    fuSound As UInteger   ' DWORD
) As Boolean
End Function
' pszSound : LPCSTR optional
' fuSound : DWORD
Declare PtrSafe Function sndPlaySoundA Lib "winmm" ( _
    ByVal pszSound As String, _
    ByVal fuSound As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

sndPlaySoundA = ctypes.windll.winmm.sndPlaySoundA
sndPlaySoundA.restype = wintypes.BOOL
sndPlaySoundA.argtypes = [
    wintypes.LPCSTR,  # pszSound : LPCSTR optional
    wintypes.DWORD,  # fuSound : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WINMM.dll')
sndPlaySoundA = Fiddle::Function.new(
  lib['sndPlaySoundA'],
  [
    Fiddle::TYPE_VOIDP,  # pszSound : LPCSTR optional
    -Fiddle::TYPE_INT,  # fuSound : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "winmm")]
extern "system" {
    fn sndPlaySoundA(
        pszSound: *const u8,  // LPCSTR 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.Ansi)]
public static extern bool sndPlaySoundA([MarshalAs(UnmanagedType.LPStr)] string pszSound, uint fuSound);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WINMM_sndPlaySoundA' -Namespace Win32 -PassThru
# $api::sndPlaySoundA(pszSound, fuSound)
#uselib "WINMM.dll"
#func global sndPlaySoundA "sndPlaySoundA" sptr, sptr
; sndPlaySoundA pszSound, fuSound   ; 戻り値は stat
; pszSound : LPCSTR optional -> "sptr"
; fuSound : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "WINMM.dll"
#cfunc global sndPlaySoundA "sndPlaySoundA" str, int
; res = sndPlaySoundA(pszSound, fuSound)
; pszSound : LPCSTR optional -> "str"
; fuSound : DWORD -> "int"
; BOOL sndPlaySoundA(LPCSTR pszSound, DWORD fuSound)
#uselib "WINMM.dll"
#cfunc global sndPlaySoundA "sndPlaySoundA" str, int
; res = sndPlaySoundA(pszSound, fuSound)
; pszSound : LPCSTR optional -> "str"
; fuSound : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	winmm = windows.NewLazySystemDLL("WINMM.dll")
	procsndPlaySoundA = winmm.NewProc("sndPlaySoundA")
)

// pszSound (LPCSTR optional), fuSound (DWORD)
r1, _, err := procsndPlaySoundA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(pszSound))),
	uintptr(fuSound),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function sndPlaySoundA(
  pszSound: PAnsiChar;   // LPCSTR optional
  fuSound: DWORD   // DWORD
): BOOL; stdcall;
  external 'WINMM.dll' name 'sndPlaySoundA';
result := DllCall("WINMM\sndPlaySoundA"
    , "AStr", pszSound   ; LPCSTR optional
    , "UInt", fuSound   ; DWORD
    , "Int")   ; return: BOOL
●sndPlaySoundA(pszSound, fuSound) = DLL("WINMM.dll", "bool sndPlaySoundA(char*, dword)")
# 呼び出し: sndPlaySoundA(pszSound, fuSound)
# pszSound : LPCSTR optional -> "char*"
# fuSound : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。