Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <iostream>
- #include <Windows.h>
- #pragma comment(lib, "winmm.lib")
- struct WAVHeader
- {
- int8_t chunkId[4];
- int32_t chunkSize;
- int8_t format[4];
- int8_t subchunk1Id[4];
- int32_t subchunk1Size;
- int16_t audioFormat;
- int16_t numOfChan;
- int32_t sampleRate;
- int32_t byteRate;
- int16_t blockAlign;
- int16_t bitsPerSample;
- int8_t subchunk2Id[4];
- int32_t subchunk2Size;
- };
- int wmain(int argc, wchar_t* argv[])
- {
- if (argc != 2)
- {
- MessageBoxA(nullptr, "Error: no arguments specified!", nullptr, MB_ICONERROR);
- return 1;
- }
- HANDLE hFile = CreateFileW(argv[1], GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
- if (hFile == INVALID_HANDLE_VALUE)
- {
- MessageBoxA(nullptr, "Error: could not open file!", nullptr, MB_ICONERROR);
- return 1;
- }
- WAVHeader header;
- DWORD bytesRead;
- if (!ReadFile(hFile, &header, sizeof(header), &bytesRead, nullptr))
- {
- MessageBoxA(nullptr, "Error: could not read from file!", nullptr, MB_ICONERROR);
- return 1;
- }
- CloseHandle(hFile);
- using std::string;
- std::cout << "Id: " << string(header.chunkId, std::end(header.chunkId)) << '\n'
- << "Size: " << header.chunkSize << '\n'
- << "Format: " << string(header.format, std::end(header.format)) << '\n';
- if (!PlaySoundW(argv[1], nullptr, SND_FILENAME))
- {
- MessageBoxA(nullptr, "Error: could not play file, Only supports WAV format!", nullptr, MB_ICONERROR);
- return 1;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment