🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: How to check a HANDLE?

#8606
From: Bob Gonder
Date: Thu, 07 Oct 2004 19:46
36 lines
1984 bytes
Bob Gonder wrote:

>Ed Mulroy [TeamB] wrote:
>
>>Does anyone know a way supplied by Windows to check if a HANDLE is 
>>valid, maybe something similar to IsValidLocale, IsBadReadPtr or 
>>IsWindow?
>
>How about GetFileType()

Just tried it with these cases, and it only passed with the actual
open file handle.

HANDLE		ff, h;
WIN32_FIND_DATA	fblk;

h=CreateFile("filedate.txt",GENERIC_READ+GENERIC_WRITE,FILE_SHARE_READ+FILE_SHARE_WRITE,NULL,
		OPEN_ALWAYS,FILE_FLAG_SEQUENTIAL_SCAN,NULL);
if( INVALID_HANDLE_VALUE != h )
{
	if( FILE_TYPE_UNKNOWN	!= GetFileType( h ) )
		printf( "passed\r\n" );
	if( FILE_TYPE_UNKNOWN	== GetFileType( stdin ) )
		printf( "failed\r\n" );

	ff = FindFirstFile( "filedate.txt", &fblk );
	if( INVALID_HANDLE_VALUE != ff )
	{
		if( FILE_TYPE_UNKNOWN	== GetFileType( ff ) )
			printf( "failed\r\n" );
		FindClose(ff);
	};
	CloseHandle(h);
	if( FILE_TYPE_UNKNOWN	== GetFileType( h ) )
		printf( "failed\r\n" );
};
Technical Details
Message-ID: <ig6bm0tojf81g6jl4ue9mpjbu10cmdobd3@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsread.com!newsprint.newsread.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <416541a3@newsgroups.borland.com> <drpam09dboq39i6kgrhe739k85ea8t2s0t@4ax.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,d6f466f618c24d8b
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: How to check a HANDLE?
Date: Thu, 07 Oct 2004 12:46:47 -0700
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <ig6bm0tojf81g6jl4ue9mpjbu10cmdobd3@4ax.com>
References: <416541a3@newsgroups.borland.com> <drpam09dboq39i6kgrhe739k85ea8t2s0t@4ax.com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 69.34.193.40
X-Trace: newsgroups.borland.com 1097178405 69.34.193.40 (7 Oct 2004 12:46:45 -0700)
Lines: 38
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsread.com!newsprint.newsread.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail