Questions tagged [widestring]

109 questions
53
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
  • 4,613
  • 10
  • 29
  • 43
21
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
  • 20,439
  • 4
  • 54
  • 115
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,045
  • 7
  • 40
  • 58
12
votes
4 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
  • 59,216
  • 102
  • 341
  • 614
9
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,863
  • 15
  • 24
8
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.
  • 255
  • 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
  • 836
  • 2
  • 7
  • 17
8
votes
5 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
  • 33,981
  • 13
  • 121
  • 269
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,480
  • 6
  • 20
  • 41
6
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
  • 1,929
  • 3
  • 19
  • 25
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,010
  • 2
  • 30
  • 57
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,204
  • 14
  • 71
  • 113
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
  • 618
  • 2
  • 11
  • 20
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,234
  • 2
  • 39
  • 58
5
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,359
  • 2
  • 25
  • 43
1
2 3 4 5 6 7 8