Tuesday, October 21, 2008

Rather cool debugging tip…

From a Sybase newsgroup thread where the OP asked how you could determine if you were running the application with the PB debugger. "Jari" responded with:




/*
of_ispbdebug

Find out if the application is being run in PowerBuilder debugger. We
look for a PowerBuilder MDI frame.
If found, look for MDIClient. If found, look for window with title
beginning with "Debugger" If found -> Debug!

26.5.2008 JKI

*/

long ll_Desktop,ll_Child, ll_child2, ll_child3

string ls_ClassName, ls_WindowName

Constant long GW_HWNDFIRST = 0
Constant long GW_HWNDLAST = 1
Constant long GW_HWNDNEXT = 2
Constant long GW_HWNDPREV = 3
Constant long GW_OWNER = 4
Constant long GW_CHILD = 5
Constant long GW_MAX = 5

Constant long MAX_WIDTH = 255

ll_Desktop = GetDesktopWindow()

ll_Child = GetWindow( ll_Desktop, GW_CHILD )

DO WHILE (ll_Child > 0)
ls_ClassName = Space(MAX_WIDTH)
GetClassNameA( ll_Child, ls_ClassName, MAX_WIDTH )

// PowerBuilder Main window. The whole name would be for PB11
"PBFRAME110".
IF Left(ls_classname, 7) = "PBFRAME" THEN
// PowerBuilder Main window found. Now look for MDI client
ll_Child2 = GetWindow( ll_Child, GW_CHILD )
DO WHILE (ll_Child2 > 0)
ls_ClassName = Space(MAX_WIDTH)
GetClassNameA( ll_Child2, ls_ClassName, MAX_WIDTH )
IF ls_classname = "MDIClient" THEN
// We get closer, the MDI Client was found. Now look for the
debugger sheet; use the Window title, not the class
ll_Child3 = GetWindow( ll_Child2, GW_CHILD )
DO WHILE (ll_Child3 > 0)
ls_WindowName = Space(MAX_WIDTH)
GetWindowTextA( ll_Child3, ls_WindowName, MAX_WIDTH )
IF Left ( ls_WindowName, 8 ) = "Debugger" THEN
RETURN true
END IF
ll_Child3 = GetWindow( ll_Child3, GW_HWNDNEXT )
LOOP
END IF
ll_Child2 = GetWindow( ll_Child2, GW_HWNDNEXT )
LOOP
END IF
ll_Child = GetWindow( ll_Child, GW_HWNDNEXT )
LOOP

RETURN false


The local external function definitions:

FUNCTION LONG GetDesktopWindow() LIBRARY "user32" alias for
"GetDesktopWindow;Ansi"
FUNCTION LONG GetWindow( long hWnd, long uCmd ) LIBRARY "user32" alias
for "GetWindow;Ansi"
FUNCTION LONG GetClassNameA ( long hWnd, Ref String lpClassName, long
nMaxCount ) LIBRARY "user32" alias for "GetClassNameA;Ansi"
FUNCTION LONG GetWindowTextA ( long hWnd, Ref String lpString, long
nMaxCount ) LIBRARY "user32" alias for "GetWindowTextA;Ansi"


The instance variables:

// Values for the environment checking
CONSTANT String IS_ENV_EXE = "EXE"
CONSTANT String IS_ENV_PB = "PB"
CONSTANT String IS_ENV_DEBUG = "DEBUG"

2 comments:

TeamSybase Blogs » Blog Archive » Another cool debugging tip… said...

[...] TeamSybase Blogs Blogs from TeamSybase members « Rather cool debugging tip… [...]

Jari Kirvesoja said...

Hey, that's cool, seeing one's own posting in TeamSybase Blog! :-)