Click here to Skip to main content
15,885,985 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionSendMessage for Interprocess communication stops working Pin
ForNow1-Nov-16 15:29
ForNow1-Nov-16 15:29 
AnswerRe: SendMessage for Interprocess communication stops working Pin
Midi_Mick1-Nov-16 16:16
professionalMidi_Mick1-Nov-16 16:16 
GeneralRe: SendMessage for Interprocess communication stops working Pin
ForNow1-Nov-16 16:22
ForNow1-Nov-16 16:22 
GeneralRe: SendMessage for Interprocess communication stops working Pin
Midi_Mick1-Nov-16 17:36
professionalMidi_Mick1-Nov-16 17:36 
AnswerRe: SendMessage for Interprocess communication stops working Pin
Randor 1-Nov-16 17:56
professional Randor 1-Nov-16 17:56 
GeneralRe: SendMessage for Interprocess communication stops working Pin
ForNow2-Nov-16 13:59
ForNow2-Nov-16 13:59 
GeneralRe: SendMessage for Interprocess communication stops working Pin
Randor 2-Nov-16 16:42
professional Randor 2-Nov-16 16:42 
AnswerRe: SendMessage for Interprocess communication stops working Pin
leon de boer2-Nov-16 3:10
leon de boer2-Nov-16 3:10 
Lets first discuss the general Windows cases. Basic rule never use SendMessage between any windows that you don't directly know the message arrangements use PostMessage instead. The other trap with SendMessage is it is easy to go circular (happens a lot when playing around with scrollbar code Smile | :) ). Make sure the send message handling doesn't send a messsage back to the caller which then sends off another message and around and around it goes.

I also have a scary feeling you have a different thread on the console app given the title Interprocess. If that is true you can not blindly use SendMessage, it crosses a thread boundary and it will deadlock .... Guaranteed if done raw. It is sort of covered in the Microsoft discussion of SendMessage when they talk about the data marshalling and playing around with SendMessageTimeout. The easier solution is just don't use it, PostMessage is there and has no issues. If you need a response back you post back another message so you setup a ping/pong message system using PostMessage, saves a lot of effort and heartache.

In the directory watcher code I did for you that is why I used PostMessage in the thread not SendMessage. Use SendMessage there and it will Deadlock randomly.
// Post off message back to application window.
PostMessage(watchData->AppWindow, watchData->MsgId, watchData->CmdId, (LPARAM)msgToApp);


Randor in his post is correct if you want to tow the "Microsoft line", so I guess look at is what you are coding a critical system. Historically most have always used WM_USER and I have never seen a clash because there is really only you, Windows and your framework that post messages around inside your application and you can see it in testing and debugging on your machine. This isn't a bug that would suddenly appear in the field or such, it was always more a problem if you had two or more programmers and they both selected the same message number you got some funny things happen. Anyhow if you are going to stick to messages perhaps move up to WM_APP messages (It came in with Windows 95) because that range is designed to do exactly what you are doing and will be one more bit of safety. None of these message ranges go inside/outside your applications so it's only stuff within your application you have to worry about.

AFAIK windows itself puts no messages into the WM_USER range these days because of the data marshal requirements and I believe it has been like that since Win95. Even the classic old ones like LB_ADDSTRING got moved into the standard windows range. LB_ADDSTRING used to be WM_USER + 1 which is why us old timers used to go for WM_USER+100, it was our goto number Smile | :)

For what it's worth having two window elements with the same ID happens a lot more and is just as catastrophic. There is no way to stop it happening except by controlling the allocation of ID numbers to elements. An interesting programming office prank was to get hold of a resource editor and move the ID numbers around on exe which had the resources bound and watch the fun that followed (Borlands whitewater resource kit was so good at it). Some even had the menus in the resource and you could change the menu ID numbers.
In vino veritas


modified 2-Nov-16 10:36am.

GeneralRe: SendMessage for Interprocess communication stops working Pin
ForNow2-Nov-16 14:32
ForNow2-Nov-16 14:32 
GeneralRe: SendMessage for Interprocess communication stops working Pin
leon de boer2-Nov-16 16:57
leon de boer2-Nov-16 16:57 
QuestionNeed help with cryptography Pin
SMD1111-Nov-16 8:54
SMD1111-Nov-16 8:54 
AnswerRe: Need help with cryptography Pin
Randor 1-Nov-16 19:04
professional Randor 1-Nov-16 19:04 
Question[C]Problem in creating a random string Pin
xXxRevolutionxXx27-Oct-16 1:31
xXxRevolutionxXx27-Oct-16 1:31 
AnswerRe: [C]Problem in creating a random string Pin
Richard MacCutchan27-Oct-16 1:46
mveRichard MacCutchan27-Oct-16 1:46 
GeneralRe: [C]Problem in creating a random string Pin
k505427-Oct-16 4:47
mvek505427-Oct-16 4:47 
GeneralRe: [C]Problem in creating a random string Pin
Richard MacCutchan27-Oct-16 4:55
mveRichard MacCutchan27-Oct-16 4:55 
AnswerRe: [C]Problem in creating a random string Pin
Jochen Arndt27-Oct-16 2:35
professionalJochen Arndt27-Oct-16 2:35 
AnswerRe: [C]Problem in creating a random string Pin
leon de boer27-Oct-16 3:43
leon de boer27-Oct-16 3:43 
SuggestionRe: [C]Problem in creating a random string Pin
David Crow27-Oct-16 4:48
David Crow27-Oct-16 4:48 
GeneralRe: [C]Problem in creating a random string Pin
Daniel Pfeffer27-Oct-16 5:11
professionalDaniel Pfeffer27-Oct-16 5:11 
AnswerRe: [C]Problem in creating a random string Pin
Krishnakumartg27-Oct-16 20:18
Krishnakumartg27-Oct-16 20:18 
GeneralRe: [C]Problem in creating a random string Pin
k505428-Oct-16 4:59
mvek505428-Oct-16 4:59 
PraiseRe: [C]Problem in creating a random string Pin
Krishnakumartg30-Oct-16 18:50
Krishnakumartg30-Oct-16 18:50 
QuestionRe: [C]Problem in creating a random string Pin
David Crow31-Oct-16 2:31
David Crow31-Oct-16 2:31 
QuestionUsing COM in DLL called by .Net application Pin
Leif Simon Goodwin26-Oct-16 3:02
Leif Simon Goodwin26-Oct-16 3:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.