c++.windows.32-bits - Error in wsprintf when using double as input
- joe xdobs.com Mar 26 2005
There is a bug in wsprintf when printing double values. It appears to print out the "f" or "lf" of a "%4.0lf" rathern than the interpolated value. I tried several different formatting strings the same holds true for "%g". This was tested in the compiler version downloaded March 22-2005 with the -DUNICODE=1 and -D_UNICODE=1 for the compiler running on Windows XP SP 2 fully patched. double dval = 10.0; char *cb = new char; TCHAR *wcb = new TCHAR; sprintf(cb, "%2.0lf%%", dval); // 8 bit works wsprintf(wcb, TEXT("%2.0lf%%"), dval); // 16 bit fails and will only contain // the lf in the resulting string. To work around this I hacked a test where I converted the format picture to 8 bit string and then used the standard sprintf (8 bit char* string) rather than the wsprintf (16 bit TCHAR*) and then converted the result back to 16 bit before passing it to the windows function and it worked OK but these conversions are not cheap so it would be nice to have it fixed. My sample snippet #ifdef MARS char *cb = new char; // buffer to hold 8 bit formated value char *fmt= new char; // buffer to hold 8 bit format string. memset(fmt, 0,128); memset(cb,0,128); // convert format string from 16 bit to 8 bit. int fmt_len = wcslen(fFormat); int nc = WideCharToMultiByte(CP_UTF8, 0, fFormat, fmt_len, fmt, 128, 0, 0); // Generate 8 bit string representing fCurr_val sprintf(cb, fmt, fCurr_val); // Convert the 8 bit string back to 16 bit wide char. int xw = MultiByteToWideChar(CP_UTF8, 0, cb, strlen(cb), tbuff, tbuff_size); delete cb; delete fmt; #else wsprintf(tbuff, fFormat, fCurr_val); #endif joe xdobs.com - If anybody out there is an expert in DLL usage with this compiler then I could use some help. I have code which generates a DLL and libview utility claims everything is properly exported but when trying to use the DLL by importing the lib still gets undefined symbols. The DLL generated by eVC works fine.
Mar 26 2005