'
' ---------------------------------------------------------------------------
' Jacques Philippe                                                 April 2002
'
' Demo Calling A Asm Routine in RapidQ                    Without Any Include
' ---------------------------------------------------------------------------
'
' This Demo Simply REverse a String Calling an Asm Routine
'
$ESCAPECHARS ON
$TYPECHECK ON
$INCLUDE "RAPIDQ.INC"
'
' Begin of File ReverseString.Inc   cut and pasted
'
DECLARE FUNCTION CallAsmProc LIB "user32" ALIAS "CallWindowProcA" _
            (Proc AS LONG, A1 AS LONG, A2 AS LONG, A3 AS LONG, _
            A4 AS LONG) AS LONG
'
' ============================================================
' ----- START ASM ReverseString -----
DefByte ReverseStringArray (0 To 60) = _
   { _
    &HC8, &H00, &H00, &H00, &H51, &H56, &H57, &H8B, &H7D, &H0C,  _
    &H8B, &H75, &H08, &HB8, &H00, &H00, &H00, &H00, &HB9, &H00,  _
    &H01, &H00, &H00, &HFC, &HA4, &H40, &H80, &H3E, &H00, &H0F,  _
    &H84, &H02, &H00, &H00, &H00, &HE0, &HF2, &H8B, &H75, &H0C,  _
    &H01, &HC6, &H4E, &H8B, &H7D, &H08, &H89, &HC1, &HFC, &HA4,  _
    &H4E, &H4E, &HE0, &HFA, &H5F, &H5E, &H59, &HC9, &HC2, &H10,  _
    &H00 _
   }
' ----- END ASM ReverseString -----
'
' ----- POINTER to use In CallAsmProc -----
'       A Bit Faster than Calling ReverseString
DefInt ptrReverseString
ptrReverseString = VarPtr (ReverseStringArray(0))
'
' ----- RQ CALL ReverseString -----
Function ReverseString (Arg1 As Long, Arg2 As Long, Arg3 As Long, _
                                            Arg4 As Long) as Long
    Result = CallAsmProc (ptrReverseString, Arg1, Arg2, Arg3, Arg4)
End Function
'
' ============================================================
' End of File ReverseString.Inc   cut and pasted
'
'
DefInt iTmp
DefStr myString = "What Time is it ?"
DefStr buffer = Space$(Len(MyString) + 5)  ' The asm routine will work there 
'
' Calling the Function ReverseString
' ----------------------------------
Print "\nI Call the Function ReverseString"
Print "    Result : ";myString;"  ASM REVERSED BECOMES  ";
ReverseString (VarPtr(myString), VarPtr(buffer), 0, 0)
Print myString
'
' Directly Calling API CallAsmProc with the Pointer ptrReverseString
' ------------------------------------------------------------------
Print "\nI Directly Call API CallAsmProc with the Pointer ptrReverseString"
Print "    Result : ";myString;"  ASM REVERSED BECOMES  ";
CallAsmProc (ptrReverseString, VarPtr(myString), VarPtr(buffer), 0, 0)
Print myString
Print "\n   *** It was Reversed, it is now Re Reversed :)"
'
' -------------------------------------------------------------
' EXIT CONSOLE
' ------------
DefStr sExit
Input "\n\n                    CR to QUIT \n\n", sExit
Application.Terminate
End

