Errata for the Liberty BASIC 4 Companion A Work in Progress ----------------- The most important correction is also ubiquitous in the Companion. When the book was first written, handle values could be passed into API calls as type "long". As newer versions of Windows were released, this caused errors. Handles must now be passed as type "ulong" or in some cases as type "word." Handles can be handles of windows or controls, which are obtained with the HWND() function. Handles are also created by API calls that create controls with CreateWindowEx. The handle is the returned value. Handles are also used to communicate with Device Contexts. API Fundamentals ----------------- Translating Calls to LB Syntax ----------------- Incorrect: Declare Function Rectangle Lib "gdi32" Alias "Rectangle" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long Correct: ByVal hDC as ulong Incorrect: ByVal hDC As Long - the first parameter to pass into the call. In this case, hDC is the handle of a device context. A LONG in Visual BASIC is also a LONG in LB. Correct: ByVal hDC As Long - the first parameter to pass into the call. In this case, hDC is the handle of a device context. A LONG in Visual BASIC is also a LONG in LB, unless it is a handle, in which case it is type ulong. Incorrect: *** HDC hDC the next parameter in this call specifies that the handle of the Device Context is to be passed to the function as a handle, which is a 32-bit value. Notice that the parameters are grouped within parentheses as they are in VB syntax. In LB: hDC as long Correct: *** HDC hDC the next parameter in this call specifies that the handle of the Device Context is to be passed to the function as a handle, which is an unsigned 32-bit value. Notice that the parameters are grouped within parentheses as they are in VB syntax. In LB: hDC as ulong Incorrect: OPEN "GDI32" for dll as #gdi Calldll #gdi, "Rectangle",_ hDC as long,_ X1 as long,_ Y1 as long,_ X2 as long,_ Y2 as long,_ result as boolean close #gdi Correct: Calldll #gdi32, "Rectangle",_ hDC as ulong,_ X1 as long,_ Y1 as long,_ X2 as long,_ Y2 as long,_ result as boolean Incorrect: calldll #user32, "GetWindowTextA",_ hWnd as long,_ Txt$ as ptr,_ txtLen as long,_ r as long Correct: calldll #user32, "GetWindowTextA",_ hWnd as ulong,_ Txt$ as ptr,_ txtLen as long,_ r as long Incorrect: HDC as long,_ (ByVal hDC As long, (HDC hDC Correct: HDC as ulong,_ (ByVal hDC As long, (HDC hDC --------------------- The Windows API in Action Incorrect: In multiple locations in this chapter: h as long or handle as long Correct: h as ulong or handle as ulong Incorrect: In multiple locations in this chapter: hDC as long Correct: hDC as ulong Incorrect: hText as long,_ 'handle of texteditor Correct: hText as ulong,_ 'handle of texteditor Incorrect: hButton AS long,_ 'handle of window or control Correct: hButton AS ulong,_ 'handle of window or control Incorrect: calldll #user32, "GetDesktopWindow",hDesktop as long Correct: calldll #user32, "GetDesktopWindow",hDesktop as ulong Incorrect: calldll #user32, "GetNextWindow", handle As long,_ 'known window handle Flag as long,_ 'next or previous flag nextWinHandle as long 'returns window handle calldll #user32, "GetParent", _ hButton AS long, _ 'get parent of this window hParent AS long 'returns handle of parent window Correct: calldll #user32, "GetNextWindow", handle As ulong,_ 'known window handle Flag as long,_ 'next or previous flag nextWinHandle as ulong 'returns window handle calldll #user32, "GetParent", _ hButton AS ulong, _ 'get parent of this window hParent AS ulong 'returns handle of parent window Incorrect: calldll #user32, "GetWindowDC", h as long, hDC as long calldll #user32, "GetWindowLongA",_ h as long,_ 'handle of window that will contain controls _GWL_HINSTANCE as long,_ 'flag for word value desired=instance handle hInstance as long 'instance handle of window is returned Correct: calldll #user32, "GetWindowDC", h as ulong, hDC as ulong calldll #user32, "GetWindowLongA",_ h as ulong,_ 'handle of window that will contain controls _GWL_HINSTANCE as long,_ 'flag for word value desired=instance handle hInstance as ulong 'instance handle of window is returned Incorrect: calldll #user32, "SetParent",_ hChild as long,_ 'handle of window hParent as long,_ 'handle of window to become parent result as long Correct: calldll #user32, "SetParent",_ hChild as ulong,_ 'handle of window hParent as ulong,_ 'handle of window to become parent result as long Incorrect: mainH as long,_ 'window handle Correct: mainH as ulong,_ 'window handle Incorrect: hWndMain as ulong,_ 'window handle Correct: hWndMain as ulong,_ 'window handle