Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ +
- #include <WinAPICom.au3>
- ; ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ +
- $tagStruct = "ptr VTable; int RefCnt;" & _
- "handle hQueryInterface; handle hAddRef; handle hRelease;" & _
- "handle hMyFunc;" & _
- "ptr QueryInterface; ptr AddRef; ptr Release;" & _
- "ptr MyFunc;"
- $tStruct = DllStructCreate($tagStruct)
- With $tStruct
- .VTable = DllStructGetPtr($tStruct, "QueryInterface")
- .RefCnt = 1
- .hQueryInterface = DllCallbackRegister(QueryInterface, "long", "ptr;ptr;ptr;")
- .hAddRef = DllCallbackRegister(AddRef, "ulong", "ptr;")
- .hRelease = DllCallbackRegister(Release, "ulong", "ptr;")
- .hMyFunc = DllCallbackRegister(MyFunc, "none", "ptr;")
- .QueryInterface = DllCallbackGetPtr($tStruct.hQueryInterface)
- .AddRef = DllCallbackGetPtr($tStruct.hAddRef)
- .Release = DllCallbackGetPtr($tStruct.hRelease)
- .MyFunc = DllCallbackGetPtr($tStruct.hMyFunc)
- EndWith
- ; ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ +
- $oObj = ObjCreateInterface(DllStructGetPtr($tStruct), _WinAPI_CreateGUID(), "MyFunc none();")
- $oObj.MyFunc()
- ; ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ +
- $oObj = Null
- DllCallbackFree($tStruct.hRelease)
- ; ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ +
- Func MyFunc($this)
- ConsoleWrite("Hallo aus MyFunc!" & @CRLF)
- EndFunc
- ; ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ +
- Func QueryInterface($this, $riid, $ppvObject)
- $tObj = DllStructCreate("ptr p", $ppvObject)
- $tObj.p = $this
- AddRef($this)
- EndFunc
- Func AddRef($this)
- $tObj = DllStructCreate($tagStruct, $this)
- $tObj.RefCnt += 1
- Return $tObj.RefCnt
- EndFunc
- Func Release($this)
- $tObj = DllStructCreate($tagStruct, $this)
- $tObj.RefCnt -= 1
- If $tObj.RefCnt <= 0 Then
- DllCallbackFree($tObj.hQueryInterface)
- DllCallbackFree($tObj.hAddRef)
- DllCallbackFree($tObj.hMyFunc)
- EndIf
- Return $tObj.RefCnt
- EndFunc
- ; ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement