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

R

Robert Diamond

Hi ppl, just a quick question...

I need to use "MultiByteToWideChar(stuff)" to convert a char[MAX_PATH] to
unicode, so that OleLoadPicturePath 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\my image.bmp" is translated to the unicode equivalent, without
problems

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

So i want to send in a path string to MultiByteToWideChar(stuff) which might
have %[code] in it, and I want MultiByteToWideChar() 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");
MultiByteToWideChar(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%20file.bmp");
MultiByteToWideChar(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%20file.bmp"...
}

I've tried to read up at msdn on MultiByteToWideChar, 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 MultiByteToWideChar is the subject of overflows, so maybe finding a
different call would be best. Thanks in advance ;)
 
J

John Carson

Robert Diamond said:
Hi ppl, just a quick question...

I need to use "MultiByteToWideChar(stuff)" to convert a
char[MAX_PATH] to unicode, so that OleLoadPicturePath 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\my image.bmp" is translated to the unicode equivalent,
without problems

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

So i want to send in a path string to MultiByteToWideChar(stuff)
which might have %[code] in it, and I want MultiByteToWideChar() 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");
MultiByteToWideChar(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%20file.bmp");
MultiByteToWideChar(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%20file.bmp"...
}
[/QUOTE]

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.public.vc.language
or
comp.os.ms-windows.programmer.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%20file.bmp"

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

"C:\\image%20file.bmp"
 
R

Robert Diamond

John Carson said:
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.public.vc.language
or
comp.os.ms-windows.programmer.win32

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

I did post to two m$ vc newgroups
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%20file.bmp"

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

"C:\\image%20file.bmp"

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\\some%20thing" turns into unicode for "something\\some thing".
Notice the space... the %[code] was decoded, and i don't want it to... i
want "something\\some%20thing" to turn into unicode for

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!
 
K

Kevin Goodsell

Robert said:
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!

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

*PLONK*

-Kevin
 
J

John Carson

Robert Diamond said:
the %
Code:
 does come through... it comes through decoded... ie:
"something\\some%20thing" turns into unicode for "something\\some
thing". Notice the space... the %[code] was decoded, and i don't want
it to... i want "something\\some%20thing" to turn into unicode for
"something\\some%20thing" (Notice the "%20" and not the ' ' <space>
char).[/QUOTE]

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.
[QUOTE]
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![/QUOTE]

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.public.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.microsoft.news,
using Outlook Express, then microsoft.public.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.
 

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,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top