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. IPC Thru WM_COPYDATA

IPC Thru WM_COPYDATA

Scheduled Pinned Locked Moved C / C++ / MFC
debuggingcsharpc++visual-studiodata-structures
9 Posts 4 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 have been having intermittent problems notifying a child window process with SendMessage So I decided to go with the Microsoft Sanctioned way WM_COPYDATA In my console Parent process I do GetConsoleWindow (which I observe returns what seems a valid HWND), I declare a COPYDATASTRUCT member on the stack (locally) and do SendMessage I have gotten the child window HWND with FindWindow in my MFC child window I have a messagemap entry and nothing it never gets there I am running under both the console app and the MFC app under Visual studio debugger so I can see what's going on

    ON_MESSAGE(WM_COPYDATA,Debug_it)

    J L 2 Replies Last reply
    0
    • F ForNow

      Hi I have been having intermittent problems notifying a child window process with SendMessage So I decided to go with the Microsoft Sanctioned way WM_COPYDATA In my console Parent process I do GetConsoleWindow (which I observe returns what seems a valid HWND), I declare a COPYDATASTRUCT member on the stack (locally) and do SendMessage I have gotten the child window HWND with FindWindow in my MFC child window I have a messagemap entry and nothing it never gets there I am running under both the console app and the MFC app under Visual studio debugger so I can see what's going on

      ON_MESSAGE(WM_COPYDATA,Debug_it)

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

      See the first comment at WM_COPYDATA message (Windows)[^]:

      Quote:

      Starting with Windows Vista, the application that is to receive the WM_COPYDATA message must call the ChangeWindowMessageFilterEx function. Otherwise the the message will not be received. It will be blocked by UIPI.

      F 1 Reply Last reply
      0
      • F ForNow

        Hi I have been having intermittent problems notifying a child window process with SendMessage So I decided to go with the Microsoft Sanctioned way WM_COPYDATA In my console Parent process I do GetConsoleWindow (which I observe returns what seems a valid HWND), I declare a COPYDATASTRUCT member on the stack (locally) and do SendMessage I have gotten the child window HWND with FindWindow in my MFC child window I have a messagemap entry and nothing it never gets there I am running under both the console app and the MFC app under Visual studio debugger so I can see what's going on

        ON_MESSAGE(WM_COPYDATA,Debug_it)

        L Offline
        L Offline
        leon de boer
        wrote on last edited by
        #3

        I am not sure the copydata can be local but for safety I would just use globalalloc anyhow

        HGLOBAL hgbl = GlobalAlloc(GMEM_ZEROINIT, sizeof(COPYDATASTRUCT) ); // Allocate the global memory
        COPYDATASTRUCT* cpd = (COPYDATASTRUCT*)GlobalLock(hgbl); // Lock the allocated memory to a pointer

        //..... use an abuse the pointer .. when you are done

        GlobalUnlock(hgbl); // Release lock on the memory block

        // Reciever then locks and plays and unlocks

        // ......zzzz sometime later one of the two parties

        GlobalFree(hgbl); // Free the allocated memory

        Not sure it's the problem but at least then when know the memory passed is valid to both parts.

        In vino veritas

        1 Reply Last reply
        0
        • J Jochen Arndt

          See the first comment at WM_COPYDATA message (Windows)[^]:

          Quote:

          Starting with Windows Vista, the application that is to receive the WM_COPYDATA message must call the ChangeWindowMessageFilterEx function. Otherwise the the message will not be received. It will be blocked by UIPI.

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

          Thanks for your help I just tried

          ChangeWindowMessageFilterEx

          I got a FALSE GetLastError returned ERROR_ACCESS_DENIED This is because my process is at SECURITY_MANDATORY_LOW_RID AnyWay I can Change this. Thing is I understand the concern for security however I (my process ) created the child process so I should be able and send messages

          J 1 Reply Last reply
          0
          • F ForNow

            Thanks for your help I just tried

            ChangeWindowMessageFilterEx

            I got a FALSE GetLastError returned ERROR_ACCESS_DENIED This is because my process is at SECURITY_MANDATORY_LOW_RID AnyWay I can Change this. Thing is I understand the concern for security however I (my process ) created the child process so I should be able and send messages

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

            It's not a problem of sending messages but of receiving. So the only solution would be increasing the UIPI level of your MFC application or using another IPC method.

            F 2 Replies Last reply
            0
            • J Jochen Arndt

              It's not a problem of sending messages but of receiving. So the only solution would be increasing the UIPI level of your MFC application or using another IPC method.

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

              Thanks I didn't read it entirely For a Mainframe in the OnCreate and for a modless dialog I'll put it in the OnInitDialog

              1 Reply Last reply
              0
              • J Jochen Arndt

                It's not a problem of sending messages but of receiving. So the only solution would be increasing the UIPI level of your MFC application or using another IPC method.

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

                Still works intermittently I am going to try DDE since my code is based on messages

                R 1 Reply Last reply
                0
                • F ForNow

                  Still works intermittently I am going to try DDE since my code is based on messages

                  R Offline
                  R Offline
                  Rick York
                  wrote on last edited by
                  #8

                  Many, many years ago I wrote a very simple app to demonstrate the use of WM_COPYDATA with MFC and I see that it is still online : Inter-Process Communication Using WM_COPYDATA[^] I rebuilt it just now in VS2015 (with very little effort) and it still works on W10. You might want to have a look at it as an example.

                  F 1 Reply Last reply
                  0
                  • R Rick York

                    Many, many years ago I wrote a very simple app to demonstrate the use of WM_COPYDATA with MFC and I see that it is still online : Inter-Process Communication Using WM_COPYDATA[^] I rebuilt it just now in VS2015 (with very little effort) and it still works on W10. You might want to have a look at it as an example.

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

                    I originally had the WM_COPYDATA as a ON_MESSAGE message map handler than I noticed the OnCopyData I wasn't able to get it to work with that as well My current method works fine as I don't have to wait for a reply with the SetEvent and shared storage thanks for your help

                    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