Memory error with this code

Ask for help, how to use AHK_H, etc.
think
Posts: 138
Joined: 09 Feb 2014, 05:20

Memory error with this code

15 Aug 2019, 04:13

I get a memory error if running this code with AHK_H. Any idea?
Display a list of fonts on the system: https://www.autohotkey.com/boards/viewtopic.php?t=14838

Code: Select all

#NoEnv
#Warn

Gui Add, ListView, x8 y8 w273 h362, Font name
LV_ModifyCol(1, 250)

Global FontList := []

EnumFonts() {
    hDC := DllCall("GetDC", "UInt", DllCall("GetDesktopWindow"))
    Callback := RegisterCallback("EnumFontsCallback", "F")
    DllCall("EnumFontFamilies", "UInt", hDC, "UInt", 0, "Ptr", Callback, "UInt", lParam := 0)
    DllCall("ReleaseDC", "UInt", hDC)
}

EnumFontsCallback(lpelf) {
    FontList.Push(StrGet(lpelf + 28, 32))
    Return True
}

EnumFonts()

Loop % FontList.MaxIndex() {
	LV_Add("", FontList[A_Index])
}

Gui Show, w290 h379, Fonts
Return

GuiEscape:
GuiClose:
    ExitApp
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Memory error with this code

16 Aug 2019, 14:23

As far as I understand you need to use all parameters for callback:

Code: Select all

#Warn

Gui Add, ListView, x8 y8 w273 h362, Font name
LV_ModifyCol(1, 250)

Global FontList := []

EnumFonts() {
    hDC := DllCall("GetDC", "UInt", DllCall("GetDesktopWindow"))
    Callback := RegisterCallback("EnumFontsCallback", "F")
    DllCall("EnumFontFamilies", "UInt", hDC, "UInt", 0, "Ptr", Callback, "UInt", lParam := 0)
    DllCall("ReleaseDC", "UInt", hDC)
}

EnumFontsCallback(lpelf, lpntm, FontType, lParam) {
    FontList.Push(StrGet(lpelf + 28,32))
    Return True
}

EnumFonts()

Loop % FontList.MaxIndex() {
	LV_Add("", FontList[A_Index])
}

Gui Show, w290 h379, Fonts
Return

GuiEscape:
GuiClose:
    ExitApp

Return to “Ask for Help”

Who is online

Users browsing this forum: No registered users and 21 guests