Broadcasting custom windows message(Interprocess communication)
-
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?
-
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?
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!)
-
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?
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:
-
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!)
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.
-
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:
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:
-
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.
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!)
-
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:
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