NO

Author Topic: wprintf does not work correctly.  (Read 13818 times)

edison

  • Guest
Re: wprintf does not work correctly.
« Reply #15 on: June 12, 2014, 06:01:55 PM »
SetConsoleOutputCP(65001) does not work, but 936 works.

Code: [Select]
#include <stdio.h>
#include <wchar.h>
#include <windows.h>

int main(void)
{
wchar_t *a = L"中文";
DWORD n;
SetFileApisToOEM();
SetConsoleOutputCP(936);
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), a, wcslen(a), &n, NULL);

wprintf(L"%ls\n", a);
wprintf(L"%ls\n", L"中文");
return 0;
}

output:
Win 8.1 x64 chs:
Code: [Select]
中文-?
-?
Press any key to continue...

the wprintf still not work in right way.

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: wprintf does not work correctly.
« Reply #16 on: June 12, 2014, 07:05:38 PM »
Something like this works?
Code: [Select]
char MbStr[32];
WideCharToMultiByte(936, WC_DEFAULTCHAR, L"中文", -1, MbStr, 32, NULL, NULL);
printf("%s\n",MbStr);
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

edison

  • Guest
Re: wprintf does not work correctly.
« Reply #17 on: June 12, 2014, 07:52:17 PM »
Code: [Select]
#include <stdio.h>
#include <wchar.h>
#include <windows.h>

int main(void)
{
char MbStr[32];
WideCharToMultiByte(936, WC_DEFAULTCHAR, L"中文", -1, MbStr, 32, NULL, NULL);
printf("%s\n", MbStr);
return 0;
}

the output(wrong):
Code: [Select]
)
Press any key to continue...
« Last Edit: June 13, 2014, 05:09:35 AM by edison »

Offline jj2007

  • Member
  • *
  • Posts: 536
Re: wprintf does not work correctly.
« Reply #18 on: June 12, 2014, 11:03:19 PM »
Have you created this as a windows project or a console project?
Add '-subsystem:windows' on linker command line or select subsystem=windows form linker tab.

Thanks. Adding user32.lib, enabling M$ extensions and changing to sub windows made it finally work. Would be great if the IDE was able to guess these settings automatically, or at least throw warnings of the "wWinMain detected - are you sure it's a console app?" style...

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: wprintf does not work correctly.
« Reply #19 on: June 13, 2014, 08:44:05 AM »
Code: [Select]
#include <stdio.h>
#include <wchar.h>
#include <windows.h>

int main(void)
{
char MbStr[32];
WideCharToMultiByte(936, WC_DEFAULTCHAR, L"中文", -1, MbStr, 32, NULL, NULL);
printf("%s\n", MbStr);
return 0;
}

the output(wrong):
Code: [Select]
)
Press any key to continue...
Ya it seems that the low level part of a file writing on printf family is unaware of encodings and codepages. This probably lead to mishandling of strings.  :-X
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

edison

  • Guest
Re: wprintf does not work correctly.
« Reply #20 on: July 15, 2014, 09:36:45 AM »
The wprintf of POCC 8.0 RC5 still not work correctly, nothing changed here.

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: wprintf does not work correctly.
« Reply #21 on: July 15, 2014, 11:08:36 AM »
Yes, Pelle want the IO subsystem to comply with Cxx standard, while MS subsystem is not compliant...
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

edison

  • Guest
Re: wprintf does not work correctly.
« Reply #22 on: August 11, 2014, 08:07:31 AM »
Still not works in 8.0 RC6.
Is there any chance to fix this problem in furture version ?