Questions tagged [widestring]

112 questions
65
votes
3 answers

What exactly is the L prefix in C++?

I understand what it does: specifies a string literal as a const wchar_t * (wide character string) instead of const char * (plain old characters), but how is it actually defined? Is it a macro of some sort? Is it an operator for GCC compilers? What…
user965369
  • 5,413
  • 13
  • 33
  • 47
22
votes
1 answer

Why can Delphi DLLs use WideString without using ShareMem?

David's answer to another question shows a Delphi DLL function returning a WideString. I never thought that was possible without the use of ShareMem. My test DLL: function SomeFunction1: Widestring; stdcall; begin Result := 'Hello'; end; function…
kobik
  • 21,001
  • 4
  • 61
  • 121
21
votes
4 answers

Is it necessary to convert string to WideString in Delphi?

I found a Windows API function that performs "natural comparison" of strings. It is defined as follows: int StrCmpLogicalW( LPCWSTR psz1, LPCWSTR psz2 ); To use it in Delphi, I declared it this way: interface function StrCmpLogicalW(psz1,…
Mariusz Schimke
  • 3,185
  • 8
  • 45
  • 63
15
votes
5 answers

Can we use wmain() with Unix compilers or it'll work only on Windows?

Can we use the wmain() function with Unix compilers or it'll work only on/for Windows?
Rella
  • 65,003
  • 109
  • 363
  • 636
10
votes
1 answer

Why do I need Sharemem in my Delphi dll which only exposes a function with WideString parameters?

I have a dll and a test application written in Delphi. The test application uses multiple threads to call the function exported by the dll. The exported function has a trivial thread safe implementation. When running the test application various…
RM.
  • 1,984
  • 19
  • 29
10
votes
6 answers

How to display L"أَبْجَدِيَّة عَرَبِيَّة‎中文" using wcout?

I want to display an Arabic message mixed with Chinese using wcout. The following code is OK: #include using namespace std; int main() { wcout.imbue(locale("chs")); wcout << L"中文"; // OK } However, the following code doesn't…
xmllmx
  • 39,765
  • 26
  • 162
  • 323
9
votes
1 answer

C++: wide characters outputting incorrectly?

My code is basically this: wstring japan = L"日本"; wstring message = L"Welcome! Japan is "; message += japan; wprintf(message.c_str()); I'm wishing to use wide strings but I do not know how they're outputted, so I used wprintf. When I run…
John D.
  • 265
  • 4
  • 10
8
votes
2 answers

Delphi 2010 Wide functions vs. String functions

We're currently converting a Delphi 2007 project to Delphi 2010. We were already using Unicode (via WideStrings and TNT Unicode Controls). I was expecting to replace all Wide functions, e.g. WideUpperCase, with their equivalent, e.g. UpperCase, but…
Mick
  • 846
  • 2
  • 7
  • 18
7
votes
2 answers

When should we prefer wide-character strings?

I am modernizing a large, legacy MFC codebase which contains a veritable medley of string types: CString std::string std::wstring char* wchar_t* _bstr_t I'd like to standardize on a single string type internally, and convert to other types only…
BTownTKD
  • 7,911
  • 2
  • 31
  • 47
7
votes
4 answers

When and why can sprintf fail?

I'm using swprintf to build a string into a buffer (using a loop among other things). const int MaxStringLengthPerCharacter = 10 + 1; wchar_t* pTmp = pBuffer; for ( size_t i = 0; i < nNumPlayers ; ++i) { const int nPlayerId = GetPlayer(i); …
Srekel
  • 2,183
  • 3
  • 21
  • 26
7
votes
4 answers

Converting wide char string to lowercase in C++

How do I convert a wchar_t string from upper case to lower case in C++? The string contains a mixture of Japanese, Chinese, German and Greek characters. I thought about using…
Nitramk
  • 1,542
  • 6
  • 25
  • 42
6
votes
2 answers

Mixing wide and narrow string literals in C

Just found out that all of the following work: printf( "%ls\n", "123" L"456" ); printf( "%ls\n", L"123" "456" ); printf( "%ls\n", L"123" L"456" ); The output is 123456 123456 123456 Why can I freely mix and match wide and narrow string literals to…
dragonroot
  • 5,653
  • 3
  • 38
  • 63
6
votes
4 answers

(Wide)String - storing in TFileStream, Delphi 7. What is the fastest way?

I'm using Delphi7 (non-unicode VCL), I need to store lots of WideStrings inside a TFileStream. I can't use TStringStream as the (wide)strings are mixed with binary data, the format is projected to speed up loading and writing the data ... However I…
migajek
  • 8,524
  • 15
  • 77
  • 116
5
votes
2 answers

Delphi XE2 AnsiFormat() and ANSI String constants

Is there a handy Format() function that works only on Ansi strings? Because everytime I use an AnsiString with Format() I get a warning. And no, I don't want Delphi to convert my AnsiStrings back and forth between Wide and Ansi strings. That is just…
Brian Hawk
  • 728
  • 2
  • 12
  • 24
5
votes
2 answers

How can I make fixed-length Delphi strings use wide characters?

Under Delphi 2010 (and probably under D2009 also) the default string type is UnicodeString. However if we declare... const s :string = 'Test'; ss :string[4] = 'Test'; ... then the first string s if declared as UnicodeString, but the second one…
GJ.
  • 10,810
  • 2
  • 45
  • 62
1
2 3 4 5 6 7 8