WaitForMultipleObjects getting access violation in Worker Thread
-
ForNow wrote:
don’t think the wait should be in the main thread
If you would implement the Wait... in the main thread then you could wait forever and your main thread could be frozen forever. BTW, how do you create/obtain the event HANDLEs that you pass in the WaitForMultipleObjects? Are they all correct?
I am using CreateEvent as it gives me more flexibility i.e auto reset As opposed to WSACreateEvent I then pass everything in a structure pointed to by LPVOID had to build it with no alignment (Zp1) as I was getting slack bytes among members of the structure thanks
-
I am using CreateEvent as it gives me more flexibility i.e auto reset As opposed to WSACreateEvent I then pass everything in a structure pointed to by LPVOID had to build it with no alignment (Zp1) as I was getting slack bytes among members of the structure thanks
Could you post some code snippets describing what you do?
-
Could you post some code snippets describing what you do?
-
Hi In the process of re-writing my CAsyncSocket to the more controllable WSA flavor I got stuck on WaitForMultipleObjects. For Each Event on the socket that I do a bind by that I mean FD_READ, FD_WRITE I CreateEvent I associate the events with WSAEventSelect. I pass all the info (HWND windows message etc when I want notification to be sent in a structure) pointed to by a LPVOID the parameter in The CreateThread I let the worker thread wait on the events and do the appropriate SendMessage Problems is I am abending or rather getting an Access violation on WaitForMultipleobjects Running under the visual studio debugger I can see the values of the 5 events are correct The first thing i thought of was that my worker thread didnt have security rights to the events I created in the Mother thread ( all threads are in the same process) I just figured the quickest way to resolve this was to name the events and do a OpenEvent If I get a null from any events I would have a problem All of the events named from OpenEvent return a value however they are not the same event values that I created Real mystery to me Hope some one can help Thanks
ForNow wrote:
I pass all the info (HWND windows
The MFC framework does not always give you the *real* HWND to a window. As strange as this might sound, the MFC framework maintains two object maps. The 'real objects' and an internal 'temporary handle map'. MFC will sometimes give you a temporary CTempWnd instead. If you are passing the window handle of a MFC class then you need to use CWnd::GetSafeHwnd[^]. There are some rare occasions where GetSafeHwnd cannot give you the real window handle and will return NULL instead so you should probably check for that too. Not many people are using MFC these days. You should consider moving on. I can't think of much else that would cause WaitForMultipleObjects to throw an access violation. The only other thing I can think of... is a corrupt heap. Sounds like you are somehow passing garbage to WaitForMultipleObjects. Best Wishes, -David Delaune
-
ForNow wrote:
I pass all the info (HWND windows
The MFC framework does not always give you the *real* HWND to a window. As strange as this might sound, the MFC framework maintains two object maps. The 'real objects' and an internal 'temporary handle map'. MFC will sometimes give you a temporary CTempWnd instead. If you are passing the window handle of a MFC class then you need to use CWnd::GetSafeHwnd[^]. There are some rare occasions where GetSafeHwnd cannot give you the real window handle and will return NULL instead so you should probably check for that too. Not many people are using MFC these days. You should consider moving on. I can't think of much else that would cause WaitForMultipleObjects to throw an access violation. The only other thing I can think of... is a corrupt heap. Sounds like you are somehow passing garbage to WaitForMultipleObjects. Best Wishes, -David Delaune
Thanks I had some other problems I got rid of the WaitForMultipleObjects and set all my notifications on one event and extracted the correct one with WSAENumnetwork that worked when you say not many people are using MFC do yo mean they coding Windows C API I found CAsynsockets to be a pain I couldn’t pass along notification to another window Thanks
-
Thanks I had some other problems I got rid of the WaitForMultipleObjects and set all my notifications on one event and extracted the correct one with WSAENumnetwork that worked when you say not many people are using MFC do yo mean they coding Windows C API I found CAsynsockets to be a pain I couldn’t pass along notification to another window Thanks
ForNow wrote:
when you say not many people are using MFC do yo mean they coding Windows C API I found CAsynsockets to be a pain I couldn’t pass along notification to another window
I guess he meant they use C#. I used CAsyncSocket class successfully since many years (until I have changed the company to work for). I never had any problems with this class to work with both IPv4 and IPv6 sockets in IPC with multiple sockets through intranet and internet.
-
ForNow wrote:
when you say not many people are using MFC do yo mean they coding Windows C API I found CAsynsockets to be a pain I couldn’t pass along notification to another window
I guess he meant they use C#. I used CAsyncSocket class successfully since many years (until I have changed the company to work for). I never had any problems with this class to work with both IPv4 and IPv6 sockets in IPC with multiple sockets through intranet and internet.
C/C++ has pointers which gives me flexibility same with native sockets “WSA” when I tried moving my derived CAsyncSocket object pointer notification from a main window to a dialog I ran into problems. No where in the documentation does it say there has to be HWND associated with your CasyncSockets but you have to I was using CWinThread for notification it has a message pump but doesn’t have a HWND although there is hWnd member ( I think main windows ) member thanks
-
C/C++ has pointers which gives me flexibility same with native sockets “WSA” when I tried moving my derived CAsyncSocket object pointer notification from a main window to a dialog I ran into problems. No where in the documentation does it say there has to be HWND associated with your CasyncSockets but you have to I was using CWinThread for notification it has a message pump but doesn’t have a HWND although there is hWnd member ( I think main windows ) member thanks
It is very hard to understand what you mean, much more harder is to understand what, how, and what for you have implemented in your project. The reason - you avoid to show your code/pseudocode snippets. Sorry... :~
-
It is very hard to understand what you mean, much more harder is to understand what, how, and what for you have implemented in your project. The reason - you avoid to show your code/pseudocode snippets. Sorry... :~
-
ForNow wrote:
I pass all the info (HWND windows
The MFC framework does not always give you the *real* HWND to a window. As strange as this might sound, the MFC framework maintains two object maps. The 'real objects' and an internal 'temporary handle map'. MFC will sometimes give you a temporary CTempWnd instead. If you are passing the window handle of a MFC class then you need to use CWnd::GetSafeHwnd[^]. There are some rare occasions where GetSafeHwnd cannot give you the real window handle and will return NULL instead so you should probably check for that too. Not many people are using MFC these days. You should consider moving on. I can't think of much else that would cause WaitForMultipleObjects to throw an access violation. The only other thing I can think of... is a corrupt heap. Sounds like you are somehow passing garbage to WaitForMultipleObjects. Best Wishes, -David Delaune
I've managed to get SharpDX to play a video from a file without problems, and also have been able to do my 2D drawing. This was simple enough and the performance is good on Speed Test - TestMySpeed[^] .