?
Solved

Ending a process made with CreateProcess

Posted on 1997-05-10
2
Medium Priority
?
260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
ete earned 100 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

770 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