Last active
December 4, 2023 03:43
-
-
Save nir9/dd09bcb8b47874d5b719fef24f05eecd to your computer and use it in GitHub Desktop.
Beep with a ioctl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <cstdint> | |
#include <Windows.h> | |
struct Beep | |
{ | |
uint32_t freq; | |
uint32_t duration; | |
}; | |
void main() | |
{ | |
HANDLE handle = CreateFileA("\\\\.\\GLOBALROOT\\Device\\Beep", GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); | |
ULONG code = 0x10000; | |
for (int i = 0;;i+=10) | |
{ | |
struct Beep input = {}; | |
input.freq = 2000+i; | |
input.duration = 50; | |
DeviceIoControl(handle, code, &input, sizeof(input), nullptr, 0, nullptr, nullptr); | |
Sleep(100); | |
} | |
CloseHandle(handle); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment