The problem is that shift-jis cannot be reliably parsed backward because the second byte of the two byte codes can also be above 0x80 (thanks, Bill).
Exactly.... You cannot parse it backward.
Quick hack would be like this:
char szArg[] = "C:\\My Music\\[Some DB Charcters]\\foo.wav";
char szBuf[ MAX_PATH + 1 ];
char szPathSeparated[ MAX_PATH + 1 ][ MAX_PATH + 1 ];
int iPathSeparated = 0;
memset( szBuf, '\0', sizeof( szBuf ) );
if( GetSystemDefaultLangID() == 0x411 ) // Japanese
{
int len = lstrlen( szArg );
for( int i = 0, j = 0; i < len; )
{
if( (UINT) szArg[ i ] > 0x80 )
{
szBuf[ j++ ] = szArg[ i++ ];
szBuf[ j++ ] = szArg[ i++ ];
}
else
{
if( szArg[ i ] == '\\' )
{
lstrcpy( szPathSeparated[ iPathSeparated++ ], szBuf );
i++;
j = 0;
memset( szBuf, '\0', sizeof( szBuf ) );
}
else
{
szBuf[ j++ ] = szArg[ i++ ];
}
}
}
}
But this is ugly. You might want to process everything in Unicode internally....