Page 1 of 1

Don't pass handles as a LONG

Posted: Wed Nov 19, 2008 1:30 pm
by Mistrel
According to Microsoft an API handle is a pointer so use the integer data type in PureBasic (.i).

http://msdn.microsoft.com/en-us/library/aa383751

Posted: Wed Nov 19, 2008 1:46 pm
by srod
....l is evil… very, very, very evil!..
http://www.purebasic.fr/blog/

Posted: Thu Nov 20, 2008 2:39 am
by pdwyer
64bit issues aside for a moment,

I was wondering about this .i thing the other day too. I had some ported code with .i in it and it worked. (for a little while). I started seeing issues with it and so I checked the doc

http://www.purebasic.com/documentation/ ... ables.html

This is no .i! :shock:

Is its a 16 or 32bit signed int? It compiled in 4.2 but it's not documented and the code I was working on was fixed by changing it to .w as I needed a 16bit var.

On the 64bit side it would probably be worth having a macro for a "handle" type which is a 32bit var or 64bit var depending on conditional compile. But I haven't touched 64bit programming yet so I don't know if that created more issues

Posted: Thu Nov 20, 2008 3:18 am
by freak
Its the new integer type (32bit or 64bit depending on the CPU).

It officially exists since 4.30 (and will be documented there), but it actually works in 4.20 too as the development of PB x64 has been going on since then.

Posted: Thu Nov 20, 2008 3:31 am
by Mistrel
Whoah. I didn't know it worked in 4.20! :D

Posted: Thu Nov 20, 2008 8:20 am
by pdwyer
Very Nice ! 8)

Re: Don't pass handles as a LONG

Posted: Thu Nov 20, 2008 10:07 am
by Psychophanta
Mistrel wrote:According to Microsoft an API handle is a pointer so use the integer data type in PureBasic (.i).

http://msdn.microsoft.com/en-us/library/aa383751
I have asked more than one time about what the hell is a "handle" in this forum, to Fred, etc., and nobody was able to answer it.
I suspected it was a pointer but was not sure, so Thank you. :D

Posted: Thu Nov 20, 2008 2:59 pm
by pdwyer
http://en.wikipedia.org/wiki/Handle_(computing)
A handle is a particular kind of smart pointer. Handles are used when an application references blocks of memory or objects managed by another system, such as a database or an operating system. While a pointer literally contains the address of the item to which it refers, a handle is an abstract reference controlled by a separate system; its opacity allows the referent to be relocated in memory by the system without invalidating the handle — impossible with pointers. The extra layer of indirection also increases the control the managing system has over operations performed on the referent (see information hiding, encapsulation).

Handles were a popular solution to memory management in operating systems of the 1980s, such as Mac OS and Windows. Unix file descriptors are essentially handles. Like other desktop environments, the Windows API heavily uses handles to represent objects in the system and to provide a communication pathway between the operating system and user space. For example, a window on the desktop is represented by a handle of type HWND.

Traditional, doubly-indirect handles have fallen out of favour in recent times, as increases in available memory and improved virtual memory algorithms have made the use of the simpler pointer more attractive. However, many operating systems still apply the term to pointers to opaque, "private" data structures, or indexes into internal arrays passed from one process to its clients.

Posted: Fri Nov 21, 2008 4:31 am
by Inner
To hell with microsoft I'm using .l :lol: :P