widestring

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); const int nWritten = swprintf(pTmp, MaxStringLengthPerCharacter, TEXT("%d,"), nPlayerId);...

Delphi: Fast(er) widestring concatenation

i have a function who's job is to convert an ADO Recordset into html: class function RecordsetToHtml(const rs: _Recordset): WideString; And the guts of the function involves a lot of wide string concatenation: while not rs.EOF do begin Result := Result+CRLF+ '<TR>'; for i := 0 to rs.Fields.Count-1 do ...

C++ template function specialization using TCHAR on Visual Studio 2005

I'm writing a logging class that uses a templatized operator<< function. I'm specializing the template function on wide-character string so that I can do some wide-to-narrow translation before writing the log message. I can't get TCHAR to work properly - it doesn't use the specialization. Ideas? Here's the pertinent code: // Log.h head...

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 something such as: ./widestr | hexdump The hexidecimal codepoints create this: 65 57 63 6c 6...

How to cast wchar_t into int for displaying the code point?

I have a simple function in my program, when I was wanting to mess around with unicode and do stuff with it. In this function, I wished to display the code value of the character the user entered. It SEEMED possible, here's my function: wstring listcode(wchar_t arg) { wstring str = L""; str += static_cast<int> (arg); //I tried (...

What can cause SysFreeString to hit an Int 3 breakpoint?

I've got some code that worked fine under Delphi 2007 but breaks under D2010. It involves passing in a string, converting it to a PWideChar (specifically, a WideString pointer, not a UnicodeString pointer), doing some processing, and then calling SysFreeString on it. It works fine until a blank string is passed in, then SysFreeString b...

Why doesn't wstring::c_str cause a memory leak if not properly deleted

Code Segment 1: wchar_t *aString() { wchar_t *str = new wchar[5]; wcscpy(str, "asdf\0"); return str; } wchar_t *value1 = aString(); Code Segment 2 wstring wstr = L"a value"; wchar_t *value = wstr.c_str(); If value from code segment 2 is not deleted then an memory leak does not occur. However, if value1 from code seg...

Sending TCHAR buffer with send(sock, wszBuffer, ...)?

I have a wide-character XML message that I need to send over a Win32 socket in C++. TCHAR wszBuffer[1024]; Should I sprintf(szSendBuffer, "%S", wszBuffer) the wide character buffer to a char array before sending it? What is the correct way to send this? ...