Recent

Author Topic: Valid Handle?  (Read 1766 times)

Degibbo

  • New Member
  • *
  • Posts: 46
Valid Handle?
« on: February 13, 2019, 06:58:20 am »
G'day all,
I am attempting to open a USB drive with a CreateFile() call.  The handle returned is 4294967295.  A test against Invalid_Handle_Value succeeds!  This implies that 4294967295 = -1.  Calling get last error returns 0.

So, is this a valid handle or not?  It is not quite what I expected!

Any clarification would be greatly appreciated.
Cheers & thanks for the collective wisdom,
DG

ASerge

  • Hero Member
  • *****
  • Posts: 2249
Re: Valid Handle?
« Reply #1 on: February 13, 2019, 07:43:40 am »
I am attempting to open a USB drive with a CreateFile() call.  The handle returned is 4294967295.  A test against Invalid_Handle_Value succeeds!  This implies that 4294967295 = -1.  Calling get last error returns 0.
So, is this a valid handle or not? 
This is the wrong handle. But usually in this case GetLastError returns non-zero code. Maybe some other function was called between CreateFile and GetLastError?

Degibbo

  • New Member
  • *
  • Posts: 46
Re: Valid Handle? (Solved)
« Reply #2 on: February 13, 2019, 11:20:25 pm »
Thanks ASerge,
Yes, I did have another function before get last error, I sent the handle to an edit box to read it!

OK, the error is actually 5 (access denied).  Upon closer inspection of the CreateFile() function I realised that the access flags had not been set properly.

Problem now solved.
Thanks for pointing me in the right direction.
DG

 

TinyPortal © 2005-2018