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. .NET (Core and Framework)
  4. Broadcasting custom windows message(Interprocess communication)

Broadcasting custom windows message(Interprocess communication)

Scheduled Pinned Locked Moved .NET (Core and Framework)
c++csharphelpquestion
7 Posts 3 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.
  • C Offline
    C Offline
    callousfantom
    wrote on last edited by
    #1

    Hi I have a service written in Visual C++ 6 that needs to interact with an application written in vb.net. In my service I have used : <b>DWORD mymsg=RegisterWindowMessage("my_message")</b> to register a unique custom message. I then use: <b>BOOL b=SendNotifyMessage(HWND_BROADCAST,mymsg,NULL,NULL)</b> to broadcast my message. However, I can't seem to be able to capture this message in the Windowproc function of my vb.net application. <b>Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Integer Dim mymsg As Integer = RegisterWindowMessage("my_message") Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) if m.Msg=mymsg then --do something-- end if end sub</b> Please help! :sigh: P.S.:I need to show a pop up in my .net application when it receives this message. The message values have all registered properly in both applications and are returned to be the same when I print them. Also the SendNotitfyMessage in my service returns a non zero value(supposed to indicate success). What do I do?? What am I doing wrong? Is there something wrong with my message receiving code in vb.net?

    M M 2 Replies Last reply
    0
    • C callousfantom

      Hi I have a service written in Visual C++ 6 that needs to interact with an application written in vb.net. In my service I have used : <b>DWORD mymsg=RegisterWindowMessage("my_message")</b> to register a unique custom message. I then use: <b>BOOL b=SendNotifyMessage(HWND_BROADCAST,mymsg,NULL,NULL)</b> to broadcast my message. However, I can't seem to be able to capture this message in the Windowproc function of my vb.net application. <b>Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Integer Dim mymsg As Integer = RegisterWindowMessage("my_message") Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) if m.Msg=mymsg then --do something-- end if end sub</b> Please help! :sigh: P.S.:I need to show a pop up in my .net application when it receives this message. The message values have all registered properly in both applications and are returned to be the same when I print them. Also the SendNotitfyMessage in my service returns a non zero value(supposed to indicate success). What do I do?? What am I doing wrong? Is there something wrong with my message receiving code in vb.net?

      M Offline
      M Offline
      Moreno Airoldi
      wrote on last edited by
      #2

      Try changing your WndProc declaration to:

      <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
      Protected Overrides Sub WndProc(ByRef m As Message)

      2+2=5 for very large amounts of 2 (always loved that one hehe!)

      C 1 Reply Last reply
      0
      • C callousfantom

        Hi I have a service written in Visual C++ 6 that needs to interact with an application written in vb.net. In my service I have used : <b>DWORD mymsg=RegisterWindowMessage("my_message")</b> to register a unique custom message. I then use: <b>BOOL b=SendNotifyMessage(HWND_BROADCAST,mymsg,NULL,NULL)</b> to broadcast my message. However, I can't seem to be able to capture this message in the Windowproc function of my vb.net application. <b>Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Integer Dim mymsg As Integer = RegisterWindowMessage("my_message") Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) if m.Msg=mymsg then --do something-- end if end sub</b> Please help! :sigh: P.S.:I need to show a pop up in my .net application when it receives this message. The message values have all registered properly in both applications and are returned to be the same when I print them. Also the SendNotitfyMessage in my service returns a non zero value(supposed to indicate success). What do I do?? What am I doing wrong? Is there something wrong with my message receiving code in vb.net?

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        callousfantom wrote:

        a service written in Visual C++

        A Windows service application? If so, services run in a different desktop so you may want to use a more suitable IPC mechanism instead of window messages which don't cross the desktop boundary.

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        C 2 Replies Last reply
        0
        • M Moreno Airoldi

          Try changing your WndProc declaration to:

          <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
          Protected Overrides Sub WndProc(ByRef m As Message)

          2+2=5 for very large amounts of 2 (always loved that one hehe!)

          C Offline
          C Offline
          callousfantom
          wrote on last edited by
          #4

          Thanks for the suggestion but I tried it and it didn't really work. I don't think it's a security issue. I doubt that.

          M 1 Reply Last reply
          0
          • M Mark Salsbery

            callousfantom wrote:

            a service written in Visual C++

            A Windows service application? If so, services run in a different desktop so you may want to use a more suitable IPC mechanism instead of window messages which don't cross the desktop boundary.

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            C Offline
            C Offline
            callousfantom
            wrote on last edited by
            #5

            Are you trying to say that since the service (SYSTEM acct) is running under a different user context than the application, that the messages won't reach the application from the service? Because my application can communicate via messages with my service using its handle.I've already done that. This implies I can only communicate from the app. to the service and not the other way around. Or does it mean that I can only use handles to communicate one-to-one and broadcasting won't work? Neither of the two seem to make sense to me. As for another way, I could use custom named events but I've already done one way via messages and I thought I could do the same thing in the other direction. If there's something else you were trying to suggest then I'm sorry I don't think I quite understood you.:confused:

            1 Reply Last reply
            0
            • C callousfantom

              Thanks for the suggestion but I tried it and it didn't really work. I don't think it's a security issue. I doubt that.

              M Offline
              M Offline
              Moreno Airoldi
              wrote on last edited by
              #6

              Erm I just read your post again and see you are talking about a "service". If you mean a windows system service, then what Mark said is right: you shouldn't be using windows messages to exchange information - follow his advice and use some other form of inter process communications. :)

              2+2=5 for very large amounts of 2 (always loved that one hehe!)

              1 Reply Last reply
              0
              • M Mark Salsbery

                callousfantom wrote:

                a service written in Visual C++

                A Windows service application? If so, services run in a different desktop so you may want to use a more suitable IPC mechanism instead of window messages which don't cross the desktop boundary.

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                C Offline
                C Offline
                callousfantom
                wrote on last edited by
                #7

                Hi thanks for all the advice. I've managed to take care of it. I had to make the service interactive in order to make my application visible to it and I found no other way of making it visible due to the different user contexts. So you were right :-O

                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