Last active
August 29, 2015 14:21
-
-
Save kumatti1/d8b8a53960fb485f555e to your computer and use it in GitHub Desktop.
&演算子を直で呼び出す
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Option Explicit | |
| Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal length As LongPtr) | |
| 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_STDCALL = 4 | |
| Private Declare PtrSafe Function lstrlen Lib "kernel32" Alias "lstrlenW" (ByVal lpString As LongPtr) As Long | |
| Sub hoge() | |
| Dim proc As LongPtr | |
| proc = GetModuleHandle("vbe7.dll") | |
| If proc = 0 Then Exit Sub | |
| Debug.Print Hex$(proc) | |
| proc = proc + &HC0A47 | |
| Debug.Print Hex$(proc) | |
| Dim hr As Long | |
| Dim ret As Variant | |
| Const s1 = "あいうえお" | |
| Const s2 = "かきくけこ" | |
| Dim pVar(0 To 1) As LongPtr | |
| Dim v(0 To 1) As Variant | |
| v(0) = s2 | |
| v(1) = s1 | |
| pVar(0) = VarPtr(v(0)) | |
| pVar(1) = VarPtr(v(1)) | |
| Dim vt(0 To 1) As Integer | |
| vt(0) = vbLong | |
| vt(1) = vbLong | |
| hr = DispCallFunc(0, proc, CC_STDCALL, vbLong, 2, vt(0), pVar(0), ret) | |
| Debug.Print Hex$(hr), Hex$(ret) | |
| If ret Then | |
| Dim length As Long | |
| Dim s As String | |
| length = lstrlen(ret) | |
| Debug.Print length, "文字数" | |
| s = String$(length, 0) | |
| CopyMemory ByVal StrPtr(s), ByVal CLng(ret), length * 2 | |
| Debug.Print s | |
| End If | |
| End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment