通过aardio获取QQ消息中学习使用raw.malloc( 16/*sizeof(Variant)*/ * accParent.accChildCount );
By
admin
at 2018-09-25 • 0人收藏 • 1673人看过
记得之前有使用halcon的时候有一个指针,一直都没有解决这个问题.
今天突然发现论坛里这个代码有一个使用示例可以参考
import com; var oleacc = ..raw.loadDll("OLEACC.DLL"); IID_IAccessible = '\xE0\x36\x87\x61\x3D\x3C\xCF\x11\x81\x0C\x00\xAA\x00\x38\x9B\x71'; var findAccessibleChildren; findAccessibleChildren = function(accParent,name){ //这里用结构体数组也可以,直接分配内存代码更简单,因为aardio分配内存时已经初始化为VT_EMPTY,所以不需要 VariantInit var output = raw.malloc( 16/*sizeof(Variant)*/ * accParent.accChildCount ); obtained = {int size};//用结构体给API提供int指针 var pAccParent = com.GetPointer(accParent); //aardio为了避免指针操作失误,不允许COM对象自动转换为指针,所以自己取一下 var hr,obtained = oleacc.AccessibleChildren(pAccParent, 0,accParent.accChildCount, output,obtained); com.Release(pAccParent); if( hr < 0 ) return;//COM中小于0的都是错误码 for(i=0;obtained.size-1;1){ var p = raw.toPointer(output,16*i); var t = raw.convert(p,{word value}).value; if( t != 9/*_VT_DISPATCH*/ ) continue; //将数组中Variant结构体的指针转换为Variant对象,方便操作 var variant = com.Variant( p,true); var accChild = com.QueryObject( variant.pdispVal ); //转换为COM对象(COM.IDispatch) variant.clear();//释放Variant对象 if( accChild.accName(0/*CHILDID_SELF*/) == name ){ var v = accChild.accValue(0/*CHILDID_SELF*/); if(#v) return v; } var v = findAccessibleChildren(accChild,name); if(#v) return v; } } findAccessibleString = function(hwnd,name){ var pvObject = {ptr p} if( 0 == oleacc.AccessibleObjectFromWindow(hwnd,0,IID_IAccessible,pvObject) ){ var accParent = com.QueryObject( pvObject.p ); //转换为COM对象(COM.IDispatch) com.Release(pvObject.p); return findAccessibleChildren( com.QueryObject( pvObject.p ),name ); } } import winex; import console; for hwnd in winex.each( "TXGuiFoundation") { var qqMessage = findAccessibleString(hwnd,"消息"); if( #qqMessage ) console.log( qqMessage ) } console.pause();
com控件里面好像也要用这个?
Variant
登录后方可回帖