Discussion:
HANDLE INVALID_HANDLE_VALUE is 0xfffffffe and not 0xffffffff
Philipp Kursawe
2010-02-23 11:19:58 UTC
Permalink
Hello,

I am still struggling with

HANDLE INVALID_HANDLE_VALUE = new HANDLE(Pointer.createConstant(0xffffffff));

It turns out as:
this W32API$HANDLE (id=185)
immutable true
pointer Pointer$Opaque (id=1499) ***@0xffffffffffffffff

however the toString() of INVALID_HANDLE_VALUE displays:
com.sun.jna.examples.win32.W32API$***@fffffffe

And a HANDLE value returned from CreateFile is:
o W32API$HANDLE (id=165)
immutable false
pointer Pointer (id=1497)
peer 4294967295
toString() = com.sun.jna.examples.win32.W32API$***@ffffffff

Whats going on here? That way its just not possible to use
INVALID_HANDLE_VALUE.equals(CreateFile(...));

Running on Windows 32bit.

Phil
Timothy Wall
2010-02-23 14:18:07 UTC
Permalink
The definition of INVALID_HANDLE_VALUE is incorrect. I have fixed it
in SVN to be the following:

new HANDLE(Pointer.createConstant(Pointer.SIZE==8?-1:0xFFFFFFFF));
Post by Philipp Kursawe
Hello,
I am still struggling with
HANDLE INVALID_HANDLE_VALUE = new
HANDLE(Pointer.createConstant(0xffffffff));
this W32API$HANDLE (id=185)
immutable true
o W32API$HANDLE (id=165)
immutable false
pointer Pointer (id=1497)
peer 4294967295
Whats going on here? That way its just not possible to use
INVALID_HANDLE_VALUE.equals(CreateFile(...));
Running on Windows 32bit.
Phil
---------------------------------------------------------------------
Philipp Kursawe
2010-02-23 14:42:36 UTC
Permalink
Thanks Timothy, but as you could see in my sample code, I had already
fixed that locally.
The constant is still 0xfffffffe according to toString().
Are there *any* Unit tests that check this faulty behaviour?

Thanks,
Phil
The definition of INVALID_HANDLE_VALUE is incorrect.  I have fixed it in SVN
   new HANDLE(Pointer.createConstant(Pointer.SIZE==8?-1:0xFFFFFFFF));
Post by Philipp Kursawe
Hello,
I am still struggling with
HANDLE INVALID_HANDLE_VALUE = new
HANDLE(Pointer.createConstant(0xffffffff));
this    W32API$HANDLE  (id=185)
       immutable       true
o       W32API$HANDLE  (id=165)
       immutable       false
       pointer Pointer  (id=1497)
               peer    4294967295
Whats going on here? That way its just not possible to use
INVALID_HANDLE_VALUE.equals(CreateFile(...));
Running on Windows 32bit.
Phil
---------------------------------------------------------------------
---------------------------------------------------------------------
--
The Dude Abides!
Timothy Wall
2010-02-23 20:18:49 UTC
Permalink
I don't know why you'd be getting "-2" as the peer pointer value, but
you do need to pass an explicit long value to avoid sign extension, e.g.

Pointer.createConstant(0xFFFFFFFFL)

Otherwise the int gets promoted to long with sign extension.
Post by Philipp Kursawe
Thanks Timothy, but as you could see in my sample code, I had already
fixed that locally.
The constant is still 0xfffffffe according to toString().
Are there *any* Unit tests that check this faulty behaviour?
Post by Philipp Kursawe
Post by Philipp Kursawe
I am still struggling with
HANDLE INVALID_HANDLE_VALUE = new
HANDLE(Pointer.createConstant(0xffffffff));
this W32API$HANDLE (id=185)
immutable true
pointer Pointer$Opaque (id=1499)
o W32API$HANDLE (id=165)
immutable false
pointer Pointer (id=1497)
peer 4294967295
Whats going on here? That way its just not possible to use
INVALID_HANDLE_VALUE.equals(CreateFile(...));
Running on Windows 32bit.
Phil
---------------------------------------------------------------------
---------------------------------------------------------------------
--
The Dude Abides!
---------------------------------------------------------------------
Philipp Kursawe
2010-02-23 20:58:25 UTC
Permalink
Hello Timothy,
I don't know why you'd be getting "-2" as the peer pointer value, but you do
need to pass an explicit long value to avoid sign extension, e.g.
Pointer.createConstant(0xFFFFFFFFL)
THAT did it! Thanks. So you might wanna change that in the SVN trunk
to 0xffffffffL also.
Timothy Wall
2010-02-23 23:13:16 UTC
Permalink
Post by Philipp Kursawe
Hello Timothy,
On Tue, Feb 23, 2010 at 9:18 PM, Timothy Wall
I don't know why you'd be getting "-2" as the peer pointer value, but you do
need to pass an explicit long value to avoid sign extension, e.g.
Pointer.createConstant(0xFFFFFFFFL)
THAT did it! Thanks. So you might wanna change that in the SVN trunk
to 0xffffffffL also.
Done. Also added a createConstant(int) which masks out the upper bits
automatically.

Glad you got it working.

T.

Loading...