Solved

Ending a process made with CreateProcess

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

10 Experts available now in Live!

Get 1:1 Help Now