CString.FormatMessage and CString.Format difference

  • Thread starter Hai Ly Hoang [MT00KSTN]
  • Start date
H

Hai Ly Hoang [MT00KSTN]

CString.FormatMessage and CString.Format has the same parameters and they
seems to have to outcome. However, they coexist !. There must be some subtle
different between they.
Can you tell me the difference ?

Thank a lot
 
J

Jeff Partch [MVP]

Hai Ly Hoang said:
CString.FormatMessage and CString.Format has the same parameters and they
seems to have to outcome. However, they coexist !. There must be some subtle
different between they.
Can you tell me the difference ?

CString::FormatMessage calls the API FormatMessage using the
FORMAT_MESSAGE_FROM_STRING flag, which I believe uses a special set of
insert escape sequences and allows you to number which insert is used with
which argument.
 
M

Mihai N.

CString.FormatMessage and CString.Format has the same parameters and
they seems to have to outcome. However, they coexist !. There must be
some subtle different between they.
Can you tell me the difference ?

CString.FormatMessage calls the FormatMessage API

The main difference is the fact that numbers can be associated to parameters:
"You just deleted %d files from the %s folder"
will become
"You just deleted %!1!d files from the %!2!s folder"
The %d %s is also supported.

The FormatMessage is better from internationalization perspective.
In some languages the order in the sentence may require changing the order
of the parameters, like for instance some "Yoda speach":
"From the %s folder %d files you just deleted"
or
"From the %!2!s folder %!1!d files you just deleted"

The first variant is not going to work, since this will require you
to change the order of the parameters.
But the ideal is to keep the code language independent.
FormatMessage does it.
 

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

Top