1

Here you can see that when you convert from Wide to Narrow some symbols may be replaced by ?. How to detect those cases when W2A conversion is applied on a string. Round trip conversion is a way, but not fast. I guess while converting W2A function should mark somehow that the conversion was not fully possible. How to get that information?

EDIT: For example in case of

int WideCharToMultiByte(
  UINT CodePage, 
  DWORD dwFlags, 
  LPCWSTR lpWideCharStr, 
  int cchWideChar, 
  LPSTR lpMultiByteStr, 
  int cbMultiByte, 
  LPCSTR lpDefaultChar, 
  LPBOOL lpUsedDefaultChar 
);

The last argument is telling what I need. What about W2A? How to detect the case?

Community
  • 1
  • 1
Narek
  • 38,779
  • 79
  • 233
  • 389

1 Answers1

2

To check this out, use WideCharToMultiByte directly. You have an indication that default character was used there, and you have flags that affect conversion process.

W2A uses the same API with dwFlags of zero, and lpUsedDefaultChar of NULL, so information you need is just not queried at all.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • Thanks, but I know about this. I need to detect the case for W2A conversion. – Narek Nov 20 '12 at 08:37
  • How do you know? Any source code, please? I need to know what is substitutes as default character too. – Narek Nov 20 '12 at 08:40
  • Source code is in Visual Studio's `\VC\atlmfc\include\atlconv.h` – Roman R. Nov 20 '12 at 08:41
  • Thanks. So both of them are null: int `ret = WideCharToMultiByte(acp, 0, lpw, -1, lpa, nChars, NULL, NULL);` – Narek Nov 20 '12 at 08:44
  • In addition, note that `W2A` is deprecated (ATL 3.0); the [more modern version is `CW2A`](http://msdn.microsoft.com/en-us/library/87zae4a3(v=vs.80).aspx). – Mr.C64 Nov 20 '12 at 08:50