BASIC Developer & Support Resources > Scripting Languages

API Scripting Helper Library

(1/1)

JRS:
I started building an INCLUDE file of API/Library helper functions to help make scripting of API services easier. This will be an on going project as I expand on the GTK-Server definitions and test their use.


--- Code: Text ---' ScriptBasic API helper functions and declarations ' INTERFACEDECLARE SUB DLL ALIAS "_gtk" LIB "gtk-server"DECLARE SUB VARPTR ALIAS "varptr" LIB "gtk-server" ' Convert standard function calls to a space delimited command stringFUNCTION _DLL(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9)LOCAL arg_str   arg_str = STR(a0) & " " & STR(a1) & " " & STR(a2) & " " & STR(a3) & " " & STR(a4) & " " & STR(a5) & " " & STR(a6) & " " & STR(a7) & " " & STR(a8) & " " & STR(a9)  _DLL = DLL(arg_str)END FUNCTION ' Returns a data pointer address of a variable or element in a structure as a numeric string value. (Note: VARPTR is SB variable specific)FUNCTION STRPTR(mem_addr)LOCAL tmp_ptr  tmp_ptr = 0  DLL("strncpy " & VARPTR(tmp_ptr) & " " & mem_addr & " 4")  STRPTR = tmp_ptrEND FUNCTION ' Returns a ScriptBasic string variable given the memory address in numeric text format of a null terminated string variable or element of a structure.FUNCTION GETSTR(mem_addr)LOCAL tmp_ptr  tmp_ptr = 0  DLL("strncpy " & VARPTR(tmp_ptr) & " " & mem_addr & " 4")  tmp_ptr = DLL("strdup " & tmp_ptr)  GETSTR = tmp_ptrEND FUNCTION ' Returns a string of data given the memory address of a data pointer and the length in bytes requested.FUNCTION GETMEM(mem_addr, bytes)LOCAL tmp_ptr, tmp_data  tmp_ptr = 0  DLL("strncpy " & VARPTR(tmp_ptr) & " " & mem_addr & " 4")  tmp_data = 0  tmp_data = DLL("strncpy " & VARPTR(tmp_data) & " " & tmp_ptr & " " & bytes)  GETMEM = tmp_dataEND FUNCTION ' Convert a string to a hex representation of it.FUNCTION Str2Hex(str_arg)  LOCAL str_len, pos, hex_str  str_len = LEN(str_arg)  IF str_len THEN    FOR pos = 1 TO str_len      hex_str &= RIGHT("0" & HEX(ASC(MID(str_arg, pos, 1))),2)    NEXT  ELSE    hex_str = ""  END IF  Str2Hex = hex_strEND FUNCTION 

Navigation

[0] Message Index

Go to full version