Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.00 KB | None | 0 0
  1. ; ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ +
  2.  
  3. #include <WinAPICom.au3>
  4.  
  5. ; ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ +
  6.  
  7. $tagStruct = "ptr VTable; int RefCnt;" & _
  8.         "handle hQueryInterface; handle hAddRef; handle hRelease;" & _
  9.         "handle hMyFunc;" & _
  10.         "ptr QueryInterface; ptr AddRef; ptr Release;" & _
  11.         "ptr MyFunc;"
  12.  
  13. $tStruct = DllStructCreate($tagStruct)
  14.  
  15. With $tStruct
  16.     .VTable = DllStructGetPtr($tStruct, "QueryInterface")
  17.     .RefCnt = 1
  18.    
  19.     .hQueryInterface = DllCallbackRegister(QueryInterface, "long", "ptr; ptr; ptr;")
  20.     .hAddRef = DllCallbackRegister(AddRef, "ulong", "ptr;")
  21.     .hRelease = DllCallbackRegister(Release, "ulong", "ptr;")
  22.     .hMyFunc = DllCallbackRegister(MyFunc, "none", "ptr;")
  23.    
  24.     .QueryInterface = DllCallbackGetPtr($tStruct.hQueryInterface)
  25.     .AddRef = DllCallbackGetPtr($tStruct.hAddRef)
  26.     .hRelease = DllCallbackGetPtr($tStruct.hRelease)
  27.     .hMyFunc = DllCallbackGetPtr($tStruct.hMyFunc)
  28. EndWith
  29.  
  30. ; ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ +
  31.  
  32. $oObj = ObjCreateInterface(DllStructGetPtr($tStruct), _WinAPI_CreateGUID(), "MyFunc none();")
  33.  
  34. ; ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ +
  35.  
  36. $oObj = Null
  37. DllCallbackFree($tStruct.hRelease)
  38.  
  39. ; ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ +
  40.  
  41. Func MyFunc($this)
  42. EndFunc
  43.  
  44. ; ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ +
  45.  
  46. Func QueryInterface($this, $riid, $ppvObject)
  47.     $tObj = DllStructCreate("ptr p", $ppvObject)
  48.     $tObj.p = $this
  49.     AddRef($this)
  50. EndFunc
  51.  
  52.  
  53. Func AddRef($this)
  54.     $tObj = DllStructCreate($tagStruct, $this)
  55.     $tObj.RefCnt += 1
  56.     Return $tObj.RefCnt
  57. EndFunc
  58.  
  59.  
  60. Func Release($this)
  61.     $tObj = DllStructCreate($tagStruct, $this)
  62.     $tObj.RefCnt -= 1
  63.    
  64.     If $tObj.RefCnt <= 0 Then
  65.         DllCallbackFree($tObj.hQueryInterface)
  66.         DllCallbackFree($tObj.hAddRef)
  67.         DllCallbackFree($tObj.hMyFunc)
  68.     EndIf
  69.    
  70.     Return $tObj.RefCnt
  71. EndFunc
  72.  
  73. ; ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement