Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

About advanced DllCall and some library...


  • Please log in to reply
5 replies to this topic
Zaelia
  • Members
  • 754 posts
  • Last active: Jan 17 2015 02:38 AM
  • Joined: 31 Oct 2008
I am very curious so I ask... A sample, I saw a lot of thing like
COM_Release(ppv) {
	Return	DllCall(NumGet(NumGet(1*ppv)+8), "Uint", ppv)
}
or
DllCall(NumGet(NumGet(1*pStream)+8), "Uint", pStream) ; IStream::Release
but how that work ( I guess is not a random address...) ? how we dicovered this features? I searched a lot in msdn but I found nothing about API or function adress for object as XXX::YYY

thx to teach me :)
"You annoy me, therefore I exist."

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
Check out maul.esel's COM interface tutorial & this thread. This layout might help:
Com_Release(ptr) {

   Release := vTable(ptr, 2)

   return DllCall(Release, "Uint", ptr)

}

vTable(ptr, n) { ; see ComObjQuery documentation

   PtrSize := A_PtrSize ? A_PtrSize:4 ; AHK Basic Compatible

   return NumGet(NumGet(ptr+0), n*PtrSize)

}


Zaelia
  • Members
  • 754 posts
  • Last active: Jan 17 2015 02:38 AM
  • Joined: 31 Oct 2008
Thx a lot jethrow !
It' still black magic, I will need to read again :lol:
"You annoy me, therefore I exist."

CodeKiller
  • Members
  • 2067 posts
  • Last active: Feb 26 2016 09:30 AM
  • Joined: 10 Jul 2008
By the way, why DlLCall is used here ? It's useless and does nothing. It doesn't call any Dll function, it calls a number (NumGet return the value stored at a given address)... o_O

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009

It doesn't call any Dll function, it calls a number (NumGet return the value stored at a given address)

It calls a function that is in the Com Objects Virtual Table (hence vTable). The value returned by NumGet is a pointer to this function/method - in this case the 3rd function, which is Release.

Zaelia
  • Members
  • 754 posts
  • Last active: Jan 17 2015 02:38 AM
  • Joined: 31 Oct 2008
@CodeKiller:
DllCall may also consist solely of an an integer, which is interpreted as the address of the function to call. Sources of such addresses include COM and RegisterCallback()... or with a common example, by loading it beforehand
; In the following example, if the DLL isn't yet loaded, use LoadLibrary in place of GetModuleHandle.
MulDivProc := DllCall("GetProcAddress", Ptr, DllCall("GetModuleHandle", Str, "kernel32"), AStr, "MulDiv")
Loop 500
    DllCall(MulDivProc, Int, 3, Int, 4, Int, 3) ; we don't call a name with a string but a value that points an address
; My noob spirit compare this to &MyVar or UInt*, by contrast MyVar+0 or 1*MyVar or other math calcul force the number in MyVar to be used instead of the address of MyVar itself.

"You annoy me, therefore I exist."