Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1449

VB6 InlineAssembler,asm bind to vb6 function

$
0
0
Code:

CDeclTrampolin.vbp


[InlineAssembler]
FileName=CDeclTrampolin.ia

Code:

Private Declare Function LoadLibrary Lib "kernel32" _
                        Alias "LoadLibraryW" ( _
                        ByVal lpLibFileName As Long) As Long
Private Declare Function GetProcAddress Lib "kernel32" ( _
                        ByVal hModule As Long, _
                        ByVal lpProcName As String) As Long

Sub Main()
    Dim hMSVCrt        As Long
    Dim pfn_snwprintf  As Long
    Dim pfn_ultow      As Long
    Dim pfn_wcsupr      As Long
    Dim pfn_wstrtime_s  As Long
    Dim sBuffer        As String
   
    hMSVCrt = LoadLibrary(StrPtr("msvcrt"))
   
    pfn_snwprintf = GetProcAddress(hMSVCrt, "_snwprintf")
    pfn_ultow = GetProcAddress(hMSVCrt, "_ultow")
    pfn_wcsupr = GetProcAddress(hMSVCrt, "_wcsupr")
    pfn_wstrtime_s = GetProcAddress(hMSVCrt, "_wstrtime_s")
   
    sBuffer = String$(255, vbNullChar)
   
    AsmCallCdecl4 pfn_snwprintf, StrPtr(sBuffer), Len(sBuffer), StrPtr("Test %ld"), 1234
   
    Debug.Print sBuffer
   
    AsmCallCdecl3 pfn_ultow, &H80212123, StrPtr(sBuffer), 10
   
    Debug.Print sBuffer
   
    AsmCallCdecl2 pfn_wstrtime_s, StrPtr(sBuffer), Len(sBuffer)
   
    Debug.Print sBuffer
   
    sBuffer = "HeLlO WoRlD!!!"
   
    AsmCallCdecl1 pfn_wcsupr, StrPtr(sBuffer)
   
    Debug.Print sBuffer
    MsgBox "ok"
End Sub

modAsm.bas

Code:

Public Function AsmCallCdecl1( _
                ByVal pfn As Long, _
                ByVal lArg1 As Long, _
                Optional ByVal lRetSpace As Long) As Long
End Function

Public Function AsmCallCdecl2( _
                ByVal pfn As Long, _
                ByVal lArg1 As Long, _
                ByVal lArg2 As Long, _
                Optional ByVal lRetSpace As Long) As Long
End Function

Public Function AsmCallCdecl3( _
                ByVal pfn As Long, _
                ByVal lArg1 As Long, _
                ByVal lArg2 As Long, _
                ByVal lArg3 As Long, _
                Optional ByVal lRetSpace As Long) As Long
End Function

Public Function AsmCallCdecl4( _
                ByVal pfn As Long, _
                ByVal lArg1 As Long, _
                ByVal lArg2 As Long, _
                ByVal lArg3 As Long, _
                ByVal lArg4 As Long, _
                Optional ByVal lRetSpace As Long) As Long
End Function

CDeclTrampolin.ia
Code:

 
  ASMCallCdecl1?  BITS 32

NUM_OF_ARGS equ 1

pop eax        ; get retaddr
pop ecx        ; get pfn

mov [esp + NUM_OF_ARGS * 4], eax

call ecx

add esp, NUM_OF_ARGS * 4

ret


  ASMCallCdecl2?  BITS 32

NUM_OF_ARGS equ 2

pop eax        ; get retaddr
pop ecx        ; get pfn

mov [esp + NUM_OF_ARGS * 4], eax

call ecx

add esp, NUM_OF_ARGS * 4

ret

  ASMCallCdecl4?  BITS 32

NUM_OF_ARGS equ 4

pop eax        ; get retaddr
pop ecx        ; get pfn

mov [esp + NUM_OF_ARGS * 4], eax

call ecx

add esp, NUM_OF_ARGS * 4

ret
  ASMCallCdecl3?  BITS 32

NUM_OF_ARGS equ 3

pop eax        ; get retaddr
pop ecx        ; get pfn

mov [esp + NUM_OF_ARGS * 4], eax

call ecx

add esp, NUM_OF_ARGS * 4

ret


Viewing all articles
Browse latest Browse all 1449

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>