471,071 Members | 6,743 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,071 software developers and data experts.

char * convert to LPCWSTR

Hi,

anybody can help me to convert a "char *" to LPCWSTR with the following
function:

LPCWSTR charP2LPCWSTR(char *szText){

LPCWSTR tmp;

tmp=szText; // At this point I need help

return tmp;

}

Thanks
Jul 23 '05 #1
3 29378
> anybody can help me to convert a "char *" to LPCWSTR with the following
function:

LPCWSTR charP2LPCWSTR(char *szText){
LPCWSTR tmp;
tmp=szText; // At this point I need help
return tmp;
}

What is LPCWSTR? There is no such type in C or C++.

Martin
Jul 23 '05 #2
* Michael Breidenstein:

anybody can help me to convert a "char *" to LPCWSTR with the following
function:

LPCWSTR charP2LPCWSTR(char *szText){

LPCWSTR tmp;

tmp=szText; // At this point I need help

return tmp;

}


As you may or may not know, LPCWSTR is _not_ a standard C++ type, so a
discussion of its usage is off-topic in this group.

However, assuming it is a type¹, then your function design seems a bit
dubious.

The argument is a char* pointer, which means the caller might modify
that string, and can/should not call the function with a string literal
or other constant string. If the "C" in LPCWSTR indicates "constant",
then that seems to be a needless restriction, which should be fixed by
declaring the argument as "char const*". On the other hand, if the
LPCWSTR type is not logically constant², then how is the original string
supposed to be updated to reflect changes done via the function result?
¹) I'm just presenting an on-topic argument here. For more detailed
answers you might ask in e.g. [comp.os.ms-windows.programmer.win32].

²) Again, I'm presenting an on-topic argument, ignoring that in all
likelyhood your LPCWSTR type is the same one as in the Win32 API.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #3

"Michael Breidenstein" <mi*****@datamac.de> wrote in message
news:42**********************@news.freenet.de...
Hi,

anybody can help me to convert a "char *" to LPCWSTR with the following
function:

LPCWSTR charP2LPCWSTR(char *szText){

LPCWSTR tmp;

tmp=szText; // At this point I need help

return tmp;

}


LPCWSTR is a microsoft-defined type (a "long pointer to constant wide
string", if I recall). If you need help creating or copying wide strings
using the microsoft data types, then you need to ask in a ms newsgroup. But
when you do, you should clarify exactly what you're trying to do: copy the
pointer, cast the pointer, or copy the array of char to another array, (such
as one of the ms type WCHAR). My guess is there's already a ms-provided
function for doing this kind of thing.

-Howard


Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Maileen | last post: by
4 posts views Thread by sweety | last post: by
2 posts views Thread by Alejandro Aleman | last post: by
7 posts views Thread by nicolas.hilaire | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.