Solved

Ending a process made with CreateProcess

Posted on 1997-05-10
2
253 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Insert filename column as column a 18 76
VS2015 compilation and missing DLLs 9 161
Strange - Deleted Resource Info appears in Azure Portal 6 91
Is COM supported from Apache 1 63
This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
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…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

840 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