Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Ending a process made with CreateProcess

Posted on 1997-05-10
2
Medium Priority
?
262 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

610 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