Re: Working with LPCWSTR
Vagif Abilov <[email protected]> Tue, 15 Oct 2002 19:40:36 +0200
| Newsgroups | gmane.comp.windows.devel.oledb.devel |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
------=_NextPart_000_01F4_01C27482.BBCDEA80
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Working with LPCWSTRFirst of all, if ParseString takes an LPCWSTR parameter,
you can't change it - LPCWSTR is a _const_ pointer to a wide character
string.
Second, if your intention is to modify the string, on return you will get
another string, you can use LPWSTR either, it must be LPWSTR* (pointer to
pointer).
Third, why not let ParseString return a new string? Something like this:
inline CString ParseString(LPCWSTR pwszInput)
{
CString strOutput;
// do something
return strOutput;
}
Then if you need to convert return value to wide string, just call
T2W(ParseString(L"some string")).
Best regards
..................................
Vagif Abilov
Development team
[email protected]
Tel: +47 23 33 25 79
Mob: +47 928 21 221
Fax: +47 23 33 25 71
..................................
Contopronto AS
Valkyriegaten 15
0366 Oslo, Norway
-----Original Message-----
From: OLEDB_DEV [mailto:[email protected]]On Behalf Of Alan
Gamboa
Sent: 15. oktober 2002 19:14
To: [email protected]
Subject: [OLEDB_DEV] Working with LPCWSTR
I am so used to manipulating CString and char[] variables, I am having
problems working with LPCWSTR variables :)
in my accessor i have
MY_DEFINE_COMMAND_EX(CMyAccessor,L"SELECT blah, SUBSTRING(blah,1,1) FROM
tblBlah")
i have redefined DEFINE_COMMAND_EX as follows:
#define MY_DEFINE_COMMAND_EX(x, wszCommand) \
typedef x _CommandClass; \
static HRESULT GetDefaultCommand(LPCWSTR* ppwszCommand) throw () \
{ \
ParseString(wszCommand); \
*ppwszCommand = wszCommand; \
return S_OK; \
}
here is ParseString():
inline void ParseString(LPCWSTR wszCommand)
{
//what i want to do!
CString s = wszCommand;
s.Replace("SUBSTRING","SUBSTR");
wszCommand = s;
}
I know the syntax above isn't exactly correct. Besides, I stepped through
it and wszCommand does not come back out.
any direction is appreciated.
Alan Gamboa
CCG Systems, Inc.
You can read messages from the OLEDB_DEV archive, unsubscribe from
OLEDB_DEV, or subscribe to other DevelopMentor lists at
http://discuss.develop.com.
You can read messages from the OLEDB_DEV archive, unsubscribe from OLEDB_DEV,
or subscribe to other DevelopMentor lists at http://discuss.develop.com.
------=_NextPart_000_01F4_01C27482.BBCDEA80
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Working with LPCWSTR</TITLE>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2719.2200" name=3DGENERATOR></HEAD>
<BODY>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN =
class=3D903133517-15102002>First=20
of all, if ParseString takes an LPCWSTR parameter, you can't change it - =
LPCWSTR=20
is a _const_ pointer to a wide character string.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20
class=3D903133517-15102002>Second, if your intention is to modify the =
string, on=20
return you will get another string, you can use LPWSTR either, it must =
be=20
LPWSTR* (pointer to pointer).</SPAN></FONT></DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN =
class=3D903133517-15102002>Third,=20
why not let ParseString return a new string? Something like=20
this:</SPAN></FONT></DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20
class=3D903133517-15102002></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20
class=3D903133517-15102002>inline CString ParseString(LPCWSTR=20
pwszInput)</SPAN></FONT></DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20
class=3D903133517-15102002>{</SPAN></FONT></DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20
class=3D903133517-15102002> CString=20
strOutput;</SPAN></FONT></DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20
class=3D903133517-15102002> // do =
something</SPAN></FONT></DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20
class=3D903133517-15102002> return=20
strOutput;</SPAN></FONT></DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20
class=3D903133517-15102002>}</SPAN></FONT></DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2></FONT> </DIV>
<DIV><SPAN class=3D903133517-15102002><FONT face=3DArial color=3D#0000ff =
size=3D2>Then=20
if you need to convert return value to wide string, just call=20
T2W(ParseString(L"some string")).</FONT></SPAN></DIV>
<DIV><SPAN class=3D903133517-15102002><FONT face=3DArial color=3D#0000ff =
size=3D2></FONT></SPAN> </DIV>
<DIV><SPAN class=3D903133517-15102002><FONT face=3DArial color=3D#0000ff =
size=3D2>Best=20
regards</FONT></SPAN></DIV>
<TABLE class=3Dtext borderColor=3D#ffffff cellSpacing=3D0 =
cellPadding=3D0 width=3D200=20
bgColor=3D#ffffff border=3D0>
<TBODY>
<TR>
<TD vAlign=3Dtop noWrap colSpan=3D3> </TD></TR>
<TR>
<TD vAlign=3Dtop noWrap colSpan=3D3><FONT color=3D#333399><FONT =
face=3DArial=20
color=3D#000000 size=3D2></FONT><FONT face=3DArial color=3D#000000 =
size=3D2></FONT><FONT face=3DArial color=3D#000000 =
size=3D2></FONT><A=20
href=3D"http://www.contopronto.com/"></A></FONT></TD></TR>
<TR>
<TD vAlign=3Dcenter noWrap colSpan=3D3><FONT=20
=
color=3D#333399>..................................</FONT></TD></TR>
<TR>
<TD vAlign=3Dcenter noWrap colSpan=3D3><B><FONT=20
face=3D"Verdana, Arial, Helvetica, sans-serif" color=3D#333399 =
size=3D1>Vagif=20
Abilov </FONT></B></TD></TR>
<TR>
<TD vAlign=3Dcenter noWrap colSpan=3D3><FONT=20
face=3D"Verdana, Arial, Helvetica, sans-serif" color=3D#333399=20
size=3D1>Development team </FONT></TD></TR>
<TR>
<TD vAlign=3Dcenter noWrap colSpan=3D3><A=20
href=3D"mailto:[email protected]"><FONT=20
face=3D"Verdana, Arial, Helvetica, sans-serif"=20
size=3D1>[email protected]</FONT></A></TD></TR>
<TR>
<TD vAlign=3Dcenter noWrap colSpan=3D3> </TD></TR>
<TR>
<TD vAlign=3Dcenter noWrap width=3D31><FONT=20
face=3D"Verdana, Arial, Helvetica, sans-serif" color=3D#333399=20
size=3D1>Tel:</FONT></TD>
<TD vAlign=3Dcenter noWrap width=3D33><FONT=20
face=3D"Verdana, Arial, Helvetica, sans-serif" color=3D#333399=20
size=3D1>+47</FONT></TD>
<TD vAlign=3Dcenter noWrap width=3D160><FONT=20
face=3D"Verdana, Arial, Helvetica, sans-serif" color=3D#333399 =
size=3D1>23 33 25=20
79</FONT></TD></TR>
<TR>
<TD vAlign=3Dcenter noWrap width=3D31><FONT=20
face=3D"Verdana, Arial, Helvetica, sans-serif" color=3D#333399=20
size=3D1>Mob:</FONT></TD>
<TD vAlign=3Dcenter noWrap width=3D33><FONT=20
face=3D"Verdana, Arial, Helvetica, sans-serif" color=3D#333399=20
size=3D1>+47</FONT></TD>
<TD vAlign=3Dcenter noWrap width=3D160><FONT=20
face=3D"Verdana, Arial, Helvetica, sans-serif" color=3D#333399 =
size=3D1>928 21=20
221</FONT></TD></TR>
<TR>
<TD vAlign=3Dcenter noWrap width=3D31><FONT=20
face=3D"Verdana, Arial, Helvetica, sans-serif" color=3D#333399=20
size=3D1>Fax:</FONT></TD>
<TD vAlign=3Dcenter noWrap width=3D33><FONT=20
face=3D"Verdana, Arial, Helvetica, sans-serif" color=3D#333399=20
size=3D1>+47</FONT></TD>
<TD vAlign=3Dcenter noWrap width=3D160><FONT=20
face=3D"Verdana, Arial, Helvetica, sans-serif" color=3D#333399 =
size=3D1>23 33 25=20
71</FONT></TD></TR>
<TR>
<TD vAlign=3Dcenter noWrap colSpan=3D3><FONT=20
=
color=3D#333399>..................................</FONT></TD></TR>
<TR>
<TD vAlign=3Dcenter noWrap colSpan=3D3><FONT=20
face=3D"Verdana, Arial, Helvetica, sans-serif" color=3D#333399=20
size=3D1>Contopronto AS</FONT></TD></TR>
<TR>
<TD vAlign=3Dcenter noWrap colSpan=3D3><FONT=20
face=3D"Verdana, Arial, Helvetica, sans-serif" color=3D#333399=20
size=3D1>Valkyriegaten 15</FONT></TD></TR>
<TR>
<TD vAlign=3Dcenter noWrap colSpan=3D3 height=3D14><FONT=20
face=3D"Verdana, Arial, Helvetica, sans-serif" color=3D#333399 =
size=3D1>0366=20
Oslo, Norway</FONT></TD></TR></TBODY></TABLE>
<P><FONT face=3DArial color=3D#0000ff size=3D2></FONT> </P>
<P><FONT face=3DArial color=3D#0000ff size=3D2></FONT> </P>
<BLOCKQUOTE>
<DIV class=3DOutlookMessageHeader dir=3Dltr align=3Dleft><FONT =
face=3DTahoma=20
size=3D2>-----Original Message-----<BR><B>From:</B> OLEDB_DEV=20
[mailto:[email protected]]<B>On Behalf Of </B>Alan=20
Gamboa<BR><B>Sent:</B> 15. oktober 2002 19:14<BR><B>To:</B>=20
[email protected]<BR><B>Subject:</B> [OLEDB_DEV] Working =
with=20
LPCWSTR<BR><BR></FONT></DIV>
<P><FONT size=3D2>I am so used to manipulating CString and char[] =
variables, I=20
am having problems working with LPCWSTR variables :)</FONT> </P>
<P><FONT size=3D2>in my accessor i have</FONT> </P>
<P><FONT size=3D2>MY_DEFINE_COMMAND_EX(CMyAccessor,L"SELECT blah,=20
SUBSTRING(blah,1,1) FROM tblBlah")</FONT> </P>
<P><FONT size=3D2>i have redefined DEFINE_COMMAND_EX as =
follows:</FONT> </P>
<P><FONT size=3D2>#define MY_DEFINE_COMMAND_EX(x, wszCommand) \</FONT> =
<BR> <FONT size=3D2>typedef =
x=20
_CommandClass; \</FONT> <BR> =
<FONT=20
size=3D2>static HRESULT GetDefaultCommand(LPCWSTR* ppwszCommand) throw =
()=20
\</FONT> <BR> <FONT =
size=3D2>{=20
\</FONT> <BR> =20
<FONT=20
size=3D2>ParseString(wszCommand); \</FONT>=20
<BR> =20
<FONT =
size=3D2>*ppwszCommand =3D=20
wszCommand; \</FONT> <BR> =20
<FONT size=3D2>return S_OK; =
\</FONT>=20
<BR> <FONT size=3D2>}</FONT> =
</P>
<P><FONT size=3D2>here is ParseString():</FONT> </P>
<P><FONT size=3D2>inline void ParseString(LPCWSTR wszCommand)</FONT> =
<BR><FONT=20
size=3D2>{</FONT> <BR> <FONT =
size=3D2>//what i want to do!</FONT>=20
<BR> <FONT size=3D2>CString =
s =3D=20
wszCommand;</FONT> <BR> =
<FONT=20
size=3D2>s.Replace("SUBSTRING","SUBSTR");</FONT>=20
<BR> <FONT =
size=3D2>wszCommand =3D=20
s;</FONT> <BR><FONT size=3D2>}</FONT> </P>
<P><FONT size=3D2>I know the syntax above isn't exactly correct. =
Besides, I=20
stepped through it and wszCommand does not come back out.</FONT> </P>
<P><FONT size=3D2>any direction is appreciated.</FONT> </P>
<P><FONT size=3D2>Alan Gamboa</FONT> <BR><FONT size=3D2>CCG Systems, =
Inc.</FONT>=20
<BR> </P>You can read =
messages from=20
the OLEDB_DEV archive, unsubscribe from OLEDB_DEV, or subscribe to =
other=20
DevelopMentor lists at http://discuss.develop.com. =
</BLOCKQUOTE></BODY></HTML>
You can read messages from the OLEDB_DEV archive, unsubscribe from OLEDB_DEV,
or subscribe to other DevelopMentor lists at http://discuss.develop.com.
------=_NextPart_000_01F4_01C27482.BBCDEA80--