By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,144 Members | 1,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,144 IT Pros & Developers. It's quick & easy.

char * convert to LPCWSTR

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
> 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

P: n/a
* 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

P: n/a

"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.