UDT pointer

Windows specific questions.
Post Reply
deltarho[1859]
Posts: 4308
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

UDT pointer

Post by deltarho[1859] »

I am trying to port some Drag&Drop code from PowerBASIC.

Code: Select all

Type DragDropType
  Title As zString * 20
  hHandle As Dword
End Type
In WndProc I have

Code: Select all

Static DragDrop As DragDropType
Dim ptrDragDrop As DragDropType Ptr = @DragDrop
DragDrop.Title = "Drag and Drop"
DragDrop.hHandle = Cast(Dword, hWnd )
and ptrDragDrop is getting passed like this

............., Cast( Dword_Ptr, ptrDragDrop ) )

In the Drag&Drop function ptrDragDrop is coming in via RefData.

Compilation-wise I cannot get past the hDlg statement. I have tried everything that I can think of and this is my latest attempt.

Code: Select all

............., RefData As Dword_Ptr ) As Winbool
Dim Dummy as Uinteger Ptr
 
Dummy = Cast( Uinteger Ptr, RefData )
hDlg = Dummy->hHandle
In PowerBASIC I simply have this.

Code: Select all

.................., ByVal RefData As DragDropType Ptr) As Long
 
hDlg = @RefData.hHandle
Last edited by deltarho[1859] on Mar 25, 2018 17:02, edited 1 time in total.
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: UDT pointer

Post by fxm »

deltarho[1859] wrote:In PowerBASIC I simply have this.

Code: Select all

.................., ByVal RefData As DragDropType Ptr) As Long
 
hDlg = @RefData.hHandle
In FreeBASIC:

Code: Select all

.................., ByVal RefData As DragDropType Ptr) As Long
 
hDlg = RefData->hHandle
or:

Code: Select all

.................., ByVal RefData As DragDropType Ptr) As Long
 
hDlg = (*RefData).hHandle
deltarho[1859]
Posts: 4308
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: UDT pointer

Post by deltarho[1859] »

Thanks fxm. If only life was that simple. The problem is RefData is coming into the Drag&Drop function via Dword_Ptr and so is either a Ulong in 32 bit or Ulongint in 64 bit and why I used Uinteger in my attempt to convert RefData into a pointer. The value of RefData is a pointer but it is converted to a Dword_ptr before going to the Drag&Drop function so as to adhere to both the bi and MSDN. It is the last parameter of the Windows API SetWindowSubclass.
sancho3
Posts: 358
Joined: Sep 30, 2017 3:22

Re: UDT pointer

Post by sancho3 »

Code: Select all

Dummy = Cast( Uinteger Ptr, RefData )
hDlg = Dummy->hHandle
Dummy is a UInteger pointer so it doesn't have a hHandle to retreive.

You say you tried lots of variations so this is one you probably already have tried but...
Can you not cast RefData straight to DragDropType ptr?

Code: Select all

hDlg = Cast(DragDropType ptr, RefData)->hHandle
Its also worth checking to see that RefData is the pointer you think it is at that point.
deltarho[1859]
Posts: 4308
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: UDT pointer

Post by deltarho[1859] »

That worked sancho3.

I did not try DragDropType ptr because I didn't think the Drag&Drop function would know what that was being defined in WndProc.

The problem coming from PowerBASIC is that there is no distinction between a scalar and a pointer - they are both 32 bit values and it is our responsibility as to how to use the value in question.

Thank you.
Post Reply