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. Error when printing

Error when printing

Scheduled Pinned Locked Moved C / C++ / MFC
csharpvisual-studiohelp
6 Posts 5 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.
  • E Offline
    E Offline
    Erich Ruth
    wrote on last edited by
    #1

    I have a small program. I compile the executable. If I find the executable and double click on it, everything works fine. I can print, print preview; all is well. If within visual studio I hit the green triangle to run the executable and then I try to print or print preview, I get an error in this code: inline void* CThreadSlotData::GetThreadValue(int nSlot) { EnterCriticalSection(&m_sect); ASSERT(nSlot != 0 && nSlot < m_nMax); ASSERT(m_pSlotData != NULL); ASSERT(m_pSlotData[nSlot].dwFlags & SLOT_USED); ASSERT(m_tlsIndex != (DWORD)-1); if( nSlot <= 0 || nSlot >= m_nMax ) // check for retail builds. { LeaveCriticalSection(&m_sect); return NULL; } CThreadData* pData = (CThreadData*)TlsGetValue(m_tlsIndex); if (pData == NULL || nSlot >= pData->nCount) { LeaveCriticalSection(&m_sect); return NULL; } void* pRetVal = pData->pData[nSlot]; LeaveCriticalSection(&m_sect); return pRetVal; } It breaks at LeaveCriticalSection(). Im really perplexed as to why this error has arisen and what to do to get it to go away. If you have any insight, please let me know.

    Richard DeemingR D 2 Replies Last reply
    0
    • E Erich Ruth

      I have a small program. I compile the executable. If I find the executable and double click on it, everything works fine. I can print, print preview; all is well. If within visual studio I hit the green triangle to run the executable and then I try to print or print preview, I get an error in this code: inline void* CThreadSlotData::GetThreadValue(int nSlot) { EnterCriticalSection(&m_sect); ASSERT(nSlot != 0 && nSlot < m_nMax); ASSERT(m_pSlotData != NULL); ASSERT(m_pSlotData[nSlot].dwFlags & SLOT_USED); ASSERT(m_tlsIndex != (DWORD)-1); if( nSlot <= 0 || nSlot >= m_nMax ) // check for retail builds. { LeaveCriticalSection(&m_sect); return NULL; } CThreadData* pData = (CThreadData*)TlsGetValue(m_tlsIndex); if (pData == NULL || nSlot >= pData->nCount) { LeaveCriticalSection(&m_sect); return NULL; } void* pRetVal = pData->pData[nSlot]; LeaveCriticalSection(&m_sect); return pRetVal; } It breaks at LeaveCriticalSection(). Im really perplexed as to why this error has arisen and what to do to get it to go away. If you have any insight, please let me know.

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      You have already posted this: Print causes in afxtls.cpp - Managed C++/CLI Discussion Boards[^]


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      V 1 Reply Last reply
      0
      • E Erich Ruth

        I have a small program. I compile the executable. If I find the executable and double click on it, everything works fine. I can print, print preview; all is well. If within visual studio I hit the green triangle to run the executable and then I try to print or print preview, I get an error in this code: inline void* CThreadSlotData::GetThreadValue(int nSlot) { EnterCriticalSection(&m_sect); ASSERT(nSlot != 0 && nSlot < m_nMax); ASSERT(m_pSlotData != NULL); ASSERT(m_pSlotData[nSlot].dwFlags & SLOT_USED); ASSERT(m_tlsIndex != (DWORD)-1); if( nSlot <= 0 || nSlot >= m_nMax ) // check for retail builds. { LeaveCriticalSection(&m_sect); return NULL; } CThreadData* pData = (CThreadData*)TlsGetValue(m_tlsIndex); if (pData == NULL || nSlot >= pData->nCount) { LeaveCriticalSection(&m_sect); return NULL; } void* pRetVal = pData->pData[nSlot]; LeaveCriticalSection(&m_sect); return pRetVal; } It breaks at LeaveCriticalSection(). Im really perplexed as to why this error has arisen and what to do to get it to go away. If you have any insight, please let me know.

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

        Erich Ruth wrote:

        ...I get an error in this code:

        What error?

        Erich Ruth wrote:

        It breaks...

        What does that mean, exactly? Could it be a difference between release vs. debug mode? Have you stepped into LeaveCriticalSection() to see what is happening (e.g., fired assertion)?

        "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

        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

        E 1 Reply Last reply
        0
        • Richard DeemingR Richard Deeming

          You have already posted this: Print causes in afxtls.cpp - Managed C++/CLI Discussion Boards[^]


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          V Offline
          V Offline
          Victor Nijegorodov
          wrote on last edited by
          #4

          Richard, but there was just a wrong forum! Therefore (I think) he has reposted the question here....

          1 Reply Last reply
          0
          • D David Crow

            Erich Ruth wrote:

            ...I get an error in this code:

            What error?

            Erich Ruth wrote:

            It breaks...

            What does that mean, exactly? Could it be a difference between release vs. debug mode? Have you stepped into LeaveCriticalSection() to see what is happening (e.g., fired assertion)?

            "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

            "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

            E Offline
            E Offline
            Erich Ruth
            wrote on last edited by
            #5

            When I say it breaks, that means it pops up a box that says: "Unhandled exemption x 0x777f6a73 in MultiScreen.exe: 0xC0000005: Access violation reading location 0xfeeefefa. and then I have Break or Continue. I hit Break and it shows me this code:

            inline void* CThreadSlotData::GetThreadValue(int nSlot)
            {
            EnterCriticalSection(&m_sect);
            ASSERT(nSlot != 0 && nSlot < m_nMax);
            ASSERT(m_pSlotData != NULL);
            ASSERT(m_pSlotData[nSlot].dwFlags & SLOT_USED);
            ASSERT(m_tlsIndex != (DWORD)-1);
            if( nSlot <= 0 || nSlot >= m_nMax ) // check for retail builds.
            {
            LeaveCriticalSection(&m_sect);
            return NULL;
            }

            CThreadData\* pData = (CThreadData\*)TlsGetValue(m\_tlsIndex);
            if (pData == NULL || nSlot >= pData->nCount)
            {
            	LeaveCriticalSection(&m\_sect);
            	return NULL;
            }
            void\* pRetVal = pData->pData\[nSlot\];
            LeaveCriticalSection(&m\_sect);
            return pRetVal;
            

            }

            and its pointing to

            LeaveCriticalSection(&m_sect);

            which is the 2nd to last line.

            L 1 Reply Last reply
            0
            • E Erich Ruth

              When I say it breaks, that means it pops up a box that says: "Unhandled exemption x 0x777f6a73 in MultiScreen.exe: 0xC0000005: Access violation reading location 0xfeeefefa. and then I have Break or Continue. I hit Break and it shows me this code:

              inline void* CThreadSlotData::GetThreadValue(int nSlot)
              {
              EnterCriticalSection(&m_sect);
              ASSERT(nSlot != 0 && nSlot < m_nMax);
              ASSERT(m_pSlotData != NULL);
              ASSERT(m_pSlotData[nSlot].dwFlags & SLOT_USED);
              ASSERT(m_tlsIndex != (DWORD)-1);
              if( nSlot <= 0 || nSlot >= m_nMax ) // check for retail builds.
              {
              LeaveCriticalSection(&m_sect);
              return NULL;
              }

              CThreadData\* pData = (CThreadData\*)TlsGetValue(m\_tlsIndex);
              if (pData == NULL || nSlot >= pData->nCount)
              {
              	LeaveCriticalSection(&m\_sect);
              	return NULL;
              }
              void\* pRetVal = pData->pData\[nSlot\];
              LeaveCriticalSection(&m\_sect);
              return pRetVal;
              

              }

              and its pointing to

              LeaveCriticalSection(&m_sect);

              which is the 2nd to last line.

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

              Hi, 0xfeeefeee is a magic number[^] used by the debug heap for marking memory that's been freed. So it looks like the data at pData->pData[nSlot]; has already been freed by the time you try to read it. This probably means that the bug also exists in your 'Retail build'. A retail build with a normal heap may happily read garbage data and keep on going. You can probably debug this by setting up a memory watch[^] for &pData->pData[nSlot]; Best Wishes, -David Delaune

              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