David Raymond <[email protected]>于2017年6月10日 周六05:55写道:
> Non C programmer question: In your patch there, does sout have to be freed > or anything, or am I missing something? No. The 4th arg of WriteConsoleW is lpNumberOfCharsWritten. > > > > -----Original Message----- > From: sqlite-users [mailto:[email protected]] > On Behalf Of Olivier Mascia > Sent: Monday, June 05, 2017 6:20 PM > To: SQLite mailing list > Subject: Re: [sqlite] [SPAM] Fwd: How to correctly display unicode > characters in Windows 10 / cmd.exe / sqlite3.exe? > > > Patch shell.c to get it to output to the console using WriteConsoleW and > not fputs(). > > For a starter, see shell.c (3.19.2) around line 372 and following, > function utf8_printf(). > The intent is right (Windows needs some help to output UTF8), the > implementation is not. > For proper unicode console output on Windows you need to use > WriteConsoleW(), and not the C library. > > > shell.c > @@ -380,10 +380,12 @@ > va_start(ap, zFormat); > if( stdout_is_console && (out==stdout || out==stderr) ){ > char *z1 = sqlite3_vmprintf(zFormat, ap); > - char *z2 = sqlite3_win32_utf8_to_mbcs_v2(z1, 0); > + WCHAR *z2 = sqlite3_win32_utf8_to_unicode(z1); > sqlite3_free(z1); > - fputs(z2, out); > - sqlite3_free(z2); > + DWORD sout; > + WriteConsoleW(GetStdHandle((out == stdout) ? STD_OUTPUT_HANDLE : > STD_ERROR_HANDLE), > + z2, wcslen(z2), &sout, 0); > + sqlite3_free(z2); > }else{ > vfprintf(out, zFormat, ap); > } > > And there you go: > > sqlite> select char(0x20ac); > char(0x20ac) > € > sqlite> > > > ... > > -- > Best Regards, Meilleures salutations, Met vriendelijke groeten, > Olivier Mascia, http://integral.software > > > _______________________________________________ > sqlite-users mailing list > [email protected] > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users > _______________________________________________ > sqlite-users mailing list > [email protected] > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users > -- Best regards, Wenbo Zhao ========= _______________________________________________ sqlite-users mailing list [email protected] http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

