Guest User

Untitled

a guest
Jun 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. #include <string>
  2. #include <iostream>
  3. #include <Windows.h>
  4.  
  5. #pragma comment(lib, "winmm.lib")
  6.  
  7. struct WAVHeader
  8. {
  9. int8_t chunkId[4];
  10. int32_t chunkSize;
  11. int8_t format[4];
  12.  
  13. int8_t subchunk1Id[4];
  14. int32_t subchunk1Size;
  15. int16_t audioFormat;
  16. int16_t numOfChan;
  17. int32_t sampleRate;
  18. int32_t byteRate;
  19. int16_t blockAlign;
  20. int16_t bitsPerSample;
  21.  
  22. int8_t subchunk2Id[4];
  23. int32_t subchunk2Size;
  24. };
  25.  
  26.  
  27. int wmain(int argc, wchar_t* argv[])
  28. {
  29. if (argc != 2)
  30. {
  31. MessageBoxA(nullptr, "Error: no arguments specified!", nullptr, MB_ICONERROR);
  32. return 1;
  33. }
  34.  
  35. HANDLE hFile = CreateFileW(argv[1], GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
  36.  
  37. if (hFile == INVALID_HANDLE_VALUE)
  38. {
  39. MessageBoxA(nullptr, "Error: could not open file!", nullptr, MB_ICONERROR);
  40. return 1;
  41. }
  42.  
  43. WAVHeader header;
  44.  
  45. DWORD bytesRead;
  46. if (!ReadFile(hFile, &header, sizeof(header), &bytesRead, nullptr))
  47. {
  48. MessageBoxA(nullptr, "Error: could not read from file!", nullptr, MB_ICONERROR);
  49. return 1;
  50. }
  51.  
  52. CloseHandle(hFile);
  53.  
  54. using std::string;
  55.  
  56. std::cout << "Id: " << string(header.chunkId, std::end(header.chunkId)) << '\n'
  57. << "Size: " << header.chunkSize << '\n'
  58. << "Format: " << string(header.format, std::end(header.format)) << '\n';
  59.  
  60.  
  61. if (!PlaySoundW(argv[1], nullptr, SND_FILENAME))
  62. {
  63. MessageBoxA(nullptr, "Error: could not play file, Only supports WAV format!", nullptr, MB_ICONERROR);
  64. return 1;
  65. }
  66.  
  67. return 0;
  68. }
Add Comment
Please, Sign In to add comment