Suppose I need to use a string in a an apish function that accepts one of the parameters (and more) of a variable of type LPWSTR/LPCWSTR/LPCSTR . These are all aliases of the same type. Here is what I do in this case:

  StringCbCat(szTitle,MAX_LOADSTRING,L"123123"); 

StringSbCat Function

As you can see, the last parameter is passed "in pure form" without using variables. I use the predicate "L". Is it possible to somehow do without the predicate by making any preliminary transformations?

Thank!

  • Specify: with the letter "W" (LPWSTR) - always wide, without it (LPSTR) - always the usual char, with the letter "T" (LPTSTR) - depending on the project settings (whether UNICODE is announced or not) - Dith

1 answer 1

If you pass a string without using the L or _T (which is more universal and works for TCHAR ), your string will be automatically treated as an ANSI string.


Accordingly, if the project settings is Use Wide Character Encoding, then the code will not compile. The only thing that can be done in this case is to use any function for transcoding LPCSTR -> LPCWSTR, but it is much more difficult than just using L or _T.

  • Thank you, @Asen! - Salivan
  • @Asen, by the way, if a variable is used instead of text? How, then, to specify the macro L? - Salivan
  • @Jourdan Here is the question of where the variable came from. That's right - generally avoid ANSI lines in Unicode applications. But if it still happened, then use MultiByteToWideChar. - Asen2
  • @Jourdan, no L with a variable is required. The variable must be of the correct type, and must contain the correct (multibyte) characters. - avp
  • four
    WTF? @Asen, who used to be @SingleAsen, says thank you @ Asen2, which used to be just @Asen. Again, the clones themselves naplodil? - neoascetic