Skip to content

Instantly share code, notes, and snippets.

@kumatti1
Created February 24, 2017 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kumatti1/7c400ee7d3cab3f523e66725e3e38465 to your computer and use it in GitHub Desktop.
Save kumatti1/7c400ee7d3cab3f523e66725e3e38465 to your computer and use it in GitHub Desktop.
IPrint
Option Explicit
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
'https://msdn.microsoft.com/en-us/library/52e6es3z.aspx
Private Declare PtrSafe _
Function AtlComQIPtrAssign Lib "atl110.dll" ( _
ByRef pp As IUnknown, _
ByVal lp As IUnknown, _
ByRef riid As GUID _
) As IUnknown
Private Declare PtrSafe _
Function IIDFromString Lib "ole32.dll" ( _
ByVal lpsz As LongPtr, _
ByRef lpiid As GUID _
) As Long
Const IID_IPrint = "{b722bcc9-4e68-101b-a2bc-00aa00404770}"
'https://msdn.microsoft.com/en-us/library/windows/desktop/ms693796%28v=vs.85%29.aspx
Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As LongPtr)
Sub hoge()
Dim hr As Long
Dim iid As GUID
hr = IIDFromString(StrPtr(IID_IPrint), iid)
Dim unk As IUnknown
Dim o As Workbook
Set o = Excel.Application.Workbooks(1)
AtlComQIPtrAssign unk, o, iid
Debug.Print unk Is Nothing
CopyMemory unk, Nothing, 4
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment