0

Is there any way to add music to exe(c++)file without additional wave file?

For example, If I use "PlaySound" to play wav file, the wave file should be located under same folder where the exe file be. But I want to run it without wav file so that when someone receives the exe file, they can listen to the music without receiving the wav file..

I want it as a code...

And here's my current code.

#include <iostream>
#include <stdio.h>
#include <windows.h>
using namespace std;


/* ========================================================================== */
enum {
    BLACK,
    DARK_BLUE,
    DARK_GREEN,
    DARK_SKY_BLUE,
    DARK_RED,
    DARK_VOILET,
    DARK_YELLOW,
    GRAY,
    DARK_GRAY,
    BLUE,
    GREEN,
    SKY_BLUE,
    RED,
    VIOLET,
    YELLOW,
    WHITE,
};

enum { HIDDEN, SHOW };

void CursorView(char show)
{
    HANDLE hConsole;
    CONSOLE_CURSOR_INFO ConsoleCursor;

    hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

    ConsoleCursor.bVisible = show;
    ConsoleCursor.dwSize = 1;

    SetConsoleCursorInfo(hConsole, &ConsoleCursor);
}

void gotoxy(int x, int y)
{
    COORD XY = { x, y };
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), XY);
}
void SetColor(int color)
{
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
}

void gamedraw(void)
{
        PlaySound(TEXT("10.wav"), NULL, SND_FILENAME | SND_LOOP | SND_ASYNC);

        printf("You are listening to my song.");

  getchar();
}
void MainInit(void)
{
   system("mode con: cols=100 lines=45");
   system("cls");
}

/* ========================================================================== */

int main(void)
{
   CursorView(HIDDEN);
   MainInit();

   gamedraw();

   for (;;) {

      if (GetAsyncKeyState(VK_ESCAPE) < 0)  break;
   }

   CursorView(SHOW);

   return 0;
}
François Andrieux
  • 28,148
  • 6
  • 56
  • 87
cozyddd
  • 11
  • 1
  • For reference : [PlaySound](https://msdn.microsoft.com/en-us/library/windows/desktop/dd743680(v=vs.85).aspx). – François Andrieux Dec 08 '17 at 20:07
  • I know how to use the "PlaySound".... but what I want to ask is... how to combine exe file and wav file into 1 exe file... so that I can run console and the wav file at the same time without additional window like windowmediaplayer. Just console. – cozyddd Dec 08 '17 at 20:15
  • The reference is for anyone who may be trying to help you. It's neither a commonly used function, nor a standard function. – François Andrieux Dec 08 '17 at 20:17
  • Possible duplicate of https://stackoverflow.com/questions/20541707/add-resources-sound-files-to-exe-ms-visual-studio-2012 – François Andrieux Dec 08 '17 at 20:18
  • I can't find the way to do it in reference so far.... – cozyddd Dec 08 '17 at 20:18
  • oh... I got it now... thank you. – cozyddd Dec 08 '17 at 20:21
  • Possible duplicate of [PlaySound works in Visual Studio but not in standalone exe](https://stackoverflow.com/questions/36424691/playsound-works-in-visual-studio-but-not-in-standalone-exe) – zett42 Dec 08 '17 at 20:56

1 Answers1

-2

You can add the .wav as a resource but then playing it becomes quite a lot more difficult (either you'll have to extract the resource to some path on disk or use one of the audio APIs to submit the wav data).

SoronelHaetir
  • 14,104
  • 1
  • 12
  • 23
  • 2
    `PlaySound()` can play a WAV resource, no need to extract it to a temp file first, or pump the data manually. See [Playing WAVE Resources](https://msdn.microsoft.com/en-us/library/dd743679.aspx) on MSDN. – Remy Lebeau Dec 08 '17 at 20:28