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. Why DrawText() fails?

Why DrawText() fails?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
6 Posts 6 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.
  • R Offline
    R Offline
    RS Ratheesh
    wrote on last edited by
    #1

    Hi, I am using "DrawText(HDC hDC,LPCTSTR lpchText,int nCount,LPRECT lpRect,UINT uFormat)" in my project, it returns 0 means function fils. In which case this function will fail and whether there is error code for this function? I have gone through MSDN but they didn't mentioned the reason for failing. Thanks in Advance, Ratheesh

    D S L 3 Replies Last reply
    0
    • R RS Ratheesh

      Hi, I am using "DrawText(HDC hDC,LPCTSTR lpchText,int nCount,LPRECT lpRect,UINT uFormat)" in my project, it returns 0 means function fils. In which case this function will fail and whether there is error code for this function? I have gone through MSDN but they didn't mentioned the reason for failing. Thanks in Advance, Ratheesh

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Have you tried GetLastError()?

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

      A 1 Reply Last reply
      0
      • D David Crow

        Have you tried GetLastError()?

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

        A Offline
        A Offline
        Albert Holguin
        wrote on last edited by
        #3

        That usually works for most WinAPI calls that don't return an actual error message off the back... but its usually specified in the MSDN documentation... for whatever reason, they didn't specify this for this call[^]. That omission is a bit strange.

        1 Reply Last reply
        0
        • R RS Ratheesh

          Hi, I am using "DrawText(HDC hDC,LPCTSTR lpchText,int nCount,LPRECT lpRect,UINT uFormat)" in my project, it returns 0 means function fils. In which case this function will fail and whether there is error code for this function? I have gone through MSDN but they didn't mentioned the reason for failing. Thanks in Advance, Ratheesh

          S Offline
          S Offline
          Software_Developer
          wrote on last edited by
          #4

          The problem isn't with the DrawText call itself. Apparently something is NULL in

          DrawText(HDC hDC,LPCTSTR lpchText,int nCount,LPRECT lpRect,UINT uFormat)

          An access violation occurs in unmanaged or unsafe code when it attempts to read or write to memory that has not been allocated, or to which it does not have access. Not all reads or writes through bad pointers lead to access violations, so an access violation usually indicates that several reads or writes have occurred through bad pointers, and that memory might be corrupted. [This] might shed some light.

          B 1 Reply Last reply
          0
          • R RS Ratheesh

            Hi, I am using "DrawText(HDC hDC,LPCTSTR lpchText,int nCount,LPRECT lpRect,UINT uFormat)" in my project, it returns 0 means function fils. In which case this function will fail and whether there is error code for this function? I have gone through MSDN but they didn't mentioned the reason for failing. Thanks in Advance, Ratheesh

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Try showing the actual code from your program, and make sure that all the parameters are valid.

            Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

            1 Reply Last reply
            0
            • S Software_Developer

              The problem isn't with the DrawText call itself. Apparently something is NULL in

              DrawText(HDC hDC,LPCTSTR lpchText,int nCount,LPRECT lpRect,UINT uFormat)

              An access violation occurs in unmanaged or unsafe code when it attempts to read or write to memory that has not been allocated, or to which it does not have access. Not all reads or writes through bad pointers lead to access violations, so an access violation usually indicates that several reads or writes have occurred through bad pointers, and that memory might be corrupted. [This] might shed some light.

              B Offline
              B Offline
              bob16972
              wrote on last edited by
              #6

              TopCoder23 wrote:

              An access violation occurs

              Where exactly did they say they experienced an access violation? They could have simply passed in an invalid parameter option for format or the function could have simply checked for a NULL parameter and returned indicating failure based on that branch statement.

              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