I am writing a mp3-player and there is some code I don’t manage to get work and doesn’t understand why.
first here is the declaration of DBItem:
unsigned int iYear;
unsigned int iTrack;
unsigned int iIndex;
unsigned int fLengthSeconds;
now this DBItem is used in my LoadAudio procedure:
[code:2cxjjliy]bool LoadAudio(HWND hwnd, char *filename, GlobalData& data, DBItem *item)
file = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (item == NULL)
item = data.db.NewItem();
item->result = data.system->createStream(filename, (FMOD_MODE) (FMOD_HARDWARE | FMOD_VBRACCURATE | FMOD_LOOP_OFF), 0, &(item->sound));
if (item->result == FMOD_OK)
item->sound->getLength(NULL, item->fLengthSeconds, NULL);
Second2Time((float) *(item->fLengthSeconds) / 1000, item->szLengthString);
if (item->sound->getTag(0, -1, &(item->tag)) != FMOD_OK)
if (item->tag.datatype == FMOD_TAGDATATYPE_STRING)
if (lstrcmp(item->tag.name, "TITLE") == 0)
lstrcpy(item->szTitle, (char *) item->tag.data);
if (lstrcmp(item->tag.name, "YEAR") == 0)
item->iYear = (int) item->tag.data;
if (lstrcmp(item->tag.name, "TRACK") == 0)
item->iTrack = (int) item->tag.data;
if (lstrcmp(item->tag.name, "ALBUM") == 0)
lstrcpy(item->szAlbum, (char *) item->tag.data);
if (lstrcmp(item->tag.name, "ARTIST") == 0)
lstrcpy(item->szArtist, (char *) item->tag.data);
Now here the weird problem:
i call the LoadAudio procedure and display the title and album etc. in a messagebox. this work flawlessly.
but when i want to show the filename in an messagebox is just displays some weird chars – as if nothing was copied to the szFilename property…
and when i want to play the sound using
system->playSound(0, PlayItem->sound, false, &(channel));
i get an exception and the application quits…
i call the LoadAudio procedure this way in my main program:
[code:2cxjjliy]if (LoadAudio(hwnd, file, data, NULL))
data.PlayItem = data.db.GetStart();
data.channel = 0;
data.system->playSound(0, PlayItem->sound, false, &(channel));
now if i do the lstrcpy of the szFilename and the system->CreateStream manually just before the playsound i works?!
summarized the problem is:
why does the sound and szFilename property just didn’t get overwritten in the LoadAudio procedure?
please help me…
- stalnation asked 13 years ago
[quote="brett":1ymngwxb]Are you just having a problem because maybe you are using unicode or something? Your app expects unicode but the filename is single byte string?[/quote:1ymngwxb]
char vs wchar_t ???
The compiler should raise errors if you go mix those.
On the other hand i use TCHAR and _tcscopy() which are special defines in tchar.h so i can compile with and without _UNICODE
Would be cool though when FMOD also supports wchar_t
I also found issues regarding corrupt pointers.
Mostly the corruptions are caused by buffer overflows.
I would start by checking your own code first by commenting out the fmod parts to see if my own code is corrupt.
Else i would start fidling with fmod+own code in a small test app, afterall if you make a “work around” mostly a different part of the app gets corrupted.
mhhh that is maybe the solution i will change it.
but here the bigger problem:
i have a pointer to an item that contains a pointer to FMOD::SOUND.
in my procedure i overwrite the sound with the returning value of system->createStream…
but when i call the playSound command outside this procedure in my main application, the application gets an exception…
when i do the createStream outside this procedure in my main procedure everything works fine…
so does the sound not get inherited? perhabs i have to declare the pointer to the item that consists the sound as reference variable?
i have no idea why the createStream procedure does not work in my LoadAudio procedure and does work in my main procedure with playSound…
i hope i made my problem more easier to understand…
[quote="brett":hdnl6nx9]maybe you are storing your data in a local variable and it has gone out of scope. I don’t think there is an fmod problem here. It sounds like you are passing bad pointers to fmod, or you’ve gone too many levels deep in getting the address of the address of pointers etc.
Use a debugger and you might have some luck finding what your problem is.[/quote:hdnl6nx9]
yeah i know it is not an fmod problem, but i thought you may help me, because it is my problem that i can’t handle fmod correctly
ok thanks for your help, i will look into it…
Please login first to submit.