How to convert from byte ptr to type instance ?

BlitzMax Forums/BlitzMax Programming/How to convert from byte ptr to type instance ?

Well it is related to winapi. Envolving the window/bmax type indexing problem. You can easily assign a pointer to a speciffic window using a custom windows class that has extra window bytes. Then you have instant access to a bmax type per window, isntead of having to search a list of hwnds to find a match each and every msg loop.

Im sure there are many other reasons to be able to do this, but the one above is a good enough example of what its good for really.

The way it works is like this.

Create window in winapi
Create gadget instance in bmax
Store pointer to gadget instance in the USERDATA belonging to that window
When message is recieved with hwnd, use GetWindowLong to check if the window has an associated gadget instance in bmax.

* voila very effecient windows messaging.

I have reverted to using an array of type instance, and store the array index with the window. Its usable but could be a whole lot easier if we could just cast from pointer to type. As it is, it means I have to mess with resizing arrays, and lose all the functionality of using a linked list.

Oh and this is what I have to end up doing to get around the fact you cant cast from pointer to type.
If msg = api_WM_NCCREATE
	'declare locals
	Local bank:TBank,pointer:Byte Ptr
	bank = CreateStaticBank(lparam,4)
	pointer = Byte Ptr(bank.PeekInt(0))
	bank = CreateStaticBank(pointer,4)
	pointer = Byte Ptr(bank.PeekInt(0))
	bank = CreateStaticBank(pointer,4)
	'setup gadget
	gadget = acwin32_gadgetarray[bank.PeekInt(0)]
	gadget.hwnd = hwnd
	'set gadget arrayid in window extended bytes

	api_SetWindowLong(hwnd,acwin32_windowbytes_arrayid,gadget.arrayid)

End if


Not very pleasant aye ?