CString.FormatMessage and CString.Format difference

  • Thread starter Thread starter Hai Ly Hoang [MT00KSTN]
  • Start date 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
 
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.
 
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.
 
Back
Top