CString.FormatMessage and CString.Format difference

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hai Ly Hoang [MT00KSTN]

    #1

    CString.FormatMessage and CString.Format difference

    CString.FormatM essage 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


  • Jeff Partch [MVP]

    #2
    Re: CString.FormatM essage and CString.Format difference

    " Hai Ly Hoang [MT00KSTN]" <ReplyToGroup@M ail.com> wrote in message
    news:OV1bs5YvDH A.2136@TK2MSFTN GP10.phx.gbl...[color=blue]
    > CString.FormatM essage and CString.Format has the same parameters and they
    > seems to have to outcome. However, they coexist !. There must be some[/color]
    subtle[color=blue]
    > different between they.
    > Can you tell me the difference ?[/color]

    CString::Format Message 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.
    --
    Jeff Partch [VC++ MVP]


    Comment

    • Mihai N.

      #3
      Re: CString.FormatM essage and CString.Format difference

      > CString.FormatM essage and CString.Format has the same parameters and[color=blue]
      > they seems to have to outcome. However, they coexist !. There must be
      > some subtle different between they.
      > Can you tell me the difference ?[/color]

      CString.FormatM essage 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 internationaliz ation 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.

      --
      Mihai
      -------------------------
      Replace _year_ with _ to get the real email

      Comment

      Working...