Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. FormatMessage FORMAT_MESSAGE_FROM_STRING

FormatMessage FORMAT_MESSAGE_FROM_STRING

Scheduled Pinned Locked Moved C / C++ / MFC
jsonhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    asdf1753
    wrote on last edited by
    #1

    Hi, I tried to use FormatMessage API to format variable argument that passed to a fuction, but it only delete all '%' characater with no thing else! please help me. my code : void CEllepsisDlg::Log(CString x,...) { CString strTempInput; strTempInput = x; va_list marker; va_start( marker, x ); LPTSTR lpFprmatedMessage; va_start( marker, x ); strTempInput=x; FormatMessage(FORMAT_MESSAGE_FROM_STRING, LPCSTR(strTempInput), NULL, NULL, (LPTSTR) &lpFprmatedMessage, 2048, &marker); char * tt=(char*)&lpFprmatedMessage; va_end( marker ); } :confused::((

    J 1 Reply Last reply
    0
    • A asdf1753

      Hi, I tried to use FormatMessage API to format variable argument that passed to a fuction, but it only delete all '%' characater with no thing else! please help me. my code : void CEllepsisDlg::Log(CString x,...) { CString strTempInput; strTempInput = x; va_list marker; va_start( marker, x ); LPTSTR lpFprmatedMessage; va_start( marker, x ); strTempInput=x; FormatMessage(FORMAT_MESSAGE_FROM_STRING, LPCSTR(strTempInput), NULL, NULL, (LPTSTR) &lpFprmatedMessage, 2048, &marker); char * tt=(char*)&lpFprmatedMessage; va_end( marker ); } :confused::((

      J Offline
      J Offline
      Joel Holdsworth
      wrote on last edited by
      #2

      Well looking at your code I think you got the params for FormatMessage slightly wrong. Try changing it to

      void CEllepsisDlg::Log(CString x,...)
      {
      TCHAR fprmatedMessage[2048];

      va_list marker;
      va_start( marker, x );

      FormatMessage(FORMAT_MESSAGE_FROM_STRING, (LPCVOID)((LPCTSTR)x), NULL, NULL,
      fprmatedMessage, sizeof(fprmatedMessage), marker);

      va_end( marker );
      }

      I havn't tested it, but I think that might work better. [EDIT]Be aware that in this new scheme that i've created, nothing happens to fprmatedMessage when FormatMessage has finished. Make sure you copy the string into a CString before using outside the Log function, otherwise your program will crash. e.g.

      CString myresult = fprmatedMessage;

      If you only want to use it within the function, then you can use fprmatedMessage just like any LPTSTR.[/EDIT] Hope this helps. Joel Holdsworth Wanna give me a job this summer? Check out my online CV and project history[^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups