Re: Working with LPCWSTR

Alan Gamboa <[email protected]> Tue, 15 Oct 2002 16:00:44 -0400
Newsgroups gmane.comp.windows.devel.oledb.devel
Message-ID <[email protected]>
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C27485.8C7301E0
Content-Type: text/plain;
        charset="iso-8859-1"

thanks,

this works to a point.

tracing through atldbcli.h, "wszCommand" contains the modified string;
however, after the following call (where it is creating the command and
setting the command text):

    hr = CreateCommand(session);

hr returns S_OK, but  "wszCommand" now contains "" - something blew it away.
still debugging now...

anyone have any idea why?

thanks.

Alan Gamboa
CCG Systems, Inc.

-----Original Message-----
From: Vagif Abilov [mailto:[email protected]]
Sent: Tuesday, October 15, 2002 1:41 PM
To: [email protected]
Subject: Re: [OLEDB_DEV] Working with LPCWSTR


First 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

 <http://www.contopronto.com/>
..................................
Vagif Abilov
Development team
 <mailto:[email protected]> [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.


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_001_01C27485.8C7301E0
Content-Type: text/html;
        charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>Working with LPCWSTR</TITLE>

<META content="MSHTML 6.00.2800.1106" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=155140220-15102002><FONT face=Arial color=#0000ff
size=2>thanks,</FONT></SPAN></DIV>
<DIV><SPAN class=155140220-15102002><FONT face=Arial color=#0000ff
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=155140220-15102002><FONT face=Arial color=#0000ff size=2>this
works to a point.</FONT></SPAN></DIV>
<DIV><SPAN class=155140220-15102002><FONT face=Arial color=#0000ff
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=155140220-15102002><FONT face=Arial color=#0000ff
size=2>tracing through atldbcli.h, "wszCommand" contains the modified string;
however, after the following call (where it is creating the command and setting
the command text):</FONT></SPAN></DIV>
<DIV><SPAN class=155140220-15102002>&nbsp;&nbsp;&nbsp; </SPAN></DIV>
<DIV><SPAN class=155140220-15102002>&nbsp;&nbsp;&nbsp; <FONT face=Arial
color=#0000ff size=2>hr = CreateCommand(session);</FONT></SPAN></DIV>
<DIV><SPAN class=155140220-15102002><FONT face=Arial color=#0000ff
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=155140220-15102002><FONT face=Arial color=#0000ff size=2>hr
returns S_OK, but&nbsp; "wszCommand" now contains "" - something blew it away.
still debugging now...</FONT></SPAN></DIV>
<DIV><SPAN class=155140220-15102002><FONT face=Arial color=#0000ff
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=155140220-15102002><FONT face=Arial color=#0000ff size=2>anyone
have any idea why?</FONT></SPAN></DIV>
<DIV><SPAN class=155140220-15102002><FONT face=Arial color=#0000ff
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=155140220-15102002><FONT face=Arial color=#0000ff
size=2>thanks.</FONT></SPAN></DIV>
<DIV><SPAN class=155140220-15102002><FONT face=Arial color=#0000ff
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=155140220-15102002><FONT face=Arial color=#0000ff size=2>Alan
Gamboa</FONT></SPAN></DIV>
<DIV><SPAN class=155140220-15102002><FONT face=Arial color=#0000ff size=2>CCG
Systems, Inc.</FONT></SPAN></DIV>
<BLOCKQUOTE>
  <DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma
  size=2>-----Original Message-----<BR><B>From:</B> Vagif Abilov
  [mailto:[email protected]]<BR><B>Sent:</B> Tuesday, October 15, 2002 1:41
  PM<BR><B>To:</B> [email protected]<BR><B>Subject:</B> Re:
  [OLEDB_DEV] Working with LPCWSTR<BR><BR></FONT></DIV>
  <DIV><FONT face=Arial color=#0000ff size=2><SPAN
  class=903133517-15102002>First of all, if ParseString takes an LPCWSTR
  parameter, you can't change it - LPCWSTR is a _const_ pointer to a wide
  character string.</SPAN></FONT></DIV>
  <DIV><FONT face=Arial color=#0000ff size=2><SPAN
  class=903133517-15102002>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).</SPAN></FONT></DIV>
  <DIV><FONT face=Arial color=#0000ff size=2><SPAN
  class=903133517-15102002>Third, why not let ParseString return a new string?
  Something like this:</SPAN></FONT></DIV>
  <DIV><FONT face=Arial color=#0000ff size=2><SPAN
  class=903133517-15102002></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial color=#0000ff size=2><SPAN
  class=903133517-15102002>inline&nbsp;CString ParseString(LPCWSTR
  pwszInput)</SPAN></FONT></DIV>
  <DIV><FONT face=Arial color=#0000ff size=2><SPAN
  class=903133517-15102002>{</SPAN></FONT></DIV>
  <DIV><FONT face=Arial color=#0000ff size=2><SPAN
  class=903133517-15102002>&nbsp;&nbsp;&nbsp; CString
  strOutput;</SPAN></FONT></DIV>
  <DIV><FONT face=Arial color=#0000ff size=2><SPAN
  class=903133517-15102002>&nbsp;&nbsp;&nbsp; // do
something</SPAN></FONT></DIV>
  <DIV><FONT face=Arial color=#0000ff size=2><SPAN
  class=903133517-15102002>&nbsp;&nbsp;&nbsp; return
  strOutput;</SPAN></FONT></DIV>
  <DIV><FONT face=Arial color=#0000ff size=2><SPAN
  class=903133517-15102002>}</SPAN></FONT></DIV>
  <DIV><FONT face=Arial color=#0000ff size=2></FONT>&nbsp;</DIV>
  <DIV><SPAN class=903133517-15102002><FONT face=Arial color=#0000ff size=2>Then
  if you need to convert return value to wide string, just call
  T2W(ParseString(L"some string")).</FONT></SPAN></DIV>
  <DIV><SPAN class=903133517-15102002><FONT face=Arial color=#0000ff
  size=2></FONT></SPAN>&nbsp;</DIV>
  <DIV><SPAN class=903133517-15102002><FONT face=Arial color=#0000ff size=2>Best
  regards</FONT></SPAN></DIV>
  <TABLE class=text borderColor=#ffffff cellSpacing=0 cellPadding=0 width=200
  bgColor=#ffffff border=0>
    <TBODY>
    <TR>
      <TD vAlign=top noWrap colSpan=3>&nbsp;</TD></TR>
    <TR>
      <TD vAlign=top noWrap colSpan=3><FONT color=#333399><FONT face=Arial
        color=#000000 size=2></FONT><FONT face=Arial color=#000000
        size=2></FONT><FONT face=Arial color=#000000 size=2></FONT><A
        href="http://www.contopronto.com/"></A></FONT></TD></TR>
    <TR>
      <TD vAlign=center noWrap colSpan=3><FONT
        color=#333399>..................................</FONT></TD></TR>
    <TR>
      <TD vAlign=center noWrap colSpan=3><B><FONT
        face="Verdana, Arial, Helvetica, sans-serif" color=#333399 size=1>Vagif
        Abilov </FONT></B></TD></TR>
    <TR>
      <TD vAlign=center noWrap colSpan=3><FONT
        face="Verdana, Arial, Helvetica, sans-serif" color=#333399
        size=1>Development team </FONT></TD></TR>
    <TR>
      <TD vAlign=center noWrap colSpan=3><A
        href="mailto:[email protected]"><FONT
        face="Verdana, Arial, Helvetica, sans-serif"
        size=1>[email protected]</FONT></A></TD></TR>
    <TR>
      <TD vAlign=center noWrap colSpan=3>&nbsp;</TD></TR>
    <TR>
      <TD vAlign=center noWrap width=31><FONT
        face="Verdana, Arial, Helvetica, sans-serif" color=#333399
        size=1>Tel:</FONT></TD>
      <TD vAlign=center noWrap width=33><FONT
        face="Verdana, Arial, Helvetica, sans-serif" color=#333399
        size=1>+47</FONT></TD>
      <TD vAlign=center noWrap width=160><FONT
        face="Verdana, Arial, Helvetica, sans-serif" color=#333399 size=1>23 33
        25 79</FONT></TD></TR>
    <TR>
      <TD vAlign=center noWrap width=31><FONT
        face="Verdana, Arial, Helvetica, sans-serif" color=#333399
        size=1>Mob:</FONT></TD>
      <TD vAlign=center noWrap width=33><FONT
        face="Verdana, Arial, Helvetica, sans-serif" color=#333399
        size=1>+47</FONT></TD>
      <TD vAlign=center noWrap width=160><FONT
        face="Verdana, Arial, Helvetica, sans-serif" color=#333399 size=1>928 21
        221</FONT></TD></TR>
    <TR>
      <TD vAlign=center noWrap width=31><FONT
        face="Verdana, Arial, Helvetica, sans-serif" color=#333399
        size=1>Fax:</FONT></TD>
      <TD vAlign=center noWrap width=33><FONT
        face="Verdana, Arial, Helvetica, sans-serif" color=#333399
        size=1>+47</FONT></TD>
      <TD vAlign=center noWrap width=160><FONT
        face="Verdana, Arial, Helvetica, sans-serif" color=#333399 size=1>23 33
        25 71</FONT></TD></TR>
    <TR>
      <TD vAlign=center noWrap colSpan=3><FONT
        color=#333399>..................................</FONT></TD></TR>
    <TR>
      <TD vAlign=center noWrap colSpan=3><FONT
        face="Verdana, Arial, Helvetica, sans-serif" color=#333399
        size=1>Contopronto AS</FONT></TD></TR>
    <TR>
      <TD vAlign=center noWrap colSpan=3><FONT
        face="Verdana, Arial, Helvetica, sans-serif" color=#333399
        size=1>Valkyriegaten 15</FONT></TD></TR>
    <TR>
      <TD vAlign=center noWrap colSpan=3 height=14><FONT
        face="Verdana, Arial, Helvetica, sans-serif" color=#333399 size=1>0366
        Oslo, Norway</FONT></TD></TR></TBODY></TABLE>
  <P><FONT face=Arial color=#0000ff size=2></FONT>&nbsp;</P>
  <P><FONT face=Arial color=#0000ff size=2></FONT>&nbsp;</P>
  <BLOCKQUOTE>
    <DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma
    size=2>-----Original Message-----<BR><B>From:</B> OLEDB_DEV
    [mailto:[email protected]]<B>On Behalf Of </B>Alan
    Gamboa<BR><B>Sent:</B> 15. oktober 2002 19:14<BR><B>To:</B>
    [email protected]<BR><B>Subject:</B> [OLEDB_DEV] Working with
    LPCWSTR<BR><BR></FONT></DIV>
    <P><FONT size=2>I am so used to manipulating CString and char[] variables, I
    am having problems working with LPCWSTR variables :)</FONT> </P>
    <P><FONT size=2>in my accessor i have</FONT> </P>
    <P><FONT size=2>MY_DEFINE_COMMAND_EX(CMyAccessor,L"SELECT blah,
    SUBSTRING(blah,1,1) FROM tblBlah")</FONT> </P>
    <P><FONT size=2>i have redefined DEFINE_COMMAND_EX as follows:</FONT> </P>
    <P><FONT size=2>#define MY_DEFINE_COMMAND_EX(x, wszCommand) \</FONT>
    <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT size=2>typedef x
    _CommandClass; \</FONT> <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT
    size=2>static HRESULT GetDefaultCommand(LPCWSTR* ppwszCommand) throw ()
    \</FONT> <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT size=2>{
    \</FONT> <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT
    size=2>ParseString(wszCommand); \</FONT>
    <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT size=2>*ppwszCommand =
    wszCommand; \</FONT> <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT size=2>return S_OK;
    \</FONT> <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT
    size=2>}</FONT> </P>
    <P><FONT size=2>here is ParseString():</FONT> </P>
    <P><FONT size=2>inline void ParseString(LPCWSTR wszCommand)</FONT> <BR><FONT
    size=2>{</FONT> <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT
    size=2>//what i want to do!</FONT>
    <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT size=2>CString s =
    wszCommand;</FONT> <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT
    size=2>s.Replace("SUBSTRING","SUBSTR");</FONT>
    <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT size=2>wszCommand =
    s;</FONT> <BR><FONT size=2>}</FONT> </P>
    <P><FONT size=2>I know the syntax above isn't exactly correct. Besides, I
    stepped through it and wszCommand does not come back out.</FONT> </P>
    <P><FONT size=2>any direction is appreciated.</FONT> </P>
    <P><FONT size=2>Alan Gamboa</FONT> <BR><FONT size=2>CCG Systems, Inc.</FONT>
    <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </P>You can read messages
    from the OLEDB_DEV archive, unsubscribe from OLEDB_DEV, or subscribe to
    other DevelopMentor lists at http://discuss.develop.com. </BLOCKQUOTE>You can
  read messages from the OLEDB_DEV archive, unsubscribe from OLEDB_DEV, or
  subscribe to other 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_001_01C27485.8C7301E0--