W
windcowboy
Unregistered / Unconfirmed
GUEST, unregistred user!
近期想用Delphi研究下DirectUIHWND技术,发现一个问题就是无法解决,以前有朋友提出过,但不是很自信,据说也解决了,那请不吝赐教。问题很简单,AccessibleObjectFromWindow这个函数在Delphi里面就是无法正确的返回IAccessible指针,同样的代码我用VS2008WTL就可以简单的通过,非常的奇怪,代码如下:procedure TForm5.Button2Click(Sender: TObject);const OBJID_NATIVEOM = $FFFFFFF0;var hMsn,hChild,hChild1: THandle; IAcc: IAccessible; hLib: THandle; Func: TAccessibleObjectFromWindow; hr: HRESULT;begin hMsn := 0; iAcc := nil; Func := nil; hMsn := FindWindowEx(0,0,'MSBLWindowClass',nil); if hMsn>0 then begin //hChild := FindWindowEx(hMsn, 0, 'DirectUIHWND', nil); hChild := FindWindowEx(hMsn, 0, 'Main Window Class', nil); if hChild>0 then begin hChild1 := FindWindowEx(hChild, 0, 'DirectUIHWND', nil); if hChild1>0 then begin IAcc := nil; hLib := LoadLibrary('oleacc.dll'); if hLib>0 then begin @Func := GetProcAddress(hLib,'AccessibleObjectFromWindow'); if Assigned(Func) then begin hr := Func(hChild1,OBJID_NATIVEOM, IID_IAccessible, Pointer(IAcc)); if hr = s_ok then Caption := 'ok' else Caption := 'error'; end; end; end; end; end;VC++的几乎一模一样, LRESULT OnBnClickedButton2(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { // TODO: Add your control notification handler code here HWND hMsn,hChild0,hChild1; hMsn = FindWindowEx(0,0,L"MSBLWindowClass",NULL); if(hMsn>0) { hChild0 = FindWindowEx(hMsn,0,L"Main Window Class",NULL); if (hChild0>0) { hChild1 = FindWindowEx(hChild0,0,L"DirectUIHWND",NULL); if (hChild1>0) { IAccessible *objAcc=NULL; HMODULE hLib = ::LoadLibrary(L"oleacc.dll"); if (hLib>0) { HREFTYPE hr; FuncAccessibleObjectFromWindow Func; Func = (FuncAccessibleObjectFromWindow)GetProcAddress(hLib,"AccessibleObjectFromWindow"); hr = Func(hChild1,0,IID_IAccessible,(void **)&objAcc); if (hr!=S_OK) { MessageBox(L"error",L"Message"); } else { MessageBox(L"ok",L"Message"); } } } } } return 0; }};请高手赐教一下,为什么同样的函数调用,怎么就不能返回正确的结果吗?难道是最后的那个void** ppvObject的定义问题,参数问题?谢谢,着急,盼复。(需要Windows Live Messenger来测试这个问题。)