1. Yakov Werde
  2. PowerBuilder
  3. Monday, 27 March 2017 14:14 PM UTC

Hello All,

We are preparing for dual platform 64 / 32 bit deployment. "What's New" documentation describes changing handle datatype to LongPtr

The longptr datatype is 4 bytes in the 32-bit platform and 8 bytes in the 64-bit platform. In the 32-bit platform, longptr is the same as long; you can continue using long wherever longptr is required in 32-bit applications. In 64-bit applications, however, using long to hold longptr variables will lead to data truncation from 8 bytes to 4 bytes, or memory corruption if you pass a long ref variable when a longptr ref is required. If you want to move to 64-bit, use longptr wherever required. It does no harm to 32-bit.  

Later on the doc does say " If you want to represent/compute 8-byte long integers, use longlong"

First off in testing I discovered a nasty bug. "SAP created cr806730 for this issue - calling external function that is returning a longptr, in 64-bit, application returning 0."  At the current time, longptr does NOT work!

In the interim, SAP support suggested using LongLong as external function parm types and to capture returned handles.  But since LongLongs are 64-bit *signed* integers and LongPtr is a 'pointer type', that is supposed to be cross platform compatible, I am unsure of the ramifications of the change.  I don't want to have to refactor our code twice.

I did find this in MS documentation: •Pointer Truncation—Although a 32-bit application can use the LONGLONG data type to store a 64-bit value, there are instances where no Windows API element exists that would enable the 32-bit application to receive a 64-bit value from a 64-bit process, or to send a 64-bit value to a 64-bit process.

My question: Is possible to always use LongLong instead of LongPtr?  Is there any reason not to do so?

Thanks for sharing your knowledge on this subject

Yakov

 

Yakov Werde Accepted Answer Pending Moderation
  1. Monday, 27 March 2017 20:11 PM UTC
  2. PowerBuilder
  3. # 1

FYI:  The PB handle( ) function returns LongPtr .  The doc was not updated it still says return type is long. 

To see for yourself all you need to do is Classname(Handle(w_somewindow)). It's the same in 32 or 64 bit.

Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Monday, 27 March 2017 14:53 PM UTC
  2. PowerBuilder
  3. # 2

I am pretty sure that using LONGLONG for a pointer in a 32bit app is not an issue. The upper bits would always be 0 and would be truncated when passed into the Win API function.

This page is good for determining the correct PB datatype for an external function declaration:

https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx

This page explains the difference between 32bit and 64bit pointers. All pointers on 64bit Windows are 64bit, they just get truncated when passed to a 32bit function.

https://msdn.microsoft.com/en-us/library/windows/desktop/aa384264(v=vs.85).aspx

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.