0
0

Hello,

I have got a problem, I can get my song stop with the function FMUSIC_StopSong. I use the MEMLOADRESOURCE method.

I manage to load my music from the resource exe file and I also manage to play it but I can’t stop it :(
In fact, the music continue during 2 seconds and loop 😮
I can send my code to anybody who asks for it.

I hope you could help me.

Here is my code:

[u:2wj6gwnu][size=150:2wj6gwnu]Main.cpp:[/size:2wj6gwnu][/u:2wj6gwnu]

include <windows.h>

include <stdio.h>

include “playXm_dlg.h”

// prototype for the dialog box function
static BOOL CALLBACK DialogFunc(HWND, UINT, WPARAM, LPARAM);

// Globals variables
HINSTANCE g_hInst;
char s[255];
HWND g_hDlg;

/*****************************/
/********** minifmod **********/
/*****************************/

include “minifmod.h”

//#define USEMEMLOAD

define USEMEMLOADRESOURCE

//#define USESAMPLELOADCALLBACK
//#define USEFMOD

FMUSIC_MODULE *mod;

typedef struct
{
int length;
int pos;
void *data;
}
MEMFILE;

unsigned int memopen(char *name)
{
MEMFILE *memfile;
memfile = (MEMFILE *)calloc(sizeof(MEMFILE),1);

HRSRC rec;
HGLOBAL handle;

rec = FindResource(NULL, name, RT_RCDATA);
handle = LoadResource(NULL, rec);

memfile->data = LockResource(handle);
memfile->length = SizeofResource(NULL, rec);
memfile->pos = 0;

return((unsigned int)memfile);
}

void memclose(unsigned int handle)
{
MEMFILE *memfile = (MEMFILE *)handle;

ifndef USEMEMLOADRESOURCE

free(memfile->data); // dont free it if it was initialized with LockResource

endif

free(memfile);
}

int memread(void *buffer, int size, unsigned int handle)
{
MEMFILE *memfile = (MEMFILE *)handle;

if (memfile->pos + size >= memfile->length)
size = memfile->length – memfile->pos;

memcpy(buffer, (char *)memfile->data+memfile->pos, size);
memfile->pos += size;

return(size);
}

void memseek(unsigned int handle, int pos, signed char mode)
{
MEMFILE *memfile = (MEMFILE *)handle;

if (mode == SEEK_SET)
memfile->pos = pos;
else if (mode == SEEK_CUR)
memfile->pos += pos;
else if (mode == SEEK_END)
memfile->pos = memfile->length + pos;

if (memfile->pos > memfile->length)
memfile->pos = memfile->length;
}

int memtell(unsigned int handle)
{
MEMFILE *memfile = (MEMFILE *)handle;
return(memfile->pos);
}

/*********************************/
/********** Main program **********/
/********************************/

// Main function
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{
g_hInst = hThisInstance;
DialogBoxParam(hThisInstance, MAKEINTRESOURCE(IDD_DLG_MAIN), NULL, (DLGPROC) DialogFunc, 0);
ExitProcess(0);
}

// Initialize the main dialog box
int InitializeApp(HWND hDlg,WPARAM wParam, LPARAM lParam)
{
g_hDlg = hDlg;

// Load and play music
FSOUND_File_SetCallbacks(memopen, memclose, memread, memseek, memtell);

// Initialize
if (!FSOUND_Init(44100, 0))
{
MessageBox(0, “Error upon initialization.”, “Error”, 0);
return(FALSE);
}

mod = FMUSIC_LoadSong(MAKEINTRESOURCE(XM_FILE), NULL);

if (!mod)
{
FSOUND_Close();
MessageBox(0, “Error loading song”, “Error”, 0);
return(FALSE);
}

return TRUE;
}

// Callback function for the main dialog box
BOOL CALLBACK DialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
int fm = -1;
switch (msg) {
case WM_INITDIALOG:
InitializeApp(hwndDlg,wParam,lParam);
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam)) {

  case IDC_BTN_PLAY:
    // Play song
    fm = FMUSIC_PlaySong(mod);

wsprintf(s, “FMUSIC_PlaySong: %d”, fm);MessageBox(0,s, “”, 0);
return TRUE;

  case IDC_BTN_STOP:
    fm = FMUSIC_StopSong(mod);

wsprintf(s, “FMUSIC_StopSong: %d”, fm);MessageBox(0,s, “”, 0);
return TRUE;

    return TRUE;
}
break;

case WM_CLOSE:
// Libère les ressources
if (!mod)
FSOUND_Close();

EndDialog(hwndDlg, FALSE);
return TRUE;

case WM_DESTROY:
return TRUE;
}
return FALSE;
}

[u:2wj6gwnu][size=150:2wj6gwnu]playXm_dlg.h :[/size:2wj6gwnu][/u:2wj6gwnu]

define RCDATA 10

define IDD_DLG_MAIN 1000

define IDC_BTN_PLAY 1001

define IDC_BTN_STOP 1002

define XM_FILE 10000

[u:2wj6gwnu][size=150:2wj6gwnu]playXm_dlg.rc:[/size:2wj6gwnu][/u:2wj6gwnu]

define RCDATA 10

define IDD_DLG_MAIN 1000

define IDC_BTN_PLAY 1001

define IDC_BTN_STOP 1002

define XM_FILE 10000

IDD_DLG_MAIN DIALOGEX 6,5,152,44
CAPTION “XmPlayer”
FONT 8,”MS Sans Serif”
STYLE 0x10CA0800
EXSTYLE 0x00000000
BEGIN
CONTROL “&PLAY”,IDC_BTN_PLAY,”Button”,0x50018000,6,16,66,13,0×00000000
CONTROL “&STOP”,IDC_BTN_STOP,”Button”,0x50018000,82,16,56,13,0×00000000
END
XM_FILE RCDATA DISCARDABLE “xm/music.xm”

[u:2wj6gwnu][size=150:2wj6gwnu]minifmod.h :[/size:2wj6gwnu][/u:2wj6gwnu]

It comes from the package of minifmod 1.60 (GCC package)

[u:2wj6gwnu][size=150:2wj6gwnu]makefile.win :[/size:2wj6gwnu][/u:2wj6gwnu]

Project: playXm

Makefile created by Dev-C++ 4.9.9.2

CPP = g++.exe
CC = gcc.exe
WINDRES = windres.exe
RES = playXm_private.res
OBJ = main.o $(RES)
LINKOBJ = main.o $(RES)
LIBS = -L”lib” -mwindows lib/libminifmod.a lib/libwinmm.a
INCS = -I”include”
CXXINCS = -I”lib/gcc/mingw32/3.4.2/include” -I”include/c++/3.4.2/backward” -I”include/c++/3.4.2/mingw32″ -I”include/c++/3.4.2″ -I”include”
BIN = playXm.exe
CXXFLAGS = $(CXXINCS) -fexpensive-optimizations -O3
CFLAGS = $(INCS) -fexpensive-optimizations -O3
RM = rm -f

.PHONY: all all-before all-after clean clean-custom

all: all-before playXm.exe all-after

clean: clean-custom
${RM} $(OBJ) $(BIN)

$(BIN): $(OBJ)
$(CPP) $(LINKOBJ) -o “playXm.exe” $(LIBS)

main.o: main.cpp
$(CPP) -c main.cpp -o main.o $(CXXFLAGS)

playXm_private.res: playXm_private.rc playXm_dlg.rc
$(WINDRES) -i playXm_private.rc –input-format=rc -o playXm_private.res -O coff

/*********************************/

My configuration is:
Windows 2000 Pro sp4
IDE: Dev-CPP 4.9.9.2
Resource editor: ResEd

Please let me know if you need more details.

Thanks a lot and have a nice day.

  • You must to post comments
0
0

Hello Brett,

Thanks for your answer.

It is written in file File_id.diz: MINIFMOD 1.7 XM Player Windows 95/98/NT. VC++5/6 ONLY.

When I try to use the file minifmod.lib from minifmod170.zip I have the following errors in my project:

Compiler: Default compiler
Building Makefile: “D:\playXm2\Makefile.win”
Executing make…
make.exe -f “D:\playXm2\Makefile.win” all
windres.exe -i playXm_private.rc –input-format=rc -o playXm_private.res -O coff

g++.exe main.o playXm_private.res -o “playXm.exe” -L”lib” -mwindows lib/minifmod.lib lib/libwinmm.a

Warning: .drectve /DEFAULTLIB:"uuid.lib" /DEFAULTLIB:"uuid.lib" /DEFAULTLIB:"MSVCRT" /DEFAULTLIB:"OLDNAMES" ' unrecognized
Warning: .drectve
/DEFAULTLIB:”uuid.lib” /DEFAULTLIB:”uuid.lib” /DEFAULTLIB:”MSVCRT” /DEFAULTLIB:”OLDNAMES” ‘ unrecognized
Warning: .drectve /DEFAULTLIB:"uuid.lib" /DEFAULTLIB:"uuid.lib" /DEFAULTLIB:"MSVCRT" /DEFAULTLIB:"OLDNAMES" ' unrecognized
Warning: .drectve
/DEFAULTLIB:”uuid.lib” /DEFAULTLIB:”uuid.lib” /DEFAULTLIB:”MSVCRT” /DEFAULTLIB:”OLDNAMES” ‘ unrecognized
Warning: .drectve /DEFAULTLIB:"uuid.lib" /DEFAULTLIB:"uuid.lib" /DEFAULTLIB:"MSVCRT" /DEFAULTLIB:"OLDNAMES" ' unrecognized
Warning: .drectve
/DEFAULTLIB:”uuid.lib” /DEFAULTLIB:”uuid.lib” /DEFAULTLIB:”MSVCRT” /DEFAULTLIB:”OLDNAMES” ‘ unrecognized
main.o(.text+0x194):main.cpp: undefined reference to FSOUND_Init'
main.o(.text+0x228):main.cpp: undefined reference to
FSOUND_Close’
main.o(.text+0x277):main.cpp: undefined reference to FSOUND_Close'
main.o(.text+0x389):main.cpp: undefined reference to
FSOUND_Close’
main.o(.text+0x399):main.cpp: undefined reference to `FSOUND_Close’
collect2: ld returned 1 exit status

make.exe: *** [playXm.exe] Error 1

Execution terminated

I am using Dev-C++ 4.9.9.2 so I use gcc compiler. Is it possible to use the minifmod.lib v1.7 with gcc?
Do I have to recompile the librairy from source file with gcc in order to make it works?

Thanks and have a nice day.

  • You must to post comments
0
0

No, you can’t use minifmod 1.7 with gcc, this is why the 1.6 is still in the download page :)
What you can do is to take files (the source engine) from the 1.7 and use them in your app (this is exactly what allready Andrew said).

  • You must to post comments
0
0

Hi KarLKoX,

I’m not sure to understand what I have to do because I am a newbie 😳
The bug I have uncounter is locate in the source file or in the library?
If the bug is in the source file I can compare gcc and Visual C++ source files in order to find what to do but if the bug is locate in the library, what can I do to correct it?

Thanks and have a nice day.

  • You must to post comments
0
0

Hi :)
I haven’t take a look to your pb but i allready encountered the same thing, i have added my own Stop function using the WaveOutPause function from the winmm api.

  • You must to post comments
0
0

Hello KarLKox,

I have tried another method to stop and restart the music but without success. In fact, my application crashes randomly.
It happens when you switch between Play and Stop button. Do it 3 or 4 times and it wil crash surely.

For information:
– Windows XP Pro sp2
– I’m using libminifmod.a (from gcc 1.6 package) and libwinmm.a from Dev-C++ 4.9.9.2

Could you tell me also what is the difference between files libminifmod.a and minifmod.lib?

Thanks in advance for your help.

ps: If necessary, do not hesitate to ask me for more informations.

So what’s wrong in my code:

[size=150:196dvl65][u:196dvl65]Main.cpp[/u:196dvl65][/size:196dvl65]

include <windows.h>

include “playXm_dlg.h”

// prototype for the dialog box function
static BOOL CALLBACK DialogFunc(HWND, UINT, WPARAM, LPARAM);

// Globals variables
HINSTANCE g_hInst;
char s[255];
HWND g_hDlg;

/***************************************************************************************/
/***************************************************************************************/

include “minifmod.h”

//#define USEMEMLOAD

define USEMEMLOADRESOURCE

//#define USESAMPLELOADCALLBACK
//#define USEFMOD

FMUSIC_MODULE *mod = NULL;

typedef struct
{
int length;
int pos;
void *data;
}
MEMFILE;

unsigned int memopen(char *name)
{
MEMFILE *memfile;
memfile = (MEMFILE *)calloc(sizeof(MEMFILE),1);

HRSRC rec;
HGLOBAL handle;

rec = FindResource(NULL, name, RT_RCDATA);
handle = LoadResource(NULL, rec);

memfile->data = LockResource(handle);
memfile->length = SizeofResource(NULL, rec);
memfile->pos = 0;
//wsprintf(s, “memfile->length: %d”, memfile->length);MessageBox(0,s, “”, 0);

return((unsigned int)memfile);
}

void memclose(unsigned int handle)
{
MEMFILE *memfile = (MEMFILE *)handle;

ifndef USEMEMLOADRESOURCE

free(memfile->data); // dont free it if it was initialized with LockResource

endif

free(memfile);
}

int memread(void *buffer, int size, unsigned int handle)
{
MEMFILE *memfile = (MEMFILE *)handle;

if (memfile->pos + size >= memfile->length)
size = memfile->length – memfile->pos;

memcpy(buffer, (char *)memfile->data+memfile->pos, size);
memfile->pos += size;

return(size);
}

void memseek(unsigned int handle, int pos, signed char mode)
{
MEMFILE *memfile = (MEMFILE *)handle;

if (mode == SEEK_SET)
memfile->pos = pos;
else if (mode == SEEK_CUR)
memfile->pos += pos;
else if (mode == SEEK_END)
memfile->pos = memfile->length + pos;

if (memfile->pos > memfile->length)
memfile->pos = memfile->length;
}

int memtell(unsigned int handle)
{
MEMFILE *memfile = (MEMFILE *)handle;
return(memfile->pos);
}

void PlayMusic() {
if (!mod) {
// Load and play music
FSOUND_File_SetCallbacks(memopen, memclose, memread, memseek, memtell);
// Initialize
if (!FSOUND_Init(44100, 0))
{
MessageBox(0, “Error upon initialization.”, “Error”, 0);
return;
}
// Load song
mod = FMUSIC_LoadSong(MAKEINTRESOURCE(XM_FILE), NULL);
if (!mod)
{
FSOUND_Close();
MessageBox(0, “Error loading song”, “Error”, 0);
return;
}
// Play song
FMUSIC_PlaySong(mod);
}
}

void StopMusic() {
if (mod) {
//wsprintf(s, “mod : %lu”, mod); MessageBox(0,s,0,0);
FMUSIC_StopSong(mod);
FMUSIC_FreeSong(mod);
FSOUND_Close();
mod = NULL;
}
}

/***************************************************************************************/
/***************************************************************************************/

// Main function
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{
g_hInst = hThisInstance;
DialogBoxParam(hThisInstance, MAKEINTRESOURCE(IDD_DLG_MAIN), NULL, (DLGPROC) DialogFunc, 0);
ExitProcess(0);
}

// Callback function for the main dialog box
BOOL CALLBACK DialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDC_BTN_PLAY:
// Play song
PlayMusic();
return TRUE;
case IDC_BTN_STOP:
StopMusic();
return TRUE;
}
break;
case WM_CLOSE:
DestroyWindow(hwndDlg);
return TRUE;
case WM_DESTROY:
// Libère les ressources
StopMusic();
EndDialog(hwndDlg, FALSE);
return TRUE;
}
return FALSE;
}

[size=150:196dvl65][u:196dvl65]playXm_dlg.rc[/u:196dvl65][/size:196dvl65]

define RCDATA 10

define IDD_DLG_MAIN 1000

define IDC_BTN_PLAY 1001

define IDC_BTN_STOP 1002

define XM_FILE 10000

IDD_DLG_MAIN DIALOGEX 6,5,150,44
CAPTION “XmPlayer”
FONT 8,”MS Sans Serif”
STYLE 0x10CA0800
EXSTYLE 0x00000000
BEGIN
CONTROL “&PLAY”,IDC_BTN_PLAY,”Button”,0x50018000,6,16,66,13,0×00000000
CONTROL “&STOP”,IDC_BTN_STOP,”Button”,0x50018000,82,16,56,13,0×00000000
END
XM_FILE RCDATA DISCARDABLE “xm/music.xm”

[size=150:196dvl65][u:196dvl65]playXm_dlg.h[/u:196dvl65][/size:196dvl65]

define RCDATA 10

define IDD_DLG_MAIN 1000

define IDC_BTN_PLAY 1001

define IDC_BTN_STOP 1002

define XM_FILE 10000

[size=150:196dvl65][u:196dvl65]minifmod.h[/u:196dvl65][/size:196dvl65]

It comes from the package of minifmod 1.60 (GCC package)

  • You must to post comments
Showing 5 results
Your Answer

Please first to submit.