Re: WCHAR conversion problem
- From: Norbert Unterberg <nunterberg@xxxxxxxxxxxxxxxxx>
- Date: Wed, 27 Aug 2008 19:52:00 +0200
Hi,
Iñaki schrieb:
I need to convert a WCHAR[] to a char* but I don't know how can I do that. I'm not c++ expert... and I'm using an API with WCHARs...
It seems noone has hasked the most obvious questions yet:
1. What is the expected encoding of the char* you want to convert to?
2. Why do you need to convert anyway?
The background:
1. The times where you could assume that a char* is just a char* in terms of an ASCII string are long over. People use(d) tens/hundreds of different encodings for 7 or 8 bit character strings. The multibyte encoding from the mb* string functions is only one of many (I have never used it, I believe it was used for some asian countries but I might be wrong). That means: There is no such thing as plain text, and if you ask for text formats or conversins you always need to say what encoding you want to use.
2. For more than ten years now, Windows supports the unicode character set (WCHAR), and since Windows 98 is dead there is no need to use something else, ecxept for some very rare (or very old and not-yet-converted) applications. You ask for char*, so you seem to work on one of these. Is this true, or do you just don't know about Unicode?
What I need to convert is fileName of the following struct to a char*:
typedef struct _FbwfCacheDetail {
ULONG cacheSize; // size of cache used by the file
ULONG openHandleCount; // number of currently opened handles
ULONG fileNameLength; // file name length in bytes
WCHAR fileName[1]; // file name (may not be null-terminated)
} FbwfCacheDetail, *PFbwfCacheDetail;
I've tried the following:
char *FileName = (char *)malloc( MAX_FILENAME_LENGTH );
....
wcstombs_s(&wcharsConverted,FileName,MAX_FILENAME_LENGTH,Cache_detail->fileName,MAX_FILENAME_LENGTH);
where Cache_detail->fileName is suposed to contain fileName[], but FileName is empty while wcharsConverted seems to be OK.
Do you really need to convert to "multibyte" character set, or do you really mean ANSI or UTF-8 encoding?
Norbert
.
- Follow-Ups:
- Re: WCHAR conversion problem
- From: Alex Blekhman
- Re: WCHAR conversion problem
- References:
- WCHAR conversion problem
- From: Iñaki
- WCHAR conversion problem
- Prev by Date: Re: WCHAR conversion problem
- Next by Date: Re: Heap memory available (W32 console app in Visual C++)
- Previous by thread: Re: WCHAR conversion problem
- Next by thread: Re: WCHAR conversion problem
- Index(es):
Relevant Pages
|