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. WaitForSingleObject Crash

WaitForSingleObject Crash

Scheduled Pinned Locked Moved C / C++ / MFC
8 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.
  • F Offline
    F Offline
    ForNow
    wrote on last edited by
    #1

    Hi, I am getting an exception on a WaitForSingleObject Below is the code the Security events parameter of the CreateEvent is NULL I am Wondering if that might be the issue

    Event_Handle = ::CreateEvent(NULL, FALSE, FALSE, NULL);

    int i;
    UINT start_port;

     // Sockevent.SetEvent();
    
        for (i = 0, start\_port = 11007; i < 4; start\_port++, i++)
    

    {

    threadptr[i] = NULL;
    threadptr[i] = new SockCLeintThread(start_port);
    threadptr[i]->m_pActiveWnd = m_pMainWnd;
    threadptr[i]->m_pMainWnd = m_pMainWnd;

         if (threadptr\[i\] == NULL)
                m\_pMainWnd->MessageBox((LPCTSTR)"SockClientThreadFail",NULL,MB\_ICONERROR);
    
    	   threadptr\[i\]->CreateThread(CREATE\_SUSPENDED,0,NULL);  
    
                     threadptr\[i\]->flags.is\_connected = 0;
             
                     threadptr\[i\]->ipaddr = (LPCTSTR)"192.168.1.4";					
    
    	   threadptr\[i\]->flags.busy = 0;
    
    	   SetThreadName(threadptr\[i\]->m\_nThreadID,thread\[i\]);
    				
             	      	
    	   threadptr\[i\]->ResumeThread();
    
    DWORD return\_value = ::WaitForSingleObject(Event\_Handle,INFINITE);   // wait for connection
    
    S E L 3 Replies Last reply
    0
    • F ForNow

      Hi, I am getting an exception on a WaitForSingleObject Below is the code the Security events parameter of the CreateEvent is NULL I am Wondering if that might be the issue

      Event_Handle = ::CreateEvent(NULL, FALSE, FALSE, NULL);

      int i;
      UINT start_port;

       // Sockevent.SetEvent();
      
          for (i = 0, start\_port = 11007; i < 4; start\_port++, i++)
      

      {

      threadptr[i] = NULL;
      threadptr[i] = new SockCLeintThread(start_port);
      threadptr[i]->m_pActiveWnd = m_pMainWnd;
      threadptr[i]->m_pMainWnd = m_pMainWnd;

           if (threadptr\[i\] == NULL)
                  m\_pMainWnd->MessageBox((LPCTSTR)"SockClientThreadFail",NULL,MB\_ICONERROR);
      
      	   threadptr\[i\]->CreateThread(CREATE\_SUSPENDED,0,NULL);  
      
                       threadptr\[i\]->flags.is\_connected = 0;
               
                       threadptr\[i\]->ipaddr = (LPCTSTR)"192.168.1.4";					
      
      	   threadptr\[i\]->flags.busy = 0;
      
      	   SetThreadName(threadptr\[i\]->m\_nThreadID,thread\[i\]);
      				
               	      	
      	   threadptr\[i\]->ResumeThread();
      
      DWORD return\_value = ::WaitForSingleObject(Event\_Handle,INFINITE);   // wait for connection
      
      S Offline
      S Offline
      Stephen Hewitt
      wrote on last edited by
      #2

      ForNow wrote:

      (LPCTSTR)"SockClientThreadFail"

      ForNow wrote:

      (LPCTSTR)"192.168.1.4"

      This is probably not the answer you're looking for, but it's more important. What the hell are you catting to LPCTSTR for? This is at best pointless and at worst a runtime error that would be a compile time one without the cast. You can cast all you like but it will not make it walk like a duck. If your compiling for ANSI then the cast does nothing except look stupid. If your compiling for UNICODE you're effectively telling to compiler to shut up and not issue an error (and you've made one) and just pretend that the ANSI string is a UNICODE one. Best case is a garbled string, worst a buffer overrun. Use the _T macro from <tchar.h>.

      Steve

      1 Reply Last reply
      0
      • F ForNow

        Hi, I am getting an exception on a WaitForSingleObject Below is the code the Security events parameter of the CreateEvent is NULL I am Wondering if that might be the issue

        Event_Handle = ::CreateEvent(NULL, FALSE, FALSE, NULL);

        int i;
        UINT start_port;

         // Sockevent.SetEvent();
        
            for (i = 0, start\_port = 11007; i < 4; start\_port++, i++)
        

        {

        threadptr[i] = NULL;
        threadptr[i] = new SockCLeintThread(start_port);
        threadptr[i]->m_pActiveWnd = m_pMainWnd;
        threadptr[i]->m_pMainWnd = m_pMainWnd;

             if (threadptr\[i\] == NULL)
                    m\_pMainWnd->MessageBox((LPCTSTR)"SockClientThreadFail",NULL,MB\_ICONERROR);
        
        	   threadptr\[i\]->CreateThread(CREATE\_SUSPENDED,0,NULL);  
        
                         threadptr\[i\]->flags.is\_connected = 0;
                 
                         threadptr\[i\]->ipaddr = (LPCTSTR)"192.168.1.4";					
        
        	   threadptr\[i\]->flags.busy = 0;
        
        	   SetThreadName(threadptr\[i\]->m\_nThreadID,thread\[i\]);
        				
                 	      	
        	   threadptr\[i\]->ResumeThread();
        
        DWORD return\_value = ::WaitForSingleObject(Event\_Handle,INFINITE);   // wait for connection
        
        E Offline
        E Offline
        Erudite_Eric
        wrote on last edited by
        #3

        Well your code logic is all over the place. If 'new' throws an exception, which it does on later C++ then you dont need the check for NULL, if not, that check needs to come directly after the 'new' and the loop needs to continue or exit. Also what s threadptr? Is it a static, heap or stack array, is it big wnough? Also dont you want to set the thread name before crating it? How is the handle passed t the thread,, I assume it has to be, and waits for the thread to run? But look at the exception, what does it say, what line of code is it saying is bad?

        F 1 Reply Last reply
        0
        • F ForNow

          Hi, I am getting an exception on a WaitForSingleObject Below is the code the Security events parameter of the CreateEvent is NULL I am Wondering if that might be the issue

          Event_Handle = ::CreateEvent(NULL, FALSE, FALSE, NULL);

          int i;
          UINT start_port;

           // Sockevent.SetEvent();
          
              for (i = 0, start\_port = 11007; i < 4; start\_port++, i++)
          

          {

          threadptr[i] = NULL;
          threadptr[i] = new SockCLeintThread(start_port);
          threadptr[i]->m_pActiveWnd = m_pMainWnd;
          threadptr[i]->m_pMainWnd = m_pMainWnd;

               if (threadptr\[i\] == NULL)
                      m\_pMainWnd->MessageBox((LPCTSTR)"SockClientThreadFail",NULL,MB\_ICONERROR);
          
          	   threadptr\[i\]->CreateThread(CREATE\_SUSPENDED,0,NULL);  
          
                           threadptr\[i\]->flags.is\_connected = 0;
                   
                           threadptr\[i\]->ipaddr = (LPCTSTR)"192.168.1.4";					
          
          	   threadptr\[i\]->flags.busy = 0;
          
          	   SetThreadName(threadptr\[i\]->m\_nThreadID,thread\[i\]);
          				
                   	      	
          	   threadptr\[i\]->ResumeThread();
          
          DWORD return\_value = ::WaitForSingleObject(Event\_Handle,INFINITE);   // wait for connection
          
          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          m_pMainWnd->MessageBox((LPCTSTR)"SockClientThreadFail",NULL,MB_ICONERROR);

          // and

          threadptr[i]->ipaddr = (LPCTSTR)"192.168.1.4";

          Despite numerous explanations that using casts in this way is totally wrong you still use them. You seem determined to ensure that your code will not work.

          Use the best guess

          1 Reply Last reply
          0
          • E Erudite_Eric

            Well your code logic is all over the place. If 'new' throws an exception, which it does on later C++ then you dont need the check for NULL, if not, that check needs to come directly after the 'new' and the loop needs to continue or exit. Also what s threadptr? Is it a static, heap or stack array, is it big wnough? Also dont you want to set the thread name before crating it? How is the handle passed t the thread,, I assume it has to be, and waits for the thread to run? But look at the exception, what does it say, what line of code is it saying is bad?

            F Offline
            F Offline
            ForNow
            wrote on last edited by
            #5

            I changed all the casts to _T the exceptions says unhandled exception at 7FE6D3C9B5 MFC100.DLL access violation reading location 25e5b80 This is right at the call for WiatForSingleObject

            J S 2 Replies Last reply
            0
            • F ForNow

              I changed all the casts to _T the exceptions says unhandled exception at 7FE6D3C9B5 MFC100.DLL access violation reading location 25e5b80 This is right at the call for WiatForSingleObject

              J Offline
              J Offline
              Jochen Arndt
              wrote on last edited by
              #6

              The exception occurs in the MFC DLL. So you have an invalid member in one of your MFC classes. WaitForSingleObject() is a Windows API function that has nothing to do with MFC. Before that call you are starting a thread. Assuming that the thread is derived from the MFC CWinThread class, you should check your thread class.

              F 1 Reply Last reply
              0
              • J Jochen Arndt

                The exception occurs in the MFC DLL. So you have an invalid member in one of your MFC classes. WaitForSingleObject() is a Windows API function that has nothing to do with MFC. Before that call you are starting a thread. Assuming that the thread is derived from the MFC CWinThread class, you should check your thread class.

                F Offline
                F Offline
                ForNow
                wrote on last edited by
                #7

                Event_handle is a member of CHecmd CLASS so in otherword I mixing MFC with win32 I think I got it

                1 Reply Last reply
                0
                • F ForNow

                  I changed all the casts to _T the exceptions says unhandled exception at 7FE6D3C9B5 MFC100.DLL access violation reading location 25e5b80 This is right at the call for WiatForSingleObject

                  S Offline
                  S Offline
                  Stephen Hewitt
                  wrote on last edited by
                  #8

                  Whenever you get a crash provide:

                  1. The exception info
                  2. The source around the problem with the line highlighted
                  3. The values of any variables of interest (used in the crashing line)
                  4. A stack trace

                  This is the bare minimum. I also like the some dissassembly around:

                  1. The crash site
                  2. The last transition from your code.

                  I suggest you post as much of this as you can manage.

                  Steve

                  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