🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #5993

Re: kill process?

#5993
From: Ron Eggler work
Date: Thu, 16 Jun 2005 13:55
53 lines
2797 bytes
Danila Vershinin wrote:
> "Ron Eggler @ work" <nospam@hotmail.com> wrote in message
> news:42b02536$1@newsgroups.borland.com...
>> Now my question is: is it possible for me to check if there is
>> annother open instance of my project and kill it before I gonna try
>> to initialize again?
>
> Yes this is possible. Look at other threads or search google groups
> for "allowing only one instance of an application"
> After you have read how this should be done (allowing only one
> instance), if you wish, I will put here my code to kill process.

Hey Danila,

I found this:
http://groups.google.ch/group/borland.public.delphi.students/browse_thread/t
hread/84815bc5e324e56b/e27e72b347ab6da3?q=%22allowing+only+one+instance+of+a
n+application%22&rnum=4&hl=de#e27e72b347ab6da3

I tried to change the code to a c++ one and it looks like this (I think):

bool ContinueLoop;
THandle FSnapshotHandle;
TProcessEntry32 FProcessEntry32;
#define PROCESS_TERMINATE 0x0001;
{
result=0;
FSnapshotHandle=CreateToolhel�p32Snapshot(TH32CS_SNAPPROCESS�,0);
FProcessEntry32.dwSize=Sizeof�(FProcessEntry32);
ContinueLoop=Process32First(F�SnapshotHandle,FProcessEntry32�);
while (int(ContinueLoop)<>0)
  {

if((UpperCase(ExtractFileName(FP�rocessEntry32.szExeFile))==Uppe�rCase(FileN
ame))
           || (UpperCase(FProcessEntry32.szE�xeFile)==UpperCase(FileName)))
    {
    result++;
    ContinueLoop=Process32Next(FS�napshotHandle,FProcessEntry32);
    }
    CloseHandle(FSnapshotHandle);
}

I moved that code in the WinMain()-function. And when I tried to compile the
compiler said it wouldn't know TProcessEntry32. Okay let's google... Ah it's
defined in Tlhelp32. ok, included it at the top of Project.cpp.
But the type TProcessEntry32 is still unknown. now I get stucked and it
would be pretty nice if you'd be able to help me.
Thank you!

--
keep on rockin'
roN
Technical Details
Message-ID: <42b184e4@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <42b02536$1@newsgroups.borland.com> <42b1635a@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,d9980975a6334c47
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII
From: "Ron Eggler @ work" <nospam@hotmail.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <42b02536$1@newsgroups.borland.com> <42b1635a@newsgroups.borland.com>
Subject: Re: kill process?
Date: Thu, 16 Jun 2005 15:55:49 +0200
Lines: 55
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
NNTP-Posting-Host: 194.147.52.1
Message-ID: <42b184e4@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1118930148 194.147.52.1 (16 Jun 2005 06:55:48 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail