6

How do you convert LPCWSTR to const char *?

Thanks

flavour404
  • 6,184
  • 30
  • 105
  • 136
  • 1
    Because he need it. I need it too. Example windows service written on VisualStudio2015 on c++ gives me startup params as LPCWSTR, but all my legacy code expects chonst char * array – Kostadin Nov 18 '15 at 12:54

2 Answers2

12

Use the WideCharToMultiByte function.

Note that LPCWSTR is the same as const wchar_t *, so if you're dealing with wide character data throughout your application, you may not need to convert it at all.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
2

You can also have a look at wcstombs_s

Red5
  • 21
  • 1