Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Convert LPWSTR to char?

2,287 views
Skip to first unread message

Dave McZui

unread,
Feb 4, 2003, 7:57:34 PM2/4/03
to
Hello!

My app uses a function that has a LPWSTR as
parameter.After calling this function, I need to convert
this LPWSTR to an array of char.
Example:
LPWSTR lpStr;
char cTest[200];

foo(lpStr,200); //returns a result in lpStr

cTest=lpStr; //here I don't know how convert LPWSTR to char

Can someone please help me? I already checked
WideCharToMultiByte, but I don't know if its the right way
as I can't convert it with this function either (I always
get a Systemerror 1004). Thanks to all!

Junkie

unread,
Feb 5, 2003, 3:07:01 PM2/5/03
to
Check out. wcstombs(). It works like this:

LPWSTR w = L"Hello";
char c[10] = {0};
wcstombs(c, w, wcslen(w));

- Junkie

"Dave McZui" <da...@spam.com> wrote in message
news:04df01c2ccb1$91cb6960$d4f82ecf@TK2MSFTNGXA11...


> Hello!
>
> My app uses a function that has a LPWSTR as
> parameter.After calling this function, I need to convert
> this LPWSTR to an array of char.
> Example:
> LPWSTR lpStr;
> char cTest[200];
>

> foo(lpStr,200); file://returns a result in lpStr
>
> cTest=lpStr; file://here I don't know how convert LPWSTR to char

Kyle Alons

unread,
Feb 5, 2003, 7:21:25 AM2/5/03
to
USES_CONVERSION;
strncpy(cTest, W2CA(lpStr), sizeof(cTest));

"Dave McZui" <da...@spam.com> wrote in message
news:04df01c2ccb1$91cb6960$d4f82ecf@TK2MSFTNGXA11...

Kobi Ben Tzvi

unread,
Feb 7, 2003, 6:37:40 AM2/7/03
to
Hello Dave,

Its helpful to check what error code means.
In VC++ choose "Tools menu -> Error Lookup" then write the error code you
got. This will make things more clear for you, for example the error code
you got(1004) means "Invalid flags." so obviously you used wrong flags when
calling WideCharToMultiByte.

--
Regards,
Kobi Ben Tzvi


"Dave McZui" <da...@spam.com> wrote in message
news:04df01c2ccb1$91cb6960$d4f82ecf@TK2MSFTNGXA11...

0 new messages