Page 1 of 1

Address of Integer IntPtr?

Posted: 27 Sep 2021, 07:37
by iseahound
There’s no way to get the address of an integer after a128 correct?

Re: Address of Integer IntPtr?

Posted: 27 Sep 2021, 08:22
by swagfag
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?

Re: Address of Integer IntPtr?

Posted: 28 Sep 2021, 20:27
by iseahound
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")

Re: Address of Integer IntPtr?

Posted: 28 Sep 2021, 20:41
by swagfag
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

Re: Address of Integer IntPtr?

Posted: 29 Sep 2021, 15:10
by iseahound
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.

Re: Address of Integer IntPtr?  Topic is solved

Posted: 02 Oct 2021, 10:52
by swagfag
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

Re: Address of Integer IntPtr?

Posted: 02 Oct 2021, 20:42
by iseahound
Yes but your post is very interesting. Thanks!