- Bernhard Stoeter
- PowerBuilder
- Monday, 18 December 2017 12:30 PM UTC
Hey,
I'm using PowerBuilder 2017, Build 1681, OS Win8.1 and Win10.
I like to call the WinApi function MonitorFromPoint (user32.ddl)
which is defined as:
// Definition in Windows SDK, WinUser.h
WINUSERAPI HMONITOR WINAPI MonitorFromPoint(__in POINT pt,__in DWORD dwFlags);
So I declared a local external function:
function ulong MonitorFromPoint( str_point pt, ulong dwFlags ) library "user32.dll" alias for "MonitorFromPoint"
str_point is defined as:
global type str_point from structure
long cx
long cy
end type
If I use this code in the open event of a window:
constant ulong MONITOR_DEFAULTTONEAREST = 2 // 0x00000002
str_point lstr_Point
ulong lul_hMonitor
lstr_Point.cx = this.X
lstr_Point.cy = this.Y
lul_hMonitor = MonitorFromPoint( lstr_Point, MONITOR_DEFAULTTONEAREST )
the application crashed with:
PowerBuilder application execution error (R0042):
Error: Specified argument type differs from required argument type
at runtime in DDL function monitorfrompoint.
(invalid stack pointer on return from function call) at line ...
in open event of object w_...
Altering the local external function definition to:
function ulong MonitorFromPoint( long ptx, long pty, ulong dwFlags ) library "user32.dll" alias for "MonitorFromPoint"
which is technically identical (12 bytes, long, long, ulong) and adjust my code to:
lstr_Point.cx = this.X
lstr_Point.cy = this.Y
lul_hMonitor = MonitorFromPoint( lstr_Point.cx, lstr_Point.cy, MONITOR_DEFAULTTONEAREST )
everything works as expected.
What am I missing?
Kind regards
Bernhard
Find Questions by Tag
Helpful?
If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.