Academia said:
I'm sure what I'm writing will not run on Win64 so why IntPtr.
I been using Integer since vb.NET didn't allow UInteger when I wrote
the definitions.
Almost all my usage of SendMessage returns a numerical value that
fits into a Integer so why use IntPtr and have to convert the return
to Integer?
Well, IntPtr is the correct translation that works on Win32 and Win64.
Look at the type of the property System.Windows.Forms.Message.Result.
It's IntPtr, too.
If you know it will never run on Win64, you can choose Integer, too.
However, maybe one day you will wish you had chosen Intptr because you
will have to change Integer to Intpr everywhere. Though, that's up to
you to decide, of course.
It's not clear in my mind but I think even if
SendMessage returned a negative value and I had defined the return
value as Integer it would work OK wouldn't it?
Yep
I don't know what would happen if it returned a negative value and I
had defined the return as UInteger.
Nothing happens. It's just a matter of interpretation. The runtime can't
know whether the MSB is a sign or belongs to the value.
Would CInt() or CType() convert that return to an Integer by just
changing types without doing anything to the bits?
This fails because the value is > Integer.Maxvalue:
Dim u As UInteger = &H80000000UI
Dim i As Integer = CInt(u)
You could use the Bitconverter instead:
i = BitConverter.ToInt32(BitConverter.GetBytes(u), 0)
- or leave it in an UInteger
If you need it later: ;-)
http://msdn2.microsoft.com/en-us/library/ms973190.aspx
Armin