Title: [original] added the XM music playing function to the vc6 Project (detailed operation process)
Author: tankaiha
Time: 2005-12-04,02: 45: 50
Chain: http://bbs.pediy.com/showthread.php? T = 19099
1. Download The minifmod playback component. The address is done.
2. Copy the above two files to your project directory and add # include "minifmod. H" to the source code ".
3. Find a. XM music and add it to the resource. The resource category name is "BGM". The resource ID is arbitrary, usually music.
4. Because minifmod. Lib is used, add minifmod. lib to the link item in the project properties. If there is no winmm. Lib, add it because it will be called in fmod.
5. Copy the following code to any source file of your project, usually main. cpp. This section of code comes from the main. cpp of the minifmod compressed package, mainly used to play XM music in resources. I modified the description and saved the definition # define usememloadresource
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, "BGM"); 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; 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;}
6. After the preparation is complete, add the code for playing music where you need it.
Fmusic_module * MOD; // defines the variable
Fsound_file_setcallbacks (memopen, memclose, memread, memseek, memtell); // sets the playback function to memory (Resource) for music playing.
MoD = fmusic_loadsong (makeintresource (music), null); // open a resource
FMUSIC_PlaySong (mod); start playing
FMUSIC_StopSong (mod); // stop playing
FMUSIC_FreeSong (mod); // release resources. If you execute the command on my machine, you will not need to use it.
7. If the link encounters an inexplicable error, that is, the MSVCRT. lib function is repeatedly defined, the MSVCRT. lib will be ignored in the link of the Project property.
That's all. It's detailed enough! Everyone is here to add a cool background music to the registration machine!