Callback from other thread

1

I have problem with callbacks from other application thread. Dll is some kind of wrapper between Addinational application and Application program and its working within Application program memory(with same PID). Addinational application(other thread and PID) is application which in main loop looking for "something" and when found it, it calls Callback function from Dll and then Dll calls Callback function from Application program. Maybe its little confusing look at image above. And theres crash(when dll calls callback function from application program) with message:

Unhandled exception at 0x70786a46 in MainProgram.exe: 0xC0000005: Access violation reading location 0x00000164.

Call stack mshtml.dll

Propably application program using IE controls to update UI. How could I update UI when Addinational application callsback?

Callbacks

c++
dll
callback
asked on Stack Overflow Mar 1, 2012 by user1112008 • edited Jun 20, 2020 by Community

2 Answers

1

SendMessage is a general solution for posting results to a GUI thread. It does all thread synchronization for you and doesn’t return until the message has been processed by the receiver thread's window.

PostThreadMessage is less reliable since the message may/will be lost when the receiver is in a modal loop for e.g. MessageBox, unless you have added a hook that intercepts the thread message – so just use SendMessage.

More advanced techniques involve doing the thread synchronization yourself, e.g. with a buffer, but anyway that will probably also involve SendMessage for a GUI thread, so, I suggest you just start with that, and if that’s good enough, then don’t do more.

EDIT: dang, I see now that although the first sentence talks about threads, it's really about sending data from one process to another process. Well, for that there is WM_COPYDATA. Please consider that a (user level) pointer from one process, is not valid in the other process.

answered on Stack Overflow Mar 1, 2012 by Cheers and hth. - Alf • edited Mar 1, 2012 by Cheers and hth. - Alf
0

So you want to call a function that belongs to another process. I think you need to read about RPC:s http://msdn.microsoft.com/en-us/library/windows/desktop/aa378651%28v=vs.85%29.aspx

answered on Stack Overflow Mar 1, 2012 by user877329

User contributions licensed under CC BY-SA 3.0