char * convert to LPCWSTR

  • Thread starter Michael Breidenstein
  • Start date
M

Michael Breidenstein

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
 
M

Martin Gieseking

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
 
A

Alf P. Steinbach

* 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.
 
H

Howard

Michael Breidenstein said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top