Navigation: thinBasic language > Script structure > Functions/Subs > CALL DWORD |
|
Description
Implements a run-time dynamic code execution.
Syntax
CALL DWORD dwPointer [TO LongVariable]
Returns
Parameters
Name |
Type |
Optional |
Meaning |
LongVariable |
Variable |
Yes |
A LONG or DWORD variable used to get back a value from the called dynamic code |
Remarks
Restrictions
See also
Examples
'---------------------------------------------------------------------------
' Dynamic assembler using thinBasic CALL DWORD ... [TO ...] statement
'---------------------------------------------------------------------------
'---Reference:
'---http://developer.intel.com/design/pentiumii/manuals/243191.htm
'---------------------------------------------------------------------------
Declare Function LoadLibrary Lib "KERNEL32.DLL" _
Alias "LoadLibraryA" _
(lpLibFileName As ASCIIZ) As Long
Declare Function GetProcAddress Lib "KERNEL32.DLL" _
Alias "GetProcAddress" _
(ByVal hModule As DWORD, lpProcName As ASCIIZ) As Long
Dim hLib , _ '---Used to store external Lib handle
hFun , _ '---Used to store a pointer to function
psASM As Long '---Used for passing a pointer to dynamic assembly
Dim sASM , _ '---Dynamic assembly string
sMessage , _ '---MessageBox message
sTitle As String '---MessageBox title
Dim RetVal As Long
'---Load library and get handle
hLib = LoadLibrary("User32.dll")
'---If handle was ok
If hLib Then
'---Get function pointer
hFun = GetProcAddress(hLib, "MessageBoxA")
If hFun Then
sTitle = "Dynamic Assembly Demo"
sMessage = "Hello World!"
'----------------------------------------------
' Compose ASSEMBLE MACHINE CODE STRING
'----------------------------------------------
sASM = _
CHR$(&h68) + MKL$(0) + _ ' 01 push 0 for style
CHR$(&h68) + MKL$(STRPTR(sTitle)) + _ ' 06 push title address
CHR$(&h68) + MKL$(STRPTR(sMessage)) + _ ' 11 push message address
CHR$(&h68) + MKL$(0) + _ ' 16 push 0 for hWnd handle
CHR$(&hFF) + CHR$(&h15) + MKL$(VARPTR(hFun)) + _ ' 21 call messagebox
CHR$(&HC3) ' 27 return
'----------------------------------------------
'---Get the address of the ASM string
psASM = STRPTR(sASM) ' address of code
'---Fire the direct call using dynamic asm
Call DWORD psASM To RetVal ' make the call and get the return value
'---Show return value
MSGBOX 0, RetVal
End If
End If
© 2004-2008 thinBasic. All rights reserved. | Version 1.7.0.0 | Web Site: http://www.thinbasic.com |