Skip to main content
Topic: UTF8 -> UTF16? (Read 3524 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

UTF8 -> UTF16?

I'm gonna have to ask a quick question. Say I get a filename with the following statement:

const char* filename = (const char*) file_path_display(handle->handle_get_path());

Is the filename UTF8 encoded? How am I supposed to do to convert it to TCHAR* so that Windows can recognize it? I tried MultiByteToWideChar but somehow couldn't make it work.

Thanx...

UTF8 -> UTF16?

Reply #1
never mind... i figured out... this string conversion methods are confusing...

UTF8 -> UTF16?

Reply #2
You will find UTF-8 replacements for many Win32 API functions in utf8api. When that fails, and you care to support ANSI and Unicode, use IsUnicode() and code for both. If at all possible avoid reading text from dialogs when you don't need to, since this can be unreliable with the ANSI version of utf8api.dll. (For example, a list box of strings read from tags/file/whatever, read which index the user selected and resolve the text again internally, or store the whole list internally in UTF-8 encoding.)

UTF8 -> UTF16?

Reply #3
Thanx for the explaination. What troubled me was to convert UTF8 to some TCHAR pointer so I can pass it in some Unicoded Windows data structure. Haven't programmed C++ for quite a while, need to refresh my memory... convert_utf8_to_os() does get the work done.

UTF8 -> UTF16?

Reply #4
Yes, but there are plenty of UTF-8 replacements for Win32 functions in utf8api. Check there to see if it contains the function you need. There are also defines/typedefs for uBlah for various structures to pass to those functions, but I have yet to see one that is more than just an alias for the ANSI version of the struct. It's best to use it anyway...

Of course, if your component is only going to work in Windows NT, you might as well build with UNICODE defined and forget utf8api. It does have some handy classes, such as a nice wrapper class for the file finding functions.

UTF8 -> UTF16?

Reply #5
thanx man... the API i used was SHFileOperation, which deletes files to recycle bin. i don't think it's defined in utf8api.

UTF8 -> UTF16?

Reply #6
In that case, you would use IsUnicode(), then explicitly code for both ANSI and Unicode...

Code: [Select]
const char * file = "blah";
int rval;

if (IsUnicode())
{
 string_utf16_from_utf8 foo(file);
 SHFILEOPSTRUCTW sfo;
 memset(&sfo, 0, sizeof(sfo));
 sfo.wFunc = FO_DELETE;
 sfo.pFrom = foo;
 sfo.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION; // whatever
 rval = SHFileOperationW(&sfo);
}
else
{
 string_ansi_from_utf8 foo(file);
 SHFILEOPSTRUCTA sfo;
 memset(&sfo, 0, sizeof(sfo));
 sfo.wFunc = FO_DELETE;
 sfo.pFrom = foo;
 sfo.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION;
 rval = SHFileOperationA(&sfo);
}

// check rval here


Rather basic, but you probably get the idea.

Oh yes, and this function might be added to utf8api before 0.8.1, keep a lookout...

EDIT: I see what you were asking about, I'll probably take a look and find that you already did something like that....

 
SimplePortal 1.0.0 RC1 © 2008-2020