Externs and Byte Ptr
BlitzMax Forums/BlitzMax Programming/Externs and Byte Ptr
| ||
Why use Byte Ptr and not say Int Ptr for this?Extern "win32" Function GlobalMemoryStatus(lpBuffer:Byte Ptr) End Extern lpBuffer is supposed to be this structure: Type TMemoryStatus 'for use with GlobalMemoryStatus Field dwLength:Int Field dwMemoryLoad:Int Field dwTotalPhys:Int Field dwAvailPhys:Int Field dwTotalPageFile:Int Field dwAvailPageFile:Int Field dwTotalVirtual:Int Field dwAvailVirtual:Int Method New() 'Must set the length. dwLength=SizeOf(TMemoryStatus) End Method EndType And if I create an instance of TMemoryStatus with new and pass it into GlobalMemoryStatus, it works totally fine. Thing is I don't really understand what's going on. Why is Byte Ptr is used in the function declaration instead of say Int Ptr? Is Byte pointer the normal thing you use when you point to a Type (structure) because it's a pointer to an area of memory that can be read as bytes, or what? Thanks for any insight, hope I'm making myself clear. I still haven't had that cup of tea... |
| ||
Is Byte pointer the normal thing you use when you point to a Type Byte Ptr is what I use all the time for referring to a point in memory for structs and the likes. If it happened to be an array of Ints, you could refer to it either by a Byte Ptr, or more usefully as an Int Ptr, with which you could then do something like - i = Int Ptr(mypointer)[0] - to get the first integer in the array. Byte Ptr is just convenient. If you need the real address you can cast it to Int - Int(myPtr). |
| ||
Ah very handy thanks! Did you see this thread? http://www.blitzbasic.com/Community/posts.php?topic=73289 I'm trying to pass an array of types (structures) into a WinAPI function but failing badly... |
| ||
Seems like objects can only be cast to Byte Ptr because it doesn't demand how the data is aligned. Int Ptr doesn't work. |
| ||
Ah I see, yes that makes sense. |