Inline Asm w VB6Author: Dave Date: 02.04.10 - 6:07am Just a quick post for documentation sake of using inline asm with VB6 (or at least as close as we can get to it without an external c dll. In terms of development of the asm to put in. You can use your C Compiler to generate it for you..here are the tips.
Full example here: http://sandsprite.com/CodeStuff/vb_cdecl.zip Note: All single quotes for comments are stripped by my blog script same as default CallWindowProc except param 1 is now "ByRef lpBytes As Any" or you can use the default like this: CallWindowProc( Varptr( asmBytes(0) ) , Private Declare Function CallAsm Lib "user32" Alias "CallWindowProcA" _ (ByRef lpBytes As Any, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Function Shl(x As Long) As Long 8B45 0C MOV EAX,DWORD PTR SS:[EBP+12] D1E0 SHL EAX,1 C2 10 00 RETN 10h Dim o() As Byte Const sl As String = "8B 45 0C D1 E0 C2 10 00" o() = toBytes(sl) Shl = CallAsm(o(0), x, 0, 0, 0) End Function Function Shr(x As Long) As Long 8B45 0C MOV EAX,DWORD PTR SS:[EBP+12] D1E8 SHR EAX,1 C2 10 00 RETN 10h Dim o() As Byte Const sr As String = "8B 45 0C D1 E8 C2 10 00" o() = toBytes(sr) Shr = CallAsm(o(0), x, 0, 0, 0) End Function Private Function ShlX(x As Long, shift As Byte) As Long 8B45 0C MOV EAX,DWORD PTR SS:[EBP+12] C1E0 12 SHL EAX,12 C2 10 00 RETN 10h Dim o() As Byte Const sl As String = "8B 45 0C C1 E0 __ C2 10 00" o() = toBytes(Replace(sl, "__", Hex(shift))) Shl = CallAsm(o(0), x, 0, 0, 0) End Function Private Function ShrX(x As Long, shift As Byte) As Long 8B45 0C MOV EAX,DWORD PTR SS:[EBP+12] C1E8 12 SHR EAX,12 C2 10 00 RETN 10h Dim o() As Byte Const sr As String = "8B 45 0C C1 E8 __ C2 10 00" o() = toBytes(Replace(sr, "__", Hex(shift))) ShrX = CallAsm(o(0), x, 0, 0, 0) End Function Function getESP() As Long Dim C As Currency 8 bytes, initially all 0s his isnt a naked function, so the esp is actually local to this function frame, but since we only use it for relative size differences etween before and after and there are no stack mods in vb after prolog ormally, this is fine as a standalone function 8BC4 MOV EAX,ESP C2 10 00 retn 10h CopyMemory C, &H10C2C48B, 4 getESP = CallAsm(C, 0, 0, 0, 0) End Function Function toBytes(x As String) As Byte() Dim tmp() As String Dim fx() As Byte Dim i As Long tmp = Split(x, " ") ReDim fx(UBound(tmp)) For i = 0 To UBound(tmp) fx(i) = CInt("&h" & tmp(i)) Next toBytes = fx() End Function Comments: (3)On 09.04.11 - 4:17pm gheo wrote:
On 01.31.20 - 5:12pm Dave wrote:
On 02.05.20 - 7:45am Dave wrote:
|
About Me More Blogs Main Site
|
|||||||||||||||||||||||||||||||||