python, ctypes and GetIconInfo issue

mymyxin at gmail.com mymyxin at gmail.com
Fri May 6 10:49:28 EDT 2016


A further question if you don't mind.

In your example you used a base class
and ICONINFO well as ICONINFOEX inherit it.
As the members of ICONINFO are part of ICONINFOEX
couldn't we do something like

class ICONINFO_BASE(ctypes.Structure): 
    def __del__(self, ): 
        if self.hbmMask: 
            gdi32.DeleteObject(self.hbmMask) 
            self.hbmMask = None 
        if self.hbmColor: 
            gdi32.DeleteObject(self.hbmColor) 
            self.hbmColor = None 

class ICONINFO(ICONINFO_BASE): 
    _fields_ = (('fIcon',    wintypes.BOOL), 
                ('xHotspot', wintypes.DWORD), 
                ('yHotspot', wintypes.DWORD), 
                ('hbmMask',  wintypes.HBITMAP), 
                ('hbmColor', wintypes.HBITMAP)) 

class ICONINFOEX(ICONINFO): 
    _fields_ = (('cbSize',    wintypes.DWORD), 
                # ('fIcon',     wintypes.BOOL), 
                # ('xHotspot',  wintypes.DWORD), 
                # ('yHotspot',  wintypes.DWORD), 
                # ('hbmMask',   wintypes.HBITMAP), 
                # ('hbmColor',  wintypes.HBITMAP), 
                ('wResID',    wintypes.WORD), 
                ('szModName', wintypes.WCHAR * MAX_PATH), 
                ('szResName', wintypes.WCHAR * MAX_PATH)) 

    def __init__(self, *args, **kwds): 
        super(ICONINFOEX, self).__init__(*args, **kwds) 
        self.cbSize = ctypes.sizeof(self)

A dir on instance of that class indicates that it should be possible
as it contains all needed members and size seems to be correct as well,
but a call to GetIconInfoExW fails with:

WindowsError: [Error 87] The parameter is incorrect. 


        info = ICONINFOEX()
        info.cbSize = ctypes.sizeof(info) 
        print dir(info)
        print info.cbSize
        user32.GetIconInfoExW(hIcon, ctypes.byref(info)) 

Thank you
Hubert



More information about the Python-list mailing list