Unicode Support
With Total Commander 7.5 (fs plugin interface 2.0), Unicode support has been added to all plugin types. In principle, you need to implement the same functions as for ANSI, with two differences: The function name is changed from FunctionName to FunctionNameW, and ANSI strings are changed to wide char names.
Total Commander will call the Unicode functions on all NT-based systems (Windows NT, 2000, XP, Vista, 7) if they are present. If not, or on Windows 9x/ME, Total Commander will call the ANSI functions.
IMPORTANT WARNING: When FsFindFirstW is implemented, any Path field can be up to 1023 characters long! Make sure that your plugin uses buffers of 1024 characters in both the ANSI and Unicode functions, or at least doesn't crash for such long strings.
The following functions of the file system plugin interface support Unicode:
The following functions do not exist in a Unicode form and must be implemented as ANSI:
What's the easiest way to support Unicode in an existing plugin?
There are actually two ways, an "all in one" combined Unicode/ANSI plugin, and two separate plugins.
A. Combined Unicode/ANSI plugin
1. Get my sample plugin fsplugin (file system plugins section) even if you write a different type of plugin!
2. Add the files cunicode.h and cunicode.cpp to your project. They contain various functions to make Unicode support easier.
3. Convert your existing functions to Unicode and rename them to FunctionNameW. For all file functions like CreateFile, do not call their Unicode counterpart CreateFileW directly. Instead, call the functions from cunicode.cpp like CreateFileT. These functions automatically call the right Unicode or ANSI function, and even support file name lengths >259 characters!
4. For each converted function like FunctionNameW, recreate a function FunctionName which you call this way:
int __stdcall FunctionName(char* SomeString1,char* SomeString2)
{
WCHAR SomeString1W[wdirtypemax],SomeString2W[wdirtypemax];
return FunctionNameW(awfilenamecopy(SomeString1W,SomeString1),awfilenamecopy(SomeString2W,SomeString2));
}
See the implementation of FsContentGetValue in the above plugin for function which need to return string values.
The Macro awfilenamecopy will convert the ANSI string SomeString1 to Unicode and store it inSomeString1W. This variable must not be a pointer, because awfilenamecopy uses "countof" to get the target length.
B. Two separate plugins, one Unicode, one ANSI
This method is especially suited for C/C++ plugins. Have a look at the WebDAV plugin sources for a sample plugin using this method. Here are the steps to convert an ANSI plugin to Unicode this way:
1. Replace all string references like char* and LPSTR by TCHAR*
2. Replace all string handing functions like strchr or strcpy by _tcschr and _tcscpy
3. Put TEXT() around all string constants
4. Make a copy of the current project within the same project map. Add the UNICODE and _UNICODE defines in the compiler settings of the Unicode project
5. Remove the .def file from the Unicode project. Create a new .def file, where the functions are defined as follows:
FsFindFirstW=FsFindFirst
FsFindNextW=FsFindNext
FsFindClose
...
Note the difference between Unicode and non-Unicode functions (see list above which are Unicode)
6. Set the output file to the name <pluginname>.uwfx, in the same directory as the .wfx file from the first project
Total Commander will try to load a .uwfx file with the same name as the .wfx file on Unicode systems (Win NT, 2000, XP, Vista, 7).
Note: You cannot have just the .uwfx plugin if you want to create a Unicode-only plugin! Instead, create a combined Unicode/ANSI plugin, where the ANSI functions are just empty functions returning an error.