Sign in to follow this  
Followers 0
WideBoyDixon

_WinAPI_GetObject

5 posts in this topic

Using _WinAPI_GetObject() from WinAPI.au3 always reports an error for me when I'm trying, for example, to retrieve the logical font structure for a font handle. Snippet:

Local $tFONT = DllStructCreate($tagLOGFONT)
    Local $hDC = _WinAPI_GetDC($hGUI)
    Local $hFont = _SendMessage($hGUI, $WM_GETFONT, 0)
    _WinAPI_GetObject($hFont, DllStructGetSize($tFONT), DllStructGetPtr($tFONT))
    DllStructSetData($tFONT, "FaceName", "Courier New")

This gives me a message box error on the _WinAPI_GetObject() call because the return value is non-zero. However, the return value as I understand it is the number of bytes copied in to the structure so this check is a little overzealous. Or have I missed something?

WBD

Share this post


Link to post
Share on other sites



I think _WinAPI_GetObject gives an error if the return value is 0. Try to call GetObject yourself to see if the return is not zero.

Share this post


Link to post
Share on other sites

Func _WinAPI_GetObject($hObject, $iSize, $pObject)
    Local $aResult

    $aResult = DllCall("GDI32.dll", "int", "GetObject", "int", $hObject, "int", $iSize, "ptr", $pObject)
    _WinAPI_Check("_WinAPI_GetObject", ($aResult[0] = 0), 0, True)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_GetObject

So it raises an error if $aResult[0] = 0 which is never true. When I do the DllCall myself and basically ignore the return value then everything works as I would like it to. Is this a bug in _WinAPI_GetObject()?

WBD

Share this post


Link to post
Share on other sites

Did you check if $hFont is not null? According to MSDN WM_GETFONT The return value is the handle of the font used by the control, or NULL if the control is using the system font.

Share this post


Link to post
Share on other sites

Doh! Thanks for pointing out my stupid mistake :D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0