As a programmer, you have probably had to use or create some kind of string comparison function. Usually, these are pretty simple:
function compare(s1, s1) { return s1.toLowerCase() - s2.toLowerCase(); }
This works great for the vast majority of cases. However, Windows (XP and later) sorts files differently -- and better! -- than a poor ASCII implementation.
How can I create a Minimal, Complete, and Verifiable example of native Windows natural order sorting in a custom program?
Everything I have read points to using the StrCmpLogicalW
function in shlwapi.dll
. That's great! But how can this function be used inside a custom C/C++ program?
I am not interested in re-implementing the compare function. I have already seen this, this, this, this, and this. These are no doubt very close approximations, but I just want to link or call the Windows API function in my program.
Here are some other things I have researched and tried already:
- reading the documentation on
shlwapi.dll
andStrCmpLogicalW
from Microsoft - finding a (supposedly) complete program posted from an earlier Q&A here on StackOverflow
- compiling several small code samples for Visual Studio 2010 Express, both C++ and C# versions (
fatal error C1190: managed targeted code requires a '/clr' option
... really?) - compiling several small code samples for Visual Studio 2012 Express, because some article said this would get rid of the earlier compile error about the
/clr
option, but just got a bunch of different compile errors instead - tried compiling several small code samples for Eclipse C++ with MinGW
When I first started looking into this, I thought, "It's just the Windows API, this will be easy!" I have yet to come up with a working program in any language.
I have been doing C/C++ and Unix/DOS/Windows shell scripting for a long time, and using an API has never been so irksome. Shame on you, Microsoft.
Also, I've already read the rants about ASCII sorting, but thank you. These contained some fertile soil for some good thinking.
https://blog.codinghorror.com/sorting-for-humans-natural-sort-order/
http://weblog.masukomi.org/2007/12/10/alphabetical-asciibetical/