Link to home
Start Free TrialLog in
Avatar of jrsenthilk
jrsenthilk

asked on

INVALID_HANDLE_VALUE in c#

Hi
How do i define INVALID_HANDLE_VALUE in c#..
I am using CreateFile and i am trying to check the return value..

and also how do i check if CreateFile returned a valid handle or not..
Any sample code in C#

Thank you very much...
Avatar of MogalManic
MogalManic
Flag of United States of America image

If you use System.IO.File.Create(fileName) it will return a valid FileStream object.  If you want to create a TextFile, use System.IO.File.CreateText(fileName) which will return a TextWriter.

Ether of these methods will NOT return an invalid file handle.  If anything goes wrong, an exception will be thrown.

See the following samples from Microsoft:
  http://msdn.microsoft.com/en-us/library/6ka1wd3w(VS.80).aspx
  http://msdn.microsoft.com/en-us/library/36b93480(VS.80).aspx
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Pretty sure he's talking about the CreateFile() API MogalManic...
http://msdn.microsoft.com/en-us/library/aa363858(VS.85).aspx

    Return Value
    If the function succeeds, the return value is an open handle to the specified file, device, named pipe, or mail slot.
    If the function fails, the return value is INVALID_HANDLE_VALUE. To get extended error information, call GetLastError.

Avatar of jrsenthilk
jrsenthilk

ASKER

hi Idle mind,
That was just exactly what i was looking for.
Thank you very much.... It was really very helpful..
Cheers..