MultiByteToWideChar converting %[code]... erf...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert Diamond

    MultiByteToWideChar converting %[code]... erf...

    Hi ppl, just a quick question...

    I need to use "MultiByteToWid eChar(stuff)" to convert a char[MAX_PATH] to
    unicode, so that OleLoadPictureP ath can get the image files i want, and load
    it into a HBITMAP, etc... I'm having trouble when my char[MAX_PATH] has a
    %[code], for example:

    "C:\Image\m y image.bmp" is translated to the unicode equivalent, without
    problems

    "C:\Image\my%20 image.bmp" is translated to the unicode equivalent of
    "C:\Image\m y image.bmp"

    So i want to send in a path string to MultiByteToWide Char(stuff) which might
    have %[code] in it, and I want MultiByteToWide Char() to ignor the %[code],
    in other words:

    something() {
    char sPath[MAX_PATH];
    OLECHAR sUniPath[MAX_PATH + 1];

    // This is the first (and working) string
    strcpy(sPath, "C:\image file.bmp");
    MultiByteToWide Char(CP_ACP, MB_PRECOMPOSED, sPath, -1, sUniPath,
    MAX_PATH);
    // sUniPath is the unicode for "C:\image file.bmp"
    }

    something() {
    char sPath[MAX_PATH];
    OLECHAR sUniPath[MAX_PATH + 1];

    // This is the second (and NOT working) string
    strcpy(sPath, "C:\image%20fil e.bmp");
    MultiByteToWide Char(CP_ACP, MB_PRECOMPOSED, sPath, -1, sUniPath,
    MAX_PATH);
    // sUniPath is the unicode for "C:\image file.bmp"... erf... I want it
    to be the unicode for "C:\image%20fil e.bmp"...
    }

    I've tried to read up at msdn on MultiByteToWide Char, but I couldn't find
    the params to do this (or just can't read the docs as well as some of you
    people ~.0 ). If any of you know what i'm doing wrong, or know of a
    different call to convert to unicode, please give me the info ;) I've hurd
    that MultiByteToWide Char is the subject of overflows, so maybe finding a
    different call would be best. Thanks in advance ;)


  • John Carson

    #2
    Re: MultiByteToWide Char converting %[code]... erf...

    "Robert Diamond" <-rob-@anti.spam.com> wrote in message
    news:IWRdc.2463 6$PV5.1136@news 04.bloor.is.net .cable.rogers.c om[color=blue]
    > Hi ppl, just a quick question...
    >
    > I need to use "MultiByteToWid eChar(stuff)" to convert a
    > char[MAX_PATH] to unicode, so that OleLoadPictureP ath can get the
    > image files i want, and load it into a HBITMAP, etc... I'm having
    > trouble when my char[MAX_PATH] has a %[code], for example:
    >
    > "C:\Image\m y image.bmp" is translated to the unicode equivalent,
    > without problems
    >
    > "C:\Image\my%20 image.bmp" is translated to the unicode equivalent of
    > "C:\Image\m y image.bmp"
    >
    > So i want to send in a path string to MultiByteToWide Char(stuff)
    > which might have %[code] in it, and I want MultiByteToWide Char() to
    > ignor the %[code], in other words:
    >
    > something() {
    > char sPath[MAX_PATH];
    > OLECHAR sUniPath[MAX_PATH + 1];
    >
    > // This is the first (and working) string
    > strcpy(sPath, "C:\image file.bmp");
    > MultiByteToWide Char(CP_ACP, MB_PRECOMPOSED, sPath, -1, sUniPath,
    > MAX_PATH);
    > // sUniPath is the unicode for "C:\image file.bmp"
    > }
    >
    > something() {
    > char sPath[MAX_PATH];
    > OLECHAR sUniPath[MAX_PATH + 1];
    >
    > // This is the second (and NOT working) string
    > strcpy(sPath, "C:\image%20fil e.bmp");
    > MultiByteToWide Char(CP_ACP, MB_PRECOMPOSED, sPath, -1, sUniPath,
    > MAX_PATH);
    > // sUniPath is the unicode for "C:\image file.bmp"... erf... I
    > want it to be the unicode for "C:\image%20fil e.bmp"...
    > }
    >[/color]

    You have attempted to post this to four newsgroups, two of which don't
    exist. It is off-topic in this one (comp.lang.c++) since it is Microsoft
    specific. You might try, e.g.,

    microsoft.publi c.vc.language
    or
    comp.os.ms-windows.program mer.win32

    I ran your code out of interest and the % came through fine. The error I
    found was in your backslash. A backslash is entered into code with a double
    backslash, i.e., '\\'. The first three characters in

    "C:\image%20fil e.bmp"

    are 'C', ':' and '\i'. Since there is no '\i' character, this produces
    undefined behaviour. You should use:

    "C:\\image%20fi le.bmp"


    --
    John Carson
    1. To reply to email address, remove donald
    2. Don't reply to email address (post here instead)

    Comment

    • John Carson

      #3
      Re: MultiByteToWide Char converting %[code]... erf...

      "Robert Diamond" <-rob-@anti.spam.com> wrote in message
      news:IWRdc.2463 6$PV5.1136@news 04.bloor.is.net .cable.rogers.c om[color=blue]
      > Hi ppl, just a quick question...
      >
      > I need to use "MultiByteToWid eChar(stuff)" to convert a
      > char[MAX_PATH] to unicode, so that OleLoadPictureP ath can get the
      > image files i want, and load it into a HBITMAP, etc... I'm having
      > trouble when my char[MAX_PATH] has a %[code], for example:
      >
      > "C:\Image\m y image.bmp" is translated to the unicode equivalent,
      > without problems
      >
      > "C:\Image\my%20 image.bmp" is translated to the unicode equivalent of
      > "C:\Image\m y image.bmp"
      >
      > So i want to send in a path string to MultiByteToWide Char(stuff)
      > which might have %[code] in it, and I want MultiByteToWide Char() to
      > ignor the %[code], in other words:
      >
      > something() {
      > char sPath[MAX_PATH];
      > OLECHAR sUniPath[MAX_PATH + 1];
      >
      > // This is the first (and working) string
      > strcpy(sPath, "C:\image file.bmp");
      > MultiByteToWide Char(CP_ACP, MB_PRECOMPOSED, sPath, -1, sUniPath,
      > MAX_PATH);
      > // sUniPath is the unicode for "C:\image file.bmp"
      > }
      >
      > something() {
      > char sPath[MAX_PATH];
      > OLECHAR sUniPath[MAX_PATH + 1];
      >
      > // This is the second (and NOT working) string
      > strcpy(sPath, "C:\image%20fil e.bmp");
      > MultiByteToWide Char(CP_ACP, MB_PRECOMPOSED, sPath, -1, sUniPath,
      > MAX_PATH);
      > // sUniPath is the unicode for "C:\image file.bmp"... erf... I
      > want it to be the unicode for "C:\image%20fil e.bmp"...
      > }
      >[/color]

      You have attempted to post this to four newsgroups, two of which don't
      exist. It is off-topic in this one (comp.lang.c++) since it is Microsoft
      specific. You might try, e.g.,

      microsoft.publi c.vc.language
      or
      comp.os.ms-windows.program mer.win32

      I ran your code out of interest and the % came through fine. The error I
      found was in your backslash. A backslash is entered into code with a double
      backslash, i.e., '\\'. The first three characters in

      "C:\image%20fil e.bmp"

      are 'C', ':' and '\i'. Since there is no '\i' character, this produces
      undefined behaviour. You should use:

      "C:\\image%20fi le.bmp"


      --
      John Carson
      1. To reply to email address, remove donald
      2. Don't reply to email address (post here instead)

      Comment

      • Robert Diamond

        #4
        Re: MultiByteToWide Char converting %[code]... erf...


        "John Carson" <donaldquixote@ datafast.net.au > wrote in message
        news:407841b3$1 @usenet.per.par adox.net.au...[color=blue]
        >
        > You have attempted to post this to four newsgroups, two of which don't
        > exist. It is off-topic in this one (comp.lang.c++) since it is Microsoft
        > specific. You might try, e.g.,
        >
        > microsoft.publi c.vc.language
        > or
        > comp.os.ms-windows.program mer.win32[/color]

        The two that don't exist, exist on my nntp server...

        I did post to two m$ vc newgroups
        [color=blue]
        > I ran your code out of interest and the % came through fine. The error I
        > found was in your backslash. A backslash is entered into code with a[/color]
        double[color=blue]
        > backslash, i.e., '\\'. The first three characters in
        >
        > "C:\image%20fil e.bmp"
        >
        > are 'C', ':' and '\i'. Since there is no '\i' character, this produces
        > undefined behaviour. You should use:
        >
        > "C:\\image%20fi le.bmp"[/color]

        I forgot to add the escape code in the post... not in my code....

        the %[code] does come through... it comes through decoded... ie:
        "something\\som e%20thing" turns into unicode for "something\\som e thing".
        Notice the space... the %[code] was decoded, and i don't want it to... i
        want "something\\som e%20thing" to turn into unicode for
        "something\\som e%20thing" (Notice the "%20" and not the ' ' <space> char).
        [color=blue]
        >
        > --
        > John Carson
        > 1. To reply to email address, remove donald
        > 2. Don't reply to email address (post here instead)
        >[/color]

        you forgot to reply to the new group i specified... ie: n00b, know before
        you flame, and if you flame, flame to the news group i specified as the
        reply-to group!


        Comment

        • Robert Diamond

          #5
          Re: MultiByteToWide Char converting %[code]... erf...


          "John Carson" <donaldquixote@ datafast.net.au > wrote in message
          news:407841b3$1 @usenet.per.par adox.net.au...[color=blue]
          >
          > You have attempted to post this to four newsgroups, two of which don't
          > exist. It is off-topic in this one (comp.lang.c++) since it is Microsoft
          > specific. You might try, e.g.,
          >
          > microsoft.publi c.vc.language
          > or
          > comp.os.ms-windows.program mer.win32[/color]

          The two that don't exist, exist on my nntp server...

          I did post to two m$ vc newgroups
          [color=blue]
          > I ran your code out of interest and the % came through fine. The error I
          > found was in your backslash. A backslash is entered into code with a[/color]
          double[color=blue]
          > backslash, i.e., '\\'. The first three characters in
          >
          > "C:\image%20fil e.bmp"
          >
          > are 'C', ':' and '\i'. Since there is no '\i' character, this produces
          > undefined behaviour. You should use:
          >
          > "C:\\image%20fi le.bmp"[/color]

          I forgot to add the escape code in the post... not in my code....

          the %[code] does come through... it comes through decoded... ie:
          "something\\som e%20thing" turns into unicode for "something\\som e thing".
          Notice the space... the %[code] was decoded, and i don't want it to... i
          want "something\\som e%20thing" to turn into unicode for
          "something\\som e%20thing" (Notice the "%20" and not the ' ' <space> char).
          [color=blue]
          >
          > --
          > John Carson
          > 1. To reply to email address, remove donald
          > 2. Don't reply to email address (post here instead)
          >[/color]

          you forgot to reply to the new group i specified... ie: n00b, know before
          you flame, and if you flame, flame to the news group i specified as the
          reply-to group!


          Comment

          • Kevin Goodsell

            #6
            Re: MultiByteToWide Char converting %[code]... erf...

            Robert Diamond wrote:
            [color=blue]
            >
            > you forgot to reply to the new group i specified... ie: n00b, know before
            > you flame, and if you flame, flame to the news group i specified as the
            > reply-to group!
            >
            >[/color]

            Being rude (first by OT posting + mass cross-posting, then with this) is
            a poor way to get help. Goodbye.

            *PLONK*

            -Kevin
            --
            My email address is valid, but changes periodically.
            To contact me please use the address from a recent posting.

            Comment

            • Kevin Goodsell

              #7
              Re: MultiByteToWide Char converting %[code]... erf...

              Robert Diamond wrote:
              [color=blue]
              >
              > you forgot to reply to the new group i specified... ie: n00b, know before
              > you flame, and if you flame, flame to the news group i specified as the
              > reply-to group!
              >
              >[/color]

              Being rude (first by OT posting + mass cross-posting, then with this) is
              a poor way to get help. Goodbye.

              *PLONK*

              -Kevin
              --
              My email address is valid, but changes periodically.
              To contact me please use the address from a recent posting.

              Comment

              • John Carson

                #8
                Re: MultiByteToWide Char converting %[code]... erf...

                "Robert Diamond" <-rob-@anti.spam.com> wrote in message
                news:M2eec.2958 5$0Qw.8834@news 04.bloor.is.net .cable.rogers.c om[color=blue]
                >
                >
                > the %[code] does come through... it comes through decoded... ie:
                > "something\\som e%20thing" turns into unicode for "something\\som e
                > thing". Notice the space... the %[code] was decoded, and i don't want
                > it to... i want "something\\som e%20thing" to turn into unicode for
                > "something\\som e%20thing" (Notice the "%20" and not the ' ' <space>
                > char).[/color]

                It doesn't come through decoded for me. It comes through with the %20
                intact. Since you are apparently retyping your code into the post rather
                than copying and pasting, it is anyone's guess what is going wrong. Perhaps
                the conversion is working but the method that you are using to display the
                string is what is causing the space. But that is just a guess.
                [color=blue]
                > you forgot to reply to the new group i specified... ie: n00b, know
                > before you flame, and if you flame, flame to the news group i
                > specified as the reply-to group![/color]

                You have a rather liberal definition of flame. I initially attempted to post
                my reply using the default reply procedure, which meant posting to
                microsoft.publi c.vc, as you had specified. I got an error and so manually
                modified the reply field to a newsgroup that I knew did exist.

                If I connect directly to the microsoft news server, msnews.microsof t.news,
                using Outlook Express, then microsoft.publi c.vc is *not* listed. It is also
                not on the news server of my ISP. I have, upon receiving your reply, found
                it on another news server (I still can't find alt.comp.lang.c ++ anywhere,
                though there is an alt.comp.lang.c ).

                Since you raise the issue of etiquette, I would point out that redirecting
                all replies to a single newsgroup most convenient to yourself is a
                discourtesy to others since it obliges them to switch to your preferred
                newsgroup in order to follow the thread. Cross posting to multiple
                newsgroups in the first place is a practice that is discouraged, even more
                so when your post is off topic in some of them.

                --
                John Carson
                1. To reply to email address, remove donald
                2. Don't reply to email address (post here instead)

                Comment

                Working...