Solved

Ending a process made with CreateProcess

Posted on 1997-05-10
2
251 Views
Last Modified: 2013-12-04
Hello,

I've made an application running under Win'95 wich uses an 3270 emulator to communicate with the MainFrame.
As soon as a user pushes a button in my application an emulator gets started up. I use CreateProcess to do this. This works perfectly.
Now I want  to get rid of the emulator when the user pushes the "quit" button.  I can't   get this right.
When I try to use ExitProcess, MY application gets killed and NOT the emulator.
So I tried the next thing:

OpenProcess(ProcessId, bla bla). wich gives me the ProcessHandle.
TerminateProcess(ProcessHandle,  ExitCode)

This actually kills the emulator. Just as I want to. But when I try to restart my application I get errors or warnings telling me some objects and dll's can't be found.
 
How do I kill my Emulator (created with CreateProcess) neatly? And can someone tell me what it is that I did
wrong?

Oh, and I also tried to kill the thread instead of the process,
resulting in the same thing.

I use the Winhllapi.
Thanks in advance!

Greetings
Gino Talamini
Gino.Talamini@tip.nl
0
Comment
Question by:GinoTalamini
2 Comments
 
LVL 1

Accepted Solution

by:
ete earned 50 total points
ID: 1397248
Dear Gino,
You not actually doing anything wrong at all. Process control in Win32 API is rather limited. ExitProcess() is MEANT to kill the current process. The TerminateProcess() is meant only for extreme circumstances. It DOES NOT NOTIFY the DLL:s which are attached to the process, that the process is killed and it does not necessarily remove the process object from the system. That is why it may cause undesirable side effects.

However, you have some means to overcome the problem.

Dynamic way is to use a Process Control library like DirectIPC, which has a function DxIpcCloseProcessGracefully(). (dxipc32.exe in www.winsite.com or ftp.winsite.com at Windows NT programming utilities)

Simple but "hard coded" way exists also. Use Spy++ (comes with Microsoft programming environments) or similar to find the window class name of your emulator program. Then call FindWindow() API from your own app with this hard coded class name to get the window handle. Test which one of the following messages gives the best result:

WM_CLOSE
WM_DESTROY
WM_QUIT

I hope this helps you. If you have any details to ask, please let me know.

Regards ETE
0
 

Author Comment

by:GinoTalamini
ID: 1397249
Thanks a  lot for your  explanation. I'll see what resources I've got  to work with other than the API. I really  haven't  got  that much to work  with.  I do  not have a speciallized   Window   Development Kit,   but I can't  get arround   Windows so I  have  to  cope  with any problems that come  with it. The  less uses  libraries the  better.
Thanks again, I'll  try it monday!
Greetings
Gino Talamini
Gino.Talamini@tip.nl
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now