more-taglib-examples/taglib-set-picture.cpp on Visual Studio 2008
Lukáš Lalinský
lalinsky at gmail.com
Wed Nov 5 11:16:45 CET 2008
Dňa St, 2008-11-05 o 11:02 +0100, Sven Grunewaldt napísal:
> Okay, I asked my colleagues for a little help and I got it solved now,
> but I think I found a bug.
>
> While debugging I changed the mimeType function to this:
> TagLib::String mimeType() const
> {
> TagLib::String fileName = (const char*) this->name();
> unsigned int length = fileName.length();
> TagLib::String fileExt4 = fileName.substr(length - 4, 4);
> TagLib::String fileExt5 = fileName.substr(length - 5, 5);
> fileExt4 = fileExt4.upper();
> fileExt5 = fileExt5.upper();
>
> if(fileExt4 == ".PNG")
> return "image/png";
> else if(fileExt4 == ".JPG" ||
> fileExt5 == ".JPEG")
> return "image/jpeg";
> else
> return TagLib::String::null;
> }
> This code finally works and I got the picture attached!
>
> Now to the bug thing... when I change the third line from (const
> char*)
> to (const wchar_t*) the returned string is empty.
> Maybe I got this wrong.. but shouldn't wchar_t just be the same as the
> char but in unicode?
No, TagLib::FileName is designed to work with two distinct string types
for filenames. If you either construct FileName with char* and then only
the char* cast will return the value or you can construct it with
wchar_t* and only (wchar_t*) will work. So you need to handle both
cases. You can use the code from fileref.cpp as an example:
String s;
#ifdef _WIN32
s = (wcslen((const wchar_t *) fileName) > 0) ? String((const wchar_t
*) fileName) : String((const char *) fileName);
#else
s = fileName;
#endif
Lukas
More information about the taglib-devel
mailing list