?
Solved

CreateProcess resource allocation issue

Posted on 2004-04-30
4
Medium Priority
?
202 Views
Last Modified: 2010-04-05
Hi,

I am creating a process from my Delphi 7 application. I wait for it to complete and then continue execution of my program. Here is my code:

FillChar(StartupInfo, SizeOf(StartupInfo), 0);
FillChar(ProcessInfo, SizeOf(ProcessInfo), 0);
if CreateProcess(nil, PChar(CommandLine), nil, nil, True, 0, nil, nil, StartupInfo, ProcessInfo) then
  repeat
    Application.ProcessMessages;
    GetExitCodeProcess(ProcessInfo.hProcess, ExitCode);
  until (ExitCode <> STILL_ACTIVE) or Application.Terminated;

It works fine. My problem is that Memory Sleuth indicates that there is a Thread Handle and a Process Handle still allocated once my application terminates.

My question is, how do I free these resources?

Regards,

Bill
0
Comment
Question by:wipnav
[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
  • 3
4 Comments
 
LVL 17

Expert Comment

by:geobul
ID: 10961724
Hi,

Add these two lines at the end of your code:

CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread );

Regards, Geo
0
 
LVL 17

Accepted Solution

by:
geobul earned 1000 total points
ID: 10961750
if CreateProcess(nil, PChar(CommandLine), nil, nil, True, 0, nil, nil, StartupInfo, ProcessInfo) then
  try
    repeat
      Application.ProcessMessages;
      GetExitCodeProcess(ProcessInfo.hProcess, ExitCode);
    until (ExitCode <> STILL_ACTIVE) or Application.Terminated;
  finally
    CloseHandle(ProcessInfo.hProcess);
    CloseHandle(ProcessInfo.hThread );
  end;

Regards, Geo
0
 
LVL 1

Author Comment

by:wipnav
ID: 10961914
Geo,

Perfect!

Thank you very much.

Regards,

Bill
0
 
LVL 17

Expert Comment

by:geobul
ID: 10962050
You are welcome :-)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month14 days, 14 hours left to enroll

771 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