Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions access-add-in/source/modules/NetComDomain.cls
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Attribute VB_Exposed = False
'<codelib>
' <file>com/NetComDomain.cls</file>
' <license>_codelib/license.bas</license>
' <ref><name>stdole</name><major>2</major><minor>0</minor><guid>{00020430-0000-0000-C000-000000000046}</guid></ref>
' <example>_examples/com/NetComDomain_Example_ShowWinForm_Minimal.bas</example>
' <description>Creates objects from a .NET COM library without registration (hosts the .NET 4 CLR, no references needed)</description>
'</codelib>
Expand Down Expand Up @@ -228,15 +227,16 @@ Private Sub ReleaseComPointer(ByRef Pointer As LongPtr)
End If
End Sub

' Wraps an IUnknown pointer into an Object variable (QueryInterface for IDispatch).
' The caller still owns its own reference.
' Wraps an IUnknown pointer into an Object variable. The caller still owns its own reference.
' Unknown must be declared As Object: As stdole.IUnknown makes the Set below call
' QueryInterface(IDispatch), which the default AppDomain rejects (error 13, type mismatch).
Private Function ObjectFromPointer(ByVal Pointer As LongPtr) As Object

Dim Unknown As stdole.IUnknown
Dim Unknown As Object
Dim NullPointer As LongPtr

CopyMemory Unknown, Pointer, PointerSize ' no AddRef
Set ObjectFromPointer = Unknown ' QueryInterface(IDispatch) incl. AddRef
Set ObjectFromPointer = Unknown ' AddRef
CopyMemory Unknown, NullPointer, PointerSize ' no Release when Unknown goes out of scope

End Function
Expand Down