1. Steen Jakobsen
  2. PowerBuilder
  3. Tuesday, 26 July 2022 06:24 AM UTC

Hi,

 

In my x64 refactoring of a ton of code I need to convert a String to LongPTR. How can I do that?

I have a handle to a window is stored as string and ny SDK function involving a handle musrt be of tupe LongPTR

Using PB2019R3

 

Thanks 

 

//Steen

Accepted Answer
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Tuesday, 26 July 2022 12:24 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi,

Maybe there's something I'm not aware of but wouldn't it just be a matter of:

 

longptr lptr_mylptr

string ls_mystring = "ABC"

 

lptr_myLptr = Long(ls_myString)

or 

lptr_myLptr = LongLong(ls_myString)

?

regards,

MiguelL

Comment
  1. Miguel Leeuwe
  2. Tuesday, 26 July 2022 12:32 PM UTC
okay, after John's reply I guess I'm "getting it" now. You need to pass a longptr STRING not numeric :)
  1. Helpful
  1. Steen Jakobsen
  2. Friday, 29 July 2022 07:05 AM UTC
Hi Miguel,



Actually I need to pass in a numeric value. So your feeback solved my question. I need to use the LonLong() function.

I was unaware of that function.



Thanks so much

//Steen



ps. Migrating to PB2022 in x64 is NOT a walk in the park. Have to refactor all external calls and all variables that hold pointers and handles.

However it is worth it! :-)
  1. Helpful 1
  1. Miguel Leeuwe
  2. Friday, 29 July 2022 10:56 AM UTC
Glad to hear that!.

Please mark as answered / resolved.

regards
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Tuesday, 26 July 2022 12:30 PM UTC
  2. PowerBuilder
  3. # 1

Hi, Steen - 

Since a PB String is simply a zero-terminated array of (Unicode) characters, any time you declare a string argument in an external function declaration PB will pass (the array) as a pointer... the memory address of the first character in the string. In a 32-bit process, this pointer will be 32-bit and in a 64-bit process, it will be a 64-bit memory address. You need not do anything other than declare the argument as a String.

If you include the REF keyword, the exact same thing happens, except that PB also allows the called external function to make changes to the PB string (character array).

Hope this helps.

Best regards, John

Comment
  1. Steen Jakobsen
  2. Friday, 29 July 2022 07:06 AM UTC
My need was to pass in a numeric value so I use the LongLong() function as suggested by Miguel.

But John, Thanks for your help and insight.



//Steen
  1. Helpful
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.