Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.06 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.     .Release = DllCallbackGetPtr($tStruct.hRelease)
  27.     .MyFunc = DllCallbackGetPtr($tStruct.hMyFunc)
  28. EndWith
  29.  
  30. ; ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ +
  31.  
  32. $oObj = ObjCreateInterface(DllStructGetPtr($tStruct), _WinAPI_CreateGUID(), "MyFunc none();")
  33. $oObj.MyFunc()
  34.  
  35. ; ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ +
  36.  
  37. $oObj = Null
  38. DllCallbackFree($tStruct.hRelease)
  39.  
  40. ; ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ +
  41.  
  42. Func MyFunc($this)
  43.     ConsoleWrite("Hallo aus MyFunc!" & @CRLF)
  44. EndFunc
  45.  
  46. ; ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ +
  47.  
  48. Func QueryInterface($this, $riid, $ppvObject)
  49.     $tObj = DllStructCreate("ptr p", $ppvObject)
  50.     $tObj.p = $this
  51.     AddRef($this)
  52. EndFunc
  53.  
  54.  
  55. Func AddRef($this)
  56.     $tObj = DllStructCreate($tagStruct, $this)
  57.     $tObj.RefCnt += 1
  58.     Return $tObj.RefCnt
  59. EndFunc
  60.  
  61.  
  62. Func Release($this)
  63.     $tObj = DllStructCreate($tagStruct, $this)
  64.     $tObj.RefCnt -= 1
  65.    
  66.     If $tObj.RefCnt <= 0 Then
  67.         DllCallbackFree($tObj.hQueryInterface)
  68.         DllCallbackFree($tObj.hAddRef)
  69.         DllCallbackFree($tObj.hMyFunc)
  70.     EndIf
  71.    
  72.     Return $tObj.RefCnt
  73. EndFunc
  74.  
  75. ; ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement