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. WaitForMultipleObjects getting access violation in Worker Thread

WaitForMultipleObjects getting access violation in Worker Thread

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpvisual-studiosecuritydebugging
18 Posts 5 Posters 22 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.
  • V Victor Nijegorodov

    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?

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

    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

    V 1 Reply Last reply
    0
    • F ForNow

      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

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

      Could you post some code snippets describing what you do?

      F 1 Reply Last reply
      0
      • V Victor Nijegorodov

        Could you post some code snippets describing what you do?

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

        sure be glad to in fact I appreciate it Am at work now (I work as a z/os Mainframe assemnbler programmer ) this has given me a chance to enhance my skills its 10:50 am here EST get off of work 5:00 - 5;30 will do it then thanks for your help

        1 Reply Last reply
        0
        • F ForNow

          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

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

          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

          F C 2 Replies Last reply
          0
          • L Lost User

            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

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

            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

            V 1 Reply Last reply
            0
            • F ForNow

              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

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

              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.

              F 1 Reply Last reply
              0
              • V Victor Nijegorodov

                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.

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

                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

                V 1 Reply Last reply
                0
                • F ForNow

                  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

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

                  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... :~

                  F 1 Reply Last reply
                  0
                  • V Victor Nijegorodov

                    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... :~

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

                    I’ll do that tonite ( it’s 8:45 est by me ) wanted to fix up my code Thanks

                    1 Reply Last reply
                    0
                    • L Lost User

                      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

                      C Offline
                      C Offline
                      Christmas Fantasy
                      wrote on last edited by
                      #18

                      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[^] .

                      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