Skip to content

Instantly share code, notes, and snippets.

@kumatti1
Last active November 3, 2018 09:47
Show Gist options
  • Save kumatti1/484e0ed4eb9bf0b2ec81 to your computer and use it in GitHub Desktop.
Save kumatti1/484e0ed4eb9bf0b2ec81 to your computer and use it in GitHub Desktop.
内部関数呼び出し
Option Explicit
Private Declare PtrSafe Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As LongPtr
Private Declare PtrSafe Function GetProcAddress Lib "kernel32" (ByVal hModule As LongPtr, ByVal lpProcName As String) As LongPtr
Private Declare PtrSafe _
Function DispCallFunc Lib "OleAut32.dll" ( _
ByVal pvInstance As LongPtr, _
ByVal oVft As LongPtr, _
ByVal cc_ As Long, _
ByVal vtReturn As Integer, _
ByVal cActuals As Long, _
ByRef prgvt As Integer, _
ByRef prgpvarg As LongPtr, _
ByRef pvargResult As Variant _
) As Long
Const CC_CDECL = 1
Sub hoge()
Dim proc As LongPtr
proc = GetModuleHandle("vbe7.dll")
If proc = 0 Then Exit Sub
Debug.Print Hex$(proc)
'void *__cdecl memcpy(void *Dst, const void *Src, size_t Size);
proc = proc + &H13B3
Debug.Print Hex$(proc)
Dim hr As Long
Dim ret As Variant
Dim pObj As LongPtr
pObj = ObjPtr(Application)
Dim pVtbl As LongPtr
Dim pVar(0 To 2) As LongPtr
Dim v(0 To 2) As Variant
v(0) = VarPtr(pVtbl)
v(1) = (pObj)
v(2) = 4&
pVar(0) = VarPtr(v(0))
pVar(1) = VarPtr(v(1))
pVar(2) = VarPtr(v(2))
Dim vt(0 To 2) As Integer
vt(0) = vbLong
vt(1) = vbLong
vt(2) = vbLong
hr = DispCallFunc(0, proc, CC_CDECL, vbLong, 3, vt(0), pVar(0), ret)
Debug.Print Hex$(hr), Hex$(ret)
End Sub
@RAFAAJ2000
Copy link

Hi,

Can you explain what this code does ? Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment