Address of Integer IntPtr? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
iseahound
Posts: 1444
Joined: 13 Aug 2016, 21:04
Contact:

Address of Integer IntPtr?

27 Sep 2021, 07:37

There’s no way to get the address of an integer after a128 correct?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Address of Integer IntPtr?

27 Sep 2021, 08:22

well, there's no no way of finding the address of an integer. uve got NumGet, u can read ur own memory. if u know what and where to look for, ud be able to conjure up an address(and if ure lucky, avoid corrupting ur script in the process of doing so)
what there isnt, is a practical way to do it. what u need this for? whats the use-case?
iseahound
Posts: 1444
Joined: 13 Aug 2016, 21:04
Contact:

Re: Address of Integer IntPtr?

28 Sep 2021, 20:27

I think if NumPut allowed me to input a pointer type i.e. int64* it would save me from having to allocate tiny structs. But you're right I'll just create the extra buffer. Thanks.

edit: It looks like numput just ignores the star.

Code: Select all

v := Buffer(8, 0), NumPut("uint*", 7, v)
MsgBox NumGet(v, "ptr")
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Address of Integer IntPtr?

28 Sep 2021, 20:41

iirc it checks just the first couple of chars to determine the type, so what follows may be irrelevant

what is a tiny struct? up to 8 bytes, u can use regular ahk variables, no need for buffer
iseahound
Posts: 1444
Joined: 13 Aug 2016, 21:04
Contact:

Re: Address of Integer IntPtr?

29 Sep 2021, 15:10

https://github.com/iseahound/ImagePut/blob/75e7f9b67b95c8b8d2a34448e1bb1c4506b45908/ImagePut.ahk#L1701

I rewrote the saveimagetofile gdi+ function. The way tic wrote it was hacky. The structures are in the comments if you are curious.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Address of Integer IntPtr?  Topic is solved

02 Oct 2021, 10:52

hmm, crappy api but it has to be that way
https://docs.microsoft.com/en-us/windows/win32/gdiplus/-gdiplus-determining-the-parameters-supported-by-an-encoder-use
https://docs.microsoft.com/en-us/windows/win32/gdiplus/-gdiplus-using-the-encodervalue-enumeration-use
https://docs.microsoft.com/en-us/windows/win32/gdiplus/-gdiplus-listing-parameters-and-values-for-all-encoders-use

there is a way to get a var's int ptr but it requires a VarRef:

Code: Select all

#Requires AutoHotkey v2.0-beta.1
Int64DoubleObjPtrFromVarRef(ref) {
    if !(ref is VarRef)
        throw TypeError('Expected VarRef, got ' Type(ref) '.', -1, 'ref')

    static offsetof_mContentsUnion := A_PtrSize + ; vtbl
                                              4 + ; mRefCount
                                              4   ; mFlags

    return ObjPtr(ref) + offsetof_mContentsUnion
}
ud then use it like so:

Code: Select all

; Select the proper codec based on the extension of the file.
quality := 33
this.select_codec(pBitmap, extension, &quality, &pCodec, &ep, &ci)
...
static select_codec(pBitmap, extension, quality_VarRef, &pCodec, &ep, &ci) {
    ...
      ep := Buffer(24+2*A_PtrSize)                  ; sizeof(EncoderParameter) = ptr + n*(28, 32)
         NumPut(  "uptr",     1, ep,            0)  ; Count
         DllCall("ole32\CLSIDFromString", "wstr", "{1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB}", "ptr", ep.ptr+A_PtrSize)
         NumPut(  "uint",     1, ep, 16+A_PtrSize)  ; Number of Values
         NumPut(  "uint",     4, ep, 20+A_PtrSize)  ; Type
         NumPut(   "ptr", Int64DoubleObjPtrFromVarRef(quality_VarRef), ep, 24+A_PtrSize)  ; Value
   }
}
but its probably pointless to write it like so
Last edited by swagfag on 08 Oct 2021, 02:27, edited 1 time in total.
iseahound
Posts: 1444
Joined: 13 Aug 2016, 21:04
Contact:

Re: Address of Integer IntPtr?

02 Oct 2021, 20:42

Yes but your post is very interesting. Thanks!

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: No registered users and 51 guests