Don't pass handles as a LONG

Share your advanced PureBasic knowledge/code with the community.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Don't pass handles as a LONG

Post 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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

....l is evil… very, very, very evil!..
http://www.purebasic.fr/blog/
I may look like a mule, but I'm not a complete ass.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post 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
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
freak
PureBasic Team
PureBasic Team
Posts: 5944
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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.
quidquid Latine dictum sit altum videtur
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

Whoah. I didn't know it worked in 4.20! :D
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

Very Nice ! 8)
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: Don't pass handles as a LONG

Post 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
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post 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.
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

Post by Inner »

To hell with microsoft I'm using .l :lol: :P
Post Reply