Click here to Skip to main content
16,014,591 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Get MX Record of a domain Pin
Tim Smith25-Dec-02 5:19
Tim Smith25-Dec-02 5:19 
QuestionWhat is the diffrence between MultiByteToWideChar() and mbstowcs()? Pin
wangdave24-Dec-02 23:30
wangdave24-Dec-02 23:30 
AnswerRe: What is the diffrence between MultiByteToWideChar() and mbstowcs()? Pin
Gero Gerber24-Dec-02 23:51
Gero Gerber24-Dec-02 23:51 
GeneralRe: What is the diffrence between MultiByteToWideChar() and mbstowcs()? Pin
wangdave24-Dec-02 23:59
wangdave24-Dec-02 23:59 
GeneralGet DOS Environment Variables Pin
Dominik Reichl24-Dec-02 23:29
Dominik Reichl24-Dec-02 23:29 
GeneralRe: Get DOS Environment Variables Pin
Gary R. Wheeler25-Dec-02 3:58
Gary R. Wheeler25-Dec-02 3:58 
GeneralRe: Get DOS Environment Variables Pin
Dominik Reichl26-Dec-02 3:15
Dominik Reichl26-Dec-02 3:15 
GeneralHelp about Unicode concept & functions! Pin
wangdave24-Dec-02 22:59
wangdave24-Dec-02 22:59 
Hi,
Merry Xmas!

I read some articles about Unicode in MSDN. But the sample code about Unicode function,mbstowcs(),in MSDN puzzled me.

The sample's URL:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt_mbstowcs.asp

My questions are:

1.In the sample code, I think return value of wcstombs()
and mbstowcs all should not be 1.
I think string L"Hi" should has 4 bytes, and the
corresponding MBCS string, "Hi", should
be 2 bytes.
2.The first char of MBCS string after call wcstombs()
should be 'H', while the sample output was 0x0e1a.
3.Unicode byte pointer, pwc, was only allocted one Unicode
char room for. But it received Unicode char string,
which had 2 Unicode chars,in function call mbstowcs().
4.Suppose we have a Unicode string, which has an English
char 'a' and a Chinese char '人'...

int k;
CString strTest = "a人";
wchar_t strMsg[100];
memset(strMsg,L'\0',sizeof(strMsg));
k = mbstowcs(NULL,(LPCTSTR)strTest, MB_CUR_MAX);
k = mbstowcs(strMsg,(LPCTSTR)strTest, MB_CUR_MAX);

a."k" value after first call of mbstowcs() is 3.
Why not 4?
b."k" value after second call of mbstowcs() is 1.
Why not 4 or 2?
And now, the Unicode string, strMsg, only has one
Unicode char, 97!(Watch in VC6/Debug).
Why?

Thanks.

============================================================
/* MBSTOWCS.CPP illustrates the behavior of the mbstowcs function
*/

#include <stdlib.h>
#include <stdio.h>

void main( void )
{
int i;
char *pmbnull = NULL;
char *pmbhello = (char *)malloc( MB_CUR_MAX );
wchar_t *pwchello = L"Hi";
wchar_t *pwc = (wchar_t *)malloc( sizeof( wchar_t ));

printf( "Convert to multibyte string:\n" );
i = wcstombs( pmbhello, pwchello, MB_CUR_MAX );
printf( "\tCharacters converted: %u\n", i );
printf( "\tHex value of first" );
printf( " multibyte character: %#.4x\n\n", pmbhello );

printf( "Convert back to wide-character string:\n" );
i = mbstowcs( pwc, pmbhello, MB_CUR_MAX );
printf( "\tCharacters converted: %u\n", i );
printf( "\tHex value of first" );
printf( " wide character: %#.4x\n\n", pwc );
}


Output

Convert to multibyte string:
Characters converted: 1
Hex value of first multibyte character: 0x0e1a

Convert back to wide-character string:
Characters converted: 1
Hex value of first wide character: 0x0e1e



============================================================
QuestionMay I use (LPBYTE)wcsMsg for a Unicode String? Pin
wangdave24-Dec-02 22:54
wangdave24-Dec-02 22:54 
AnswerRe: May I use (LPBYTE)wcsMsg for a Unicode String? Pin
Vagif Abilov25-Dec-02 1:13
professionalVagif Abilov25-Dec-02 1:13 
GeneralRe: May I use (LPBYTE)wcsMsg for a Unicode String? Pin
wangdave26-Dec-02 16:31
wangdave26-Dec-02 16:31 
GeneralFlicker reduction ! (Special thanks to mr Scott H. Settlemier ) Pin
HellShrimp4free24-Dec-02 22:34
HellShrimp4free24-Dec-02 22:34 
GeneralRe: Flicker reduction ! (Special thanks to mr Scott H. Settlemier ) Pin
Mike Nordell26-Dec-02 6:59
Mike Nordell26-Dec-02 6:59 
Generalinstalled graphic card Pin
Mazdak24-Dec-02 21:43
Mazdak24-Dec-02 21:43 
GeneralRe: installed graphic card Pin
Daniel Strigl24-Dec-02 23:11
Daniel Strigl24-Dec-02 23:11 
QuestionHow to catch even when a tab key is pressed ? Pin
Nguyen Huy Hung24-Dec-02 15:48
Nguyen Huy Hung24-Dec-02 15:48 
AnswerRe: How to catch even when a tab key is pressed ? Pin
Bartosz Bien25-Dec-02 11:56
Bartosz Bien25-Dec-02 11:56 
GeneralRe: How to catch even when a tab key is pressed ? Pin
Nguyen Huy Hung28-Dec-02 19:49
Nguyen Huy Hung28-Dec-02 19:49 
QuestionVC++ 6.0 on WinXP?? Pin
JoeSox24-Dec-02 15:02
JoeSox24-Dec-02 15:02 
AnswerRe: VC++ 6.0 on WinXP?? Pin
Michael Dunn24-Dec-02 18:25
sitebuilderMichael Dunn24-Dec-02 18:25 
GeneralRe: VC++ 6.0 on WinXP?? Pin
Neville Franks24-Dec-02 18:35
Neville Franks24-Dec-02 18:35 
GeneralRe: VC++ 6.0 on WinXP?? Pin
JoeSox24-Dec-02 18:45
JoeSox24-Dec-02 18:45 
GeneralRe: VC++ 6.0 on WinXP?? Pin
Neville Franks24-Dec-02 20:51
Neville Franks24-Dec-02 20:51 
GeneralRe: VC++ 6.0 on WinXP?? Pin
JoeSox24-Dec-02 18:39
JoeSox24-Dec-02 18:39 
GeneralRe: VC++ 6.0 on WinXP?? Pin
Michael Dunn24-Dec-02 19:17
sitebuilderMichael Dunn24-Dec-02 19:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.