1. Larry Peters
  2. PowerBuilder
  3. Monday, 26 July 2021 07:08 AM UTC

I wish to use the BringWindowToTop Windows API in a 64bit environment.

I have declared as follows:

FUNCTION boolean BringWindowToTop(longptr w_handle) LIBRARY "User32.dll"  Alias For "BringWindowToTop"

This works in the PowerBuilder 32bit IDE but does not work when built in 64bit.

What am I doing wrong?

I have a similar issue with:

FUNCTION ulong ShowWindow (longptr hwnd, ulong nCmdShow) LIBRARY "user32" Alias For "ShowWindow"

TIA

Accepted Answer
John Fauss Accepted Answer Pending Moderation
  1. Monday, 26 July 2021 13:43 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi, Larry -

The external function declaration for BringWindowToTop you provided looks correct. However, some questions:

1. Have you checked the Boolean return code?

2. If boolean False is being returned, have you called the GetLastError API function for more information as to why it failed, as suggested in the Windows API documentation?

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-bringwindowtotop

3. What datatype and value are you supplying in your code when calling this API function? Can you please provide a code snippet? Specifically, what PowerScript datatype are you using for the argument value and how are you setting its value before calling the API function?

4. You state "...does not work when built in 64-bit". What does "not work" mean, in your case? Can you please elaborate?

FYI - It doesn't adversely affect things, but there is no reason to include the ALIAS FOR clause in the external function declaration if the name you assign to the API function exactly matches the API function's name. Therefore, you may omit it in your example.

As for the ShowWindow API function, can you please provide the external function declaration you are using along with a code snippet that calls it?

Regards, John

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Tuesday, 27 July 2021 00:21 AM UTC
  2. PowerBuilder
  3. # 1

Hi Larry;

  Your external function looks wrong to me. That looks like the old 16/32 bit declaration.

   My framework uses this for the 32/64 bit App world ...

FUNCTION  Boolean   BringWindowToTop (long ll_hwnd ) LIBRARY "user32.dll"

HTH

Regards ... Chris

Comment
  1. Larry Peters
  2. Tuesday, 27 July 2021 04:26 AM UTC
Thanks Chris.

Tried that. (FUNCTION Boolean BringWindowToTop (long ll_hwnd ) LIBRARY "user32.dll")

No result.

Best Regards

Larry
  1. Helpful
There are no comments made yet.
Larry Peters Accepted Answer Pending Moderation
  1. Monday, 26 July 2021 20:00 PM UTC
  2. PowerBuilder
  3. # 2

Hi John, Thanks for the assist.

1. Yes. I have tested the return code. In a typical 32bit (PB IDE) test BringWindowToTop returned True but 64bit returned False. Similarly ShowWindow returned 24 in 32bit but 0 in 64bit.

2. I have NOT tested GetLastError. I will do so.

3. Good question. The value I am passing to BringWindowToTop is LongPtr. However, it gets its value from a string and since there is no Casting function LongPtr() I am using Long(). See code:

// double-click event in tv

longptr        li_hand
ulong        ll_ret
boolean        lb_ret

li_hand = LONG(as_handle)
lb_ret = BringWindowToTop(li_hand)
ll_ret = ShowWindow(li_hand, 5)


// as_handle is a string containing the stringified value
// of a window.
// This was determined by the following code:
//
// longptr    li_hand
//
// li_hand = handle(lw_sheet)    // lw_sheet is a sheet window
// is_handle = string(li_hand)    // is_handle is later used in above function

4. Does not work means the following:

In the 32-bit environment, when a treeviewitem is double-clicked, the window it is referencing (via is_handle) comes to the top and is visible. In the 64-bit environment, nothing happens after the double-click (because the BringWindowToTop call failed).

Best Regards

Larry

Comment
  1. Miguel Leeuwe
  2. Tuesday, 27 July 2021 15:04 PM UTC
Great stuff!
  1. Helpful
  1. Olan Knight
  2. Tuesday, 27 July 2021 17:14 PM UTC
Somewhere in the migration documentation it states that POINTERS are handled in PowerBuilder as LONGLONG variables.

  1. Helpful
  1. John Fauss
  2. Tuesday, 27 July 2021 17:56 PM UTC
The PB Longptr datatype is a chameleon; it's a 32-bit (long) integer when compiled for a 32-bit application and it's a 64-bit (longlong) integer when compiled for a 64-bit application. This makes it ideally suited for Windows handles.



As an aside, the Windows API also defines a "long pointer" datatype, named LONG_PTR, that is intended for use to perform pointer arithmetic. It (like many datatypes in the Windows API) is also a type definition. It's defined as the following:



#if defined(_WIN64)

typedef __int64 LONG_PTR;

#else

typedef long LONG_PTR;

#endif
  1. Helpful
There are no comments made yet.
Armeen Mazda @Appeon Accepted Answer Pending Moderation
  1. Monday, 26 July 2021 18:46 PM UTC
  2. PowerBuilder
  3. # 3

Hi Larry, I'm not sure if this is the root issue, but one obvious thing I can think of is maybe you are calling the 32-bit DLL from your 64-bit app... the bitness needs to match.  For 64-bit app you need to be specifying the user32.dll located at %windir%\System32\.  The user32.dll located at %windir%\SysWOW64\ is 32-bit.

Comment
  1. Armeen Mazda @Appeon
  2. Monday, 26 July 2021 20:18 PM UTC
You wrote: FUNCTION boolean BringWindowToTop(longptr w_handle) LIBRARY "User32.dll" Alias For "BringWindowToTop"

User32.dll you are referencing is same filename for both 32-bit and 64-bit versions but just different locations. So if for some reason your compiled app is using the User32.dll in the wrong location then you will have mismatch of bitness.
  1. Helpful
  1. John Fauss
  2. Monday, 26 July 2021 21:33 PM UTC
The 32-bit emulator built into Windows automatically redirects calls to the appropriate system folder.

As for the system folder naming incongruities between 64-bit and 32-bit, here's a link to an explanation that helps make some sense of it:

https://www.geeksforgeeks.org/system32-folder-64-bit-operating-system/

  1. Helpful
  1. Armeen Mazda @Appeon
  2. Monday, 26 July 2021 22:11 PM UTC
Thanks John!
  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.