Start New Discussion within our Software Development Community

i don't know how can i start or what classes i need in this project (wav player)
with functions (play,stop,pause,record,mute)
thanks in advanced

From Windows.h

#pragma comment(lib, "winmm")
#include <iostream>
#include <limits>
#include <string>
#include <windows.h>

void play_wave_resource( std::string resname, bool is_loop ) {
  HANDLE hfound, hsound;
  LPVOID data;

  hfound = FindResource( NULL, resname.c_str(), "WAVE" );
  if (hfound != 0) {

    hsound = LoadResource( NULL, (HRSRC)hfound );
    if (hsound != 0) {
      data = LockResource( hsound );

      if (data != NULL) sndPlaySound(
        (char *)data,
        SND_ASYNC | SND_MEMORY | (is_loop ? SND_LOOP : 0)

      UnlockResource( hsound );

  FreeResource( hfound );

void stop_wave_sound() {
  sndPlaySound( NULL, 0 );

int main() {
  using namespace std;

  play_wave_resource( "one", true );

  cout << "Press ENTER";
  cin.ignore( numeric_limits<streamsize>::max(), '\n' );


  return EXIT_SUCCESS;

one WAVE "c:\\WINDOWS\\Media\\notify.wav"

wave: res.o
	g++ -o wave res.o -lwinmm

res.o: res.rc
	windres -o res.o res.rc

Search google.. there are tons of examples..

One way that I've done it before was to use a resource and just access the resource OR extract it then play it.. when its done playing you can delete it.. I prefer to extract since for me its easier.. but you can easily just aswell play it directly from the resource.

This article has been dead for over six months. Start a new discussion instead.