wchar-t

How do you efficiently copy BSTR to wchar_t[] ?

I have a BSTR object that I would like to convert to copy to a wchar__t object. The tricky thing is the length of the BSTR object could be anywhere from a few kilobytes to a few hundred kilobytes. Is there an efficient way of copying the data across? I know I could just declare a wchar_t array and alway allocate the maximum possible data...

Wide exec for C/C++

Is there a wchar_t version of exec[lv][pe]* (i.e. an exec that uses wchar_t as path and wchar_t as arguments)? In Windows, I can just do CreateProcessW(process, cmdline), but in *nix, I'm stuck (i.e. no pure POSIX equivalent). I'm trying to add UTF-16 support to my program (an autorun). ...

Is TCHAR still relevant?

I'm new to Windows programming and after reading the Petzold book I wonder: is it still good practice to use the TCHAR type and the _T() function to declare strings or if I should just use the wchar_t and L"" strings in new code? I will target only Windows 2000 and up and my code will be i18n from the start up. ...

How to convert (not neccessarily programatically) between Windows' wchar_t and GCC/Linux one?

Suppose I have this Windows wchar_t string: L"\x4f60\x597d" and L"\x00e4\x00a0\x597d" and would like to convert it (not neccessarily programatically; it will be a one-time thing) to GCC/Linux wchar_t format, which is UTF-32 AFAIK. How do I do it? (a general explanation would be nice, but example based on this concrete case would be...

I want to convert std::string into a const wchar_t *

Is there any method? My computer is AMD64, ::std::string str; BOOL loadU(const wchar_t* lpszPathName, int flag = 0); when I used: loadU(&str); the VS2005 compiler says: Error 7 error C2664:: cannot convert parameter 1 from 'std::string *__w64 ' to 'const wchar_t *' How can I do it ? ...

Is endian conversion required for wchar_t data?

In C/C++, if a multi-byte wide character (wchar_t) value is transmitted from a big-endian system to a little-endian system (or vice-versa), will it come out the same value on the other side? Or will the bytes need to be swapped? ...

Portable wchar_t in C++

Is there a portable wchar_t in C++? On Windows, its 2 bytes. On everything else is 4 bytes. I would like to use wstring in my application, but this will cause problems if I decide down the line to port it. ...

How do I read Unicode-16 strings from a file using POSIX methods in Linux?

I have a file containing UNICODE-16 strings that I would like to read into a Linux program. The strings were written raw from Windows' internal WCHAR format. (Does Windows always use UTF-16? e.g. in Japanese versions) I believe that I can read them using raw reads and the converting with wcstombs_l. However, I cannot figure what locale ...

Win32: Determine whether stdout handle is char or wchar stream

I'm writing a win32 utility function for our product that needs to call an arbitrary program via the shell and log its output. We do this by redirecting the stdout from the child process into a pipe: saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); saAttr.bInheritHandle = TRUE; saAttr.lpSecurityDescriptor = NULL; Create...

Unexpected output of std::wcout << L"élève"; in Windows Shell

While testing some functions to convert strings between wchar_t and utf8 I met the following weird result with Visual C++ express 2008 std::wcout << L"élève" << std::endl; prints out "ÚlÞve:" which is obviously not what is expected. This is obviously a bug. How can that be ? How am I suppose to deal with such "feature" ? ...

static_cast wchar_t* to int* or short* - why is it illegal?

In both Microsoft VC2005 and g++ compilers, the following results in an error: On win32 VC2005: *sizeof(wchar_t) is 2* wchar_t *foo = 0; static_cast<unsigned short *>(foo); Results in error C2440: 'static_cast' : cannot convert from 'wchar_t *' to 'unsigned short *' ... On Mac OS X or Linux g++: *sizeof(wchar_t) is 4* wchar_t *fo...

C++, WCHAR[] to std::cout and comparision

Hi, I need to put WCHAR[] to std::cout ... It is a part of PWLAN_CONNECTION_NOTIFICATION_DATA passed from Native Wifi API callback. I tried simply std::cout << var; but it prints out the numeric address of first char. the comparision (var == L"some text") doesn't work either. The debugger returns the expected value, however the compari...

Outputting unicode characters in windows terminal

Over the past week I've been working on a roguelike game in C++ along with a friend. Mostly too learn the language. I'm using: pdcurses Windows 7 Visual studio C++ To output wchar_t's wherever I want to in the console. I have succeeded in otuputting some unicode characters such as \u263B (☻), but others such as \u2638 (☸) will just ...

How to make String to const wchar_t* conversion function work under Windows and Linux

Hi, I work on a project written for MSVCC / Windows, that I have to port to GCC / Linux. The Project has its own String Class, which stores its Data in a QString from Qt. For conversion to wchar_t* there was originally this method (for Windows): const wchar_t* String::c_str() const { if (length() > 0) { return (const wchar...

.c_str() weirdness? Data changes without rhyme or reason?

I have this simple function: const wchar_t *StringManager::GetWCharTStar(int stringId) { std::wstring originalString = StringManager::GetString(stringId); const wchar_t *retStr = originalString.c_str(); return retStr; } At the second line of that function, I have the correct wchar_t*. However, when I go to return, the dat...

How to convert concatenated strings to wide-char with the C preprocessor?

I am working on a project where I have many constant strings formed by concatenation (numbers, etc.). For example, I have a LOCATION macro that formats __FILE__ and __LINE__ into a string that I can use to know where I am in the code, when printing messages or errors: #define _STR(x) # x #define STR(x) _STR(x) #define LOCATION _...

Is wchar_t just a typedef of unsigned short?

for example, does: wchar_t x; translate to: unsigned short x; ...

C++: Is there any good way to read/write without specifically stating character type in function names? (cout vs wcout, etc)

I'm having a problem getting a program to read from a file based on a template, for example: bool parse(basic_ifstream<T> &file) { T ch; locale loc = file.getloc(); basic_string<T> buf; file.unsetf(ios_base::skipws); if (file.is_open()) { while (file >> ch) { if(isalnum(ch, loc)) ...

How I can print the wchar_t values to console?

Example: #include <iostream> using namespace std; int main() { wchar_t en[] = L"Hello"; wchar_t ru[] = L"Привет"; //Russian language cout << ru << endl << en; return 0; } This code only prints HEX-values like adress. How to print the wchar_t string? ...

How to copy a wchar_t into an NSString?

I'm using stringWithFormat @"%ls" to do it and I only see the first character copied, which makes me think it's still assuming it's a single byte char. Any ideas? ...