Hello
The main problem is that wchar_t is 4 bytes on GNU, but 2 bytes on Windows !
Though Windows typedefs WCHAR as a wchar_t, but there a wchar_t is an "unsigned short", whereas on GNU it's "unsigned long"
So WCHAR serialized data from Windows will get messed if we use native GNU data types (because then the program will read 4 bytes instead where it should have read 2 bytes!).
Now you don't have to worry about WINE, as WINE defines the data type just as Windows and hence there's no problem with WINE's internationalization functions (MultiByte.. or WideChar... etc)
But as I am using pure C++, I have to use GLibc's library functions which expects wchar_t to be 4 bytes long and NOT 2 bytes.
So as a workaround I defined these two functions to convert from wchar_t and WCHAR to keep GNU's wcstombs() happy:
inline void Convert_wchar_t_ToWCHAR(const wchar_t* wszIn,WCHAR* wszOut)
{
if(wszIn) while(*wszOut++=*wszIn++);
else *wszOut=0;
}
and
inline void ConvertWCHARTo_wchar_t(const WCHAR* wszIn,wchar_t* wszOut)
{
if(wszIn) while(*wszOut++=*wszIn++);
else *wszOut=0;
}
As you can see, all the above two does is JUST copy the arrays from one data type to another.
As we are reading the data from a .lnk (and thus the wchar_t strings are 2 byte arrays in the file..), there's no harm done, as by copying the 2 byte array into a 4 byte array, there is no loss of information.
But, unfortunately, (but NOT always..), the function wcstombs fails.
I have attached the binary and source alongwith a .lnk which demonstrates this problem.
You just need to pass the .lnk filename to the binary on the command line, and it will spit out a few details at out about the .lnk
If you test the .lnk (DAEMON_TOOLS.LNK), you will see that the program crashes in the function:
unsigned int WineWorksShortcutResolver::UnicodeToANSI(const WCHAR* wszInUnicode,unsigned int uiLen,char* szOutANSI)
at the GLibc function:
wcstombs(..)
The most confusing thing is that this does not happen in case of any other .lnk that I have (which are not many..) !
Any suggestions ?
Regards
Subhobroto Sinha