ホーム › Media.Audio › sndPlaySoundA
sndPlaySoundA
関数指定したWAVEサウンドを再生する(ANSI版)。
シグネチャ
// WINMM.dll (ANSI / -A)
#include <windows.h>
BOOL sndPlaySoundA(
LPCSTR pszSound, // optional
DWORD fuSound
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pszSound | LPCSTR | inoptional | 再生する波形音の名前またはWAVファイル名(ANSI)。NULLで再生停止。 |
| fuSound | DWORD | in | 再生方法を指定するフラグ(SND_ASYNC、SND_LOOP等)。 |
戻り値の型: 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 <MarshalAs(UnmanagedType.Bool)> 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 // BOOLfunction 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)。const std = @import("std");
extern "winmm" fn sndPlaySoundA(
pszSound: [*c]const u8, // LPCSTR optional
fuSound: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc sndPlaySoundA(
pszSound: cstring, # LPCSTR optional
fuSound: uint32 # DWORD
): int32 {.importc: "sndPlaySoundA", stdcall, dynlib: "WINMM.dll".}pragma(lib, "winmm");
extern(Windows)
int sndPlaySoundA(
const(char)* pszSound, // LPCSTR optional
uint fuSound // DWORD
);ccall((:sndPlaySoundA, "WINMM.dll"), stdcall, Int32,
(Cstring, UInt32),
pszSound, fuSound)
# pszSound : LPCSTR optional -> Cstring
# fuSound : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t sndPlaySoundA(
const char* pszSound,
uint32_t fuSound);
]]
local winmm = ffi.load("winmm")
-- winmm.sndPlaySoundA(pszSound, fuSound)
-- pszSound : LPCSTR optional
-- fuSound : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('WINMM.dll');
const sndPlaySoundA = lib.func('__stdcall', 'sndPlaySoundA', 'int32_t', ['str', 'uint32_t']);
// sndPlaySoundA(pszSound, fuSound)
// pszSound : LPCSTR optional -> 'str'
// fuSound : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WINMM.dll", {
sndPlaySoundA: { parameters: ["buffer", "u32"], result: "i32" },
});
// lib.symbols.sndPlaySoundA(pszSound, fuSound)
// pszSound : LPCSTR optional -> "buffer"
// fuSound : DWORD -> "u32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t sndPlaySoundA(
const char* pszSound,
uint32_t fuSound);
C, "WINMM.dll");
// $ffi->sndPlaySoundA(pszSound, fuSound);
// pszSound : LPCSTR optional
// fuSound : DWORD
// 構造体/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, W32APIOptions.ASCII_OPTIONS);
boolean sndPlaySoundA(
String pszSound, // LPCSTR optional
int fuSound // DWORD
);
}@[Link("winmm")]
lib LibWINMM
fun sndPlaySoundA = sndPlaySoundA(
pszSound : UInt8*, # LPCSTR optional
fuSound : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef sndPlaySoundANative = Int32 Function(Pointer<Utf8>, Uint32);
typedef sndPlaySoundADart = int Function(Pointer<Utf8>, int);
final sndPlaySoundA = DynamicLibrary.open('WINMM.dll')
.lookupFunction<sndPlaySoundANative, sndPlaySoundADart>('sndPlaySoundA');
// pszSound : LPCSTR optional -> Pointer<Utf8>
// fuSound : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function sndPlaySoundA(
pszSound: PAnsiChar; // LPCSTR optional
fuSound: DWORD // DWORD
): BOOL; stdcall;
external 'WINMM.dll' name 'sndPlaySoundA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "sndPlaySoundA"
c_sndPlaySoundA :: CString -> Word32 -> IO CInt
-- pszSound : LPCSTR optional -> CString
-- fuSound : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let sndplaysounda =
foreign "sndPlaySoundA"
(string @-> uint32_t @-> returning int32_t)
(* pszSound : LPCSTR optional -> string *)
(* fuSound : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library winmm (t "WINMM.dll"))
(cffi:use-foreign-library winmm)
(cffi:defcfun ("sndPlaySoundA" snd-play-sound-a :convention :stdcall) :int32
(psz-sound :string) ; LPCSTR optional
(fu-sound :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $sndPlaySoundA = Win32::API::More->new('WINMM',
'BOOL sndPlaySoundA(LPCSTR pszSound, DWORD fuSound)');
# my $ret = $sndPlaySoundA->Call($pszSound, $fuSound);
# pszSound : LPCSTR optional -> LPCSTR
# fuSound : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f sndPlaySoundW (Unicode版) — 指定したWAVEサウンドを再生する(Unicode版)。