1. Bernhard Stoeter
  2. PowerBuilder
  3. Monday, 18 December 2017

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

Roland Smith Accepted Answer Pending Moderation
0
Votes
Undo

It appears that the Microsoft documentation is either wrong or misleading. There are three arguments: long x, long y, long dwflags. You don't need the POINT structure. Do a web search for VB6 examples using the function.

 

Comment
There are no comments made yet.
  1. Monday, 18 December 2017
  2. PowerBuilder
  3. # 1
  • Page :
  • 1


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