#ifndef UCHAR
#define UCHAR unsigned char
#endif
typedef struct MP3ID3V1
{
UCHAR tag[3]; //"TAG"
UCHAR name[30];
UCHAR author[30];
UCHAR release[30];
UCHAR year[4];
UCHAR remark[30];
UCHAR type;
}CMP3ID3V1;
int GetMp3ID3V1Info(const char *fName, CMP3ID3V1 *mp3Info)
{
int ret = 0;
FILE *fh = fopen(fName, "rb");
if(!fh)
{
return -1;
}
ret = fseek(fh, -128, SEEK_END);
if(-1 == ret)
{
return -1;
}
ret = fread((void *)mp3Info, 128, 1, fh);
if(1 != ret)
{
return -1;
}
ret = fclose(fh);
if(0 != ret)
{
return -1;
}
return 0;
}
CString VCGetMp3ID3V1Info(CString fName)
{
char buf[128] = {0};
//wcstombs(buf, fName.GetBuffer(0), wcslen(fName.GetBuffer(0)));
CMP3ID3V1 mp3Info = {0};
//GetMp3ID3V1Info(buf, &mp3Info);
GetMp3ID3V1Info(fName, &mp3Info);
CString mp3InfoStr = _T(""), tempStr;
wchar_t infoWBuf[30] = {0};
UCHAR infoBuf[30] = {0};
memcpy(infoBuf, mp3Info.name, strlen((const char *)(mp3Info.name)));
//mbstowcs(infoWBuf, (const char *)infoBuf, strlen((const char *)infoBuf));
//tempStr.Format(_T("歌曲名: %s/r/n"), infoWBuf);
tempStr.Format(_T("歌曲名: %s/r/n"), infoBuf);
mp3InfoStr += tempStr;
memset(infoBuf, 0, sizeof(infoBuf));
memset(infoWBuf, 0, sizeof(infoWBuf));
memcpy(infoBuf, mp3Info.author, strlen((const char *)(mp3Info.author)));
//mbstowcs(infoWBuf, (const char *)infoBuf, strlen((const char *)infoBuf));
//tempStr.Format(_T("作者名: %s/r/n"), infoWBuf);
tempStr.Format(_T("作者名: %s/r/n"), infoBuf);
mp3InfoStr += tempStr;
memset(infoBuf, 0, sizeof(infoBuf));
memset(infoWBuf, 0, sizeof(infoWBuf));
memcpy(infoBuf, mp3Info.release, strlen((const char *)(mp3Info.release)));
//mbstowcs(infoWBuf, (const char *)infoBuf, strlen((const char *)infoBuf));
//tempStr.Format(_T("专辑名: %s/r/n"), infoWBuf);
tempStr.Format(_T("专辑名: %s/r/n"), infoBuf);
mp3InfoStr += tempStr;
memset(infoBuf, 0, sizeof(infoBuf));
memset(infoWBuf, 0, sizeof(infoWBuf));
return mp3InfoStr;
}