Thread View: borland.public.cppbuilder.nativeapi
2 messages
2 total messages
Started by Christian Lotze
Thu, 05 Jun 2008 07:25
CreateFile/CloseHandle increases win32 Handle Count
Author: Christian Lotze
Date: Thu, 05 Jun 2008 07:25
Date: Thu, 05 Jun 2008 07:25
27 lines
1725 bytes
1725 bytes
Hi all,
I'm reading an external harddisk directly with:
DeviceString = "\\\\.\\PHYSICALDRIVE"+IntToStr( HardDisk );
hDevice = CreateFile( DeviceString.c_str(),
GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
0);
..... (SetFilePointer/ReadFile)
CloseHandle(hDevice);
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?
Thanks, Christian
Re: CreateFile/CloseHandle increases win32 Handle Count
Author: Bob Gonder
Date: Thu, 05 Jun 2008 14:27
Date: Thu, 05 Jun 2008 14:27
47 lines
1979 bytes
1979 bytes
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;
}
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads