🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: CreateFile/CloseHandle increases win32 Handle Count

#113
From: Christian Lotze
Date: Thu, 05 Jun 2008 14:46
66 lines
3153 bytes
Bob Gonder schrieb:
> Christian Lotze wrote:
> 
>> This increases count of win32 handles every time
>>  Createfile creates two handles
>>  CloseHandle closes only one of theses handles
>>
>> (You can monitor this behaviour with processexplorer.)
>> Any hints?
> 
> You must be doing something else.
> This app shows only one more handle after CreateFile.
> And it goes away after DeleteHandle.
> Do you have PE set to show all of the handle details?
> 
> #include	"windows.h"
> #include	<conio.h>
> 
> void pause(void)
> {	cputs( "\r\nCheck for number of handles, then press any key");
> 	getch();
> }
> 
> int main(void)
> {	HANDLE		h;
> 	DWORD		written;
> 	char		str[1024];
> 
> 	pause();
> 	h = CreateFile( "\\\\.\\PHYSICALDRIVE0",
>                          GENERIC_READ,
>                          FILE_SHARE_READ | FILE_SHARE_WRITE,
>                          NULL,
>                          OPEN_EXISTING,
>                          0,
>                          0);
> 	if(INVALID_HANDLE_VALUE!=h)
> 	{
> 		pause();
> 		SetFilePointer(h,0,NULL,FILE_BEGIN);
> 		pause();
> 		ReadFile(h,str,sizeof(str), &written,0);
> 		pause();
> 		CloseHandle(h);
> 		pause();
> 	};
> 	return 0;
> }
> 
> 

Using BDS 2007:
Just setup new VCL form application put button onto form and copy your 
code (except Pause function) to that button handler. During debug 
session Handle Count in PE increases by 2 at CreateFile and decreases by 
1 at CloseHandle

Installed trial version of TaskInfo (http://www.iarsn.com/taskinfo.html)
->
Handle Type            Refs Name
F78:   Device Obj      3/1  \Device\Harddisk0\DR0
F7C:   Obj Directory  11/2  \Sessions\0\DosDevices\00000000-00035ff2
F80:   Obj Directory  11/2  \Sessions\0\DosDevices\00000000-00035ff2

F78/f7c created be CreateFile
F80 not closed by previous  CreateFile/Closehandle!
Technical Details
Message-ID: <4847fc2a$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!npeer02.iad!npeer01.iad!news.highwinds-media.com!newsfeed2.telusplanet.net!newsfeed.telus.net!indigo.octanews.net!news-out.octanews.net!mauve.octanews.net!news-out.readnews.com!transit3.readnews.com!207.99.111.53.MISMATCH!newspeer1.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <484794e5@newsgroups.borland.com> <t9tf44p56a7h577cn5re908cm3i652v55l@4ax.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,93e619dfbda10652
X-Google-Attributes: gid10cc67,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Thu, 05 Jun 2008 16:46:02 +0200
From: Christian Lotze <Chrissi099@hotmail.com>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.14) Gecko/20080421 Thunderbird/2.0.0.14 Mnenhy/0.7.5.0
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: CreateFile/CloseHandle increases win32 Handle Count
References: <484794e5@newsgroups.borland.com> <t9tf44p56a7h577cn5re908cm3i652v55l@4ax.com>
In-Reply-To: <t9tf44p56a7h577cn5re908cm3i652v55l@4ax.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 217.86.155.108
Message-ID: <4847fc2a$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1212677162 217.86.155.108 (5 Jun 2008 07:46:02 -0700)
Lines: 68
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!npeer02.iad!npeer01.iad!news.highwinds-media.com!newsfeed2.telusplanet.net!newsfeed.telus.net!indigo.octanews.net!news-out.octanews.net!mauve.octanews.net!news-out.readnews.com!transit3.readnews.com!207.99.111.53.MISMATCH!newspeer1.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail