Skip to content

Instantly share code, notes, and snippets.

@kumatti1
Created December 26, 2015 22:13
Show Gist options
  • Save kumatti1/cca4ced676376d06a25e to your computer and use it in GitHub Desktop.
Save kumatti1/cca4ced676376d06a25e to your computer and use it in GitHub Desktop.
弱参照用API
Option Explicit
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Private Declare PtrSafe _
Sub SHWeakReleaseInterface Lib "shlwapi.dll" Alias "#268" ( _
ByVal arg1 As Any, _
arg2 As Any _
)
Private Declare PtrSafe _
Function SHWeakQueryInterface Lib "shlwapi.dll" Alias "#267" ( _
ByVal arg1 As Any, _
ByVal arg2 As Any, _
arg3 As GUID, _
arg4 As Any _
) As Long
Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As LongPtr)
Sub hoge()
Dim obj As Object
Dim tmp As Object
Dim ptr As Long
Set obj = Application
ptr = ObjPtr(obj)
CopyMemory tmp, ptr, 4
Debug.Print tmp Is Nothing
'CopyMemory tmp, Nothing, 4
Call SHWeakReleaseInterface(tmp, tmp)
Debug.Print tmp Is Nothing
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment