mmikeww / AHKv2-Gdip

Gdip library compatiable with both AHK v1.1 and AHK v2
https://autohotkey.com/boards/viewtopic.php?t=6517
117 stars 60 forks source link

VarSetCapacity #32

Open ysquare opened 1 year ago

ysquare commented 1 year ago

VarSetCapacity is no longer available in ahk v2.0 release, replaced by Buffer() according to the document.

huhuime commented 1 year ago

example

Gdip_Startup()
{
    Ptr := A_PtrSize ? "UPtr" : "UInt"
    pToken := 0

    if !DllCall("GetModuleHandle", "str", "gdiplus", Ptr)
        DllCall("LoadLibrary", "str", "gdiplus")
    VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
    DllCall("gdiplus\GdiplusStartup", A_PtrSize ? "UPtr*" : "uint*", pToken, Ptr, &si, Ptr, 0)
    return pToken
}

replace

Gdip_Startup()
{
    Ptr := A_PtrSize ? "UPtr" : "UInt"
    pToken := 0

    if !DllCall("GetModuleHandle", "str", "gdiplus", Ptr)
        DllCall("LoadLibrary", "str", "gdiplus")
    ;VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
    si := Buffer(A_PtrSize = 8 ? 24 : 16, 0)
    NumPut("int", 1, si.Ptr)
    DllCall("gdiplus\GdiplusStartup", A_PtrSize ? "UPtr*" : "uint*", &pToken, Ptr, si.Ptr, Ptr, 0)
    return pToken
}
mmikeww commented 1 year ago

The problem is that this library was meant to be backwards compatible to work on both v1 and v2...