一个非常简单的问题关于char*和wchar*
大家好,我想把char*类型的变量转换成wchar*类型
具体如下: char *l= "........ ";
WCHAR * TTS=???l
我希望把l的值变为tts中
谢谢大家
[解决办法]
typedef wchar_t WCHAR;
char*的值先赋给_variant_t类型的变量然后在赋给wchar_t *
[解决办法]
int MultiByteToWideChar
好象可以。..
[解决办法]
mbstowcs()
convert multibyte string to wide character string
Function
SYNOPSIS
#include <stdlib.h>
size_t mbstowcs(wchar_t *pwcs, const char *s, size_t n);
DESCRIPTION
The mbstowcs() function converts the multibyte string addressed by s into the corresponding UNICODE string. It stores up to n wide characters in pwcs. It stops conversion after encountering and storing a null character.
PARAMETERS
pwcs
Is the address of an array of wide characters, type wchar_t, to receive the UNICODE equivalent of multibyte string s.
s
Points to a null-terminated multibyte string to be converted to UNICODE.
n
Is the maximum number of characters to convert and store in pwcs.
RETURN VALUES
If successful, mbstowcs() returns the number of multibyte characters it converted, not including the terminating null character. If s is a null pointer or points to a null character, mbstowcs() returns zero. If mbstowcs() encounters an invalid multibyte sequence, it returns -1.
CONFORMANCE
ANSI/ISO 9899-1990.
MULTITHREAD SAFETY LEVEL
MT-Safe, with exceptions.
This function is MT-Safe as long as no thread calls setlocale() while this function is executing.
[解决办法]
比如:
#define LENGTH 100
wchar_t *w_str = new wchar_t[LENGTH];
string test = "this is a test ";
mbstowcs( w_str, test.c_str(), test.size() );
[解决办法]
MultiByteToWideChar 是 win API, 参数相当复杂,
楼主自己看看 MSDN 吧······