WaitForSingleObject Crash
-
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
-
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
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
-
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
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?
-
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
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
-
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?
-
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
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 MFCCWinThread
class, you should check your thread class. -
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 MFCCWinThread
class, you should check your thread class. -
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
Whenever you get a crash provide:
- The exception info
- The source around the problem with the line highlighted
- The values of any variables of interest (used in the crashing line)
- A stack trace
This is the bare minimum. I also like the some dissassembly around:
- The crash site
- The last transition from your code.
I suggest you post as much of this as you can manage.
Steve