Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
For purposes of 64 bit compatibility, I've wrapped a third party DLL as a 32bit single-dialog-based MFC app. I then spawn that app and wait for it to finish in my main process, using the file that it produces.

This all works fine. To make it behave in a more integrated fashion I'm passing in the class name of my main window, so the sub-app can find it and use it as a parent for the dialog. This also works if I run the sub-app separately (with the correct command line).

However, when I spawn the child process from my main app and WaitForSingleObject the dialog is never displayed, like it got into the wait loop first. I do need to wait for my sub-app to finish, so anyone know how I can parent it properly?
Posted
Comments
George Jonsson 23-Oct-15 1:07am    
Have you tried to start the dialog using a thread?

I cannot see your code, but who told you that your WaitForSingleObject should not get in the way of your execution. It blocks any thread, no matter what it is. First of all, it looks like you don't understand what it does. There is no any "wait loops". Let me tell you: the attempts to wait something in a loop, which is called "spin wait", is the shame. Sometimes you have to do it and this is not your fault, but then its certainly due to the fault of some software or even hardware you are using

Now, the thread is blocked by putting it in a sleep state, without any loops. It means that it is switched off (preempted by the system) and marked "sleeping", never scheduled back to execution until it is waken up, which is happened on several conditions, first of all, signaled state of the object, and then timeout, and other thing. Importantly, nothing reads the condition. The OS works in an even-oriented manner, and then it wakes up the process, that is, removes sleep state and switches to this thread.

You need to figure out yourself why your dialog (or anything else) is blocked. Usually, simple logic helps, but there are complex cases with complicated multiple-point deadlock chain; and usually this is the case when you have to redesign your code in a fundamental way and simplify threading seriously. If it happens as a result of a bug, such bugs can be extremely hard to detect, so code redesign is the most feasible approach.

—SA
 
Share this answer
 
So it seems setting the dialog parent to the waiting app window was the problem, which I can kind of understand. I achieved what I wanted by finding the parent window from the class name, and passing the window to the dialog - but not to CDialog (so no parent is set). I then just used CenterWindow with the parent CWnd.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900