Win32 API 日本語リファレンス
ホームSystem.Diagnostics.Debug › Beep

Beep

関数
指定した周波数と長さでスピーカーからビープ音を鳴らす。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// KERNEL32.dll
#include <windows.h>

BOOL Beep(
    DWORD dwFreq,
    DWORD dwDuration
);

パラメーター

名前方向
dwFreqDWORDin
dwDurationDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

// KERNEL32.dll
#include <windows.h>

BOOL Beep(
    DWORD dwFreq,
    DWORD dwDuration
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool Beep(
    uint dwFreq,   // DWORD
    uint dwDuration   // DWORD
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function Beep(
    dwFreq As UInteger,   ' DWORD
    dwDuration As UInteger   ' DWORD
) As Boolean
End Function
' dwFreq : DWORD
' dwDuration : DWORD
Declare PtrSafe Function Beep Lib "kernel32" ( _
    ByVal dwFreq As Long, _
    ByVal dwDuration As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

Beep = ctypes.windll.kernel32.Beep
Beep.restype = wintypes.BOOL
Beep.argtypes = [
    wintypes.DWORD,  # dwFreq : DWORD
    wintypes.DWORD,  # dwDuration : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
Beep = Fiddle::Function.new(
  lib['Beep'],
  [
    -Fiddle::TYPE_INT,  # dwFreq : DWORD
    -Fiddle::TYPE_INT,  # dwDuration : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn Beep(
        dwFreq: u32,  // DWORD
        dwDuration: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern bool Beep(uint dwFreq, uint dwDuration);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_Beep' -Namespace Win32 -PassThru
# $api::Beep(dwFreq, dwDuration)
#uselib "KERNEL32.dll"
#func global Beep "Beep" sptr, sptr
; Beep dwFreq, dwDuration   ; 戻り値は stat
; dwFreq : DWORD -> "sptr"
; dwDuration : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global Beep "Beep" int, int
; res = Beep(dwFreq, dwDuration)
; dwFreq : DWORD -> "int"
; dwDuration : DWORD -> "int"
; BOOL Beep(DWORD dwFreq, DWORD dwDuration)
#uselib "KERNEL32.dll"
#cfunc global Beep "Beep" int, int
; res = Beep(dwFreq, dwDuration)
; dwFreq : DWORD -> "int"
; dwDuration : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procBeep = kernel32.NewProc("Beep")
)

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