本文主要是介绍aardio - 向API函数传址取文本的方法探讨,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
关于Aardio中调用API时,变量传址的方法,一般用 struct 类型可以了,用起来很简单。
但是对于文本型,方法可能很多。
本文重点探讨一下传递各种类型变量给API函数,并取回文本型数据的方法。
下面就以 GetWindowText 为例,演示各种取API中文本数据的方法:
import console;
import winvar gwt,t,r//===========================================================console.log('\n先声明,再调用:\n')//声明为string类型
gwt = ::User32.api("GetWindowTextA","int(addr,string,int)")// 用string类型变量t = string.repeat(255,'\x0')r = gwt (..win.getForeground(),t,255)t = raw.tostring(raw.toPointer(t))console.log('1、声明为 string,传递 string,变量值:'+t,r+"个字符")// 用buffer类型变量t = raw.buffer(255)r = gwt (..win.getForeground(),t,255)t = raw.tostring(raw.toPointer(t))console.log('2、声明为 string,传递 buffer,变量值:'+ t,r+"个字符")//声明为string&类型
gwt = ::User32.api("GetWindowTextA","int(addr,string&,int)")// 用string类型变量r,t = gwt (..win.getForeground(),string.repeat(255,'\x0'),255)t = raw.tostring(raw.toPointer(t))console.log('3、声明为 string&,传递 string,返回值:'+t,r+"个字符")r,t = gwt (..win.getForeground(),raw.buffer(255),255)t = raw.tostring(raw.toPointer(t))console.log('4、声明为 string&,传递 buffer,返回值:'+t,r+"个字符")//声明为pointer类型
gwt = ::User32.api("GetWindowTextA","int(addr,pointer,int)")// 用string类型变量t = string.repeat(255,'\x0')r = gwt (..win.getForeground(),t,255)t = raw.tostring(raw.toPointer(t))console.log('5、声明为 pointer,传递 string,变量值:'+ t,r+"个字符")// 用buffer类型变量t = raw.buffer(255)r = gwt (..win.getForeground(),t,255)t = raw.tostring(raw.toPointer(t))console.log('6、声明为 pointer,传递 buffer,变量值:'+ t,r+"个字符")//声明为struct&类型
gwt = ::User32.api("GetWindowTextA","int(addr,struct&,int)")// 用struct类型变量t = {byte t[255]}r = gwt (..win.getForeground(),t,255)t = raw.tostring(raw.toPointer(t.t))console.log('7、声明为 struct&,传递 struct,变量值:'+ t,r+"个字符")// 用struct类型变量r,t = gwt (..win.getForeground(),{byte t[255]},255)t = raw.tostring(raw.toPointer(t.t))console.log('8、声明为 struct&,传递 struct,变量值:'+ t,r+"个字符")//===========================================================console.log('\n不声明,直接调用:\n')//直接传递string类型t = string.repeat(255,'\x0')r = User32.GetWindowTextA(..win.getForeground(),t,255)t = raw.tostring(raw.toPointer(t))console.log('1、直接传递 string,变量值:'+ t,r+"个字符")//直接传递buffer类型t = raw.buffer(255)r = User32.GetWindowTextA(..win.getForeground(),t,255)t = raw.tostring(raw.toPointer(t))console.log('2、直接传递 buffer,变量值:'+ t,r+"个字符")//直接传递struct类型t = {byte t[255]}r = User32.GetWindowTextA(..win.getForeground(),t,255)t = raw.tostring(raw.toPointer(t.t))console.log('3、直接传递 struct,变量值:'+ t,r+"个字符")//直接传递struct类型r,t = User32.GetWindowTextA(..win.getForeground(),{byte t[255]},255)t = raw.tostring(raw.toPointer(t.t))console.log('4、直接传递 struct,返回值:'+ t,r+"个字符")//===========================================================
console.log('\n')
console.pause(true);
运行结果如下:
============================================================
有其他方法的,欢迎留言告知。
这篇关于aardio - 向API函数传址取文本的方法探讨的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!