hr为一个负数,Com里查看错误代码是用GetLastError吗

解决方案 »

  1.   

    #include <Mshtml.h>
    #include <windows.h>
    #include <stdio.h>
    #include <comdef.h>
    #include <tchar.h>
    #include <atlbase.h>
    #include <oleacc.h>
    BOOL CALLBACK EnumChildProc(HWND hwnd,LPARAM lParam)
    {
    TCHAR buf[100]; ::GetClassName( hwnd, (LPTSTR)&buf, 100 );
    if ( _tcscmp( buf, _T("Internet Explorer_Server") ) == 0 )
    {
    *(HWND*)lParam = hwnd;
    return FALSE;
    }
    else
    return TRUE;
    };IHTMLDocument2*  GetDocInterface(HWND  hWnd)    
    {  
               //  我们需要显示地装载OLEACC.DLL,这样我们才知道有没有安装MSAA  
               HINSTANCE  hInst  =  ::LoadLibrary(  _T("OLEACC.DLL")  );  
               IHTMLDocument2*  pDoc2=NULL;  
               if  (  hInst  !=  NULL  ){  
        HWND hWndChild=NULL;
    // Get 1st document window
    ::EnumChildWindows( hWnd, EnumChildProc, (LPARAM)&hWndChild );                       if  (  hWndChild  !=  NULL  ){  
                                       CComPtr<IHTMLDocument>  spDoc=NULL;  
                                       LRESULT  lRes;  
     
                                       UINT  nMsg  =  ::RegisterWindowMessage(  _T("WM_HTML_GETOBJECT")  );  
                                       ::SendMessageTimeout(  hWndChild,  nMsg,  0L,  0L,  SMTO_ABORTIFHUNG,  1000,  (DWORD*)&lRes  );  
     
                                       LPFNOBJECTFROMLRESULT  pfObjectFromLresult  =  (LPFNOBJECTFROMLRESULT)::GetProcAddress(  hInst,  _T("ObjectFromLresult")  );  
                                       if  (  pfObjectFromLresult  !=  NULL  ){  
                                                   HRESULT  hr;  
                                                   hr=pfObjectFromLresult(lRes,IID_IHTMLDocument,0,(void**)&spDoc);  
                                                   if  (  SUCCEEDED(hr)  )
       {  
       printf("here\n");
                                                               CComPtr<IDispatch>  spDisp;  
                                                               CComQIPtr<IHTMLWindow2>  spWin;  
                                                               spDoc->get_Script(  &spDisp  );  
                                                               spWin  =  spDisp;  
                                                               spWin->get_document(  &pDoc2  );  
                                                   }  
                                       }  
       else
       {
       printf("pfObjectFromLresult  ==  NULL\n");
       }
                           }  
                           ::FreeLibrary(hInst);  
               }    
               else{//如果没有安装MSAA  
                           printf(_T("请您安装Microsoft  Active  Acces\nsibility"));  
               }  
               return  pDoc2;  
    }    
    BOOL CALLBACK EnumWindowsProc(
      HWND hwnd,      // handle to parent window
      LPARAM lParam   // application-defined value
    )
    {
    IHTMLDocument2* pdoc2=GetDocInterface(hwnd);
    if(pdoc2!=NULL)
    {
    BSTR bsturl;
    pdoc2->get_URL(&bsturl); printf("find IE window:%x,url:%s\n",hwnd,(char*)_bstr_t(bsturl));
    SysFreeString(bsturl);
    pdoc2->Release();
    }
    // else
    // printf("%x is not IE window\n",hwnd);
    return true;
    }
    void main()
    {
    CoInitialize(NULL);
    EnumWindows(EnumWindowsProc,0);
    CoUninitialize();
    }
      

  2.   

    看文档
    比如这样
    IMAPISession::Advise
    The IMAPISession::Advise method registers to receive notification of specified events affecting the session.
    ……
    Return Values
    S_OK 
    The registration was successful. 
    MAPI_E_INVALID_ENTRYID 
    The entry identifier pointed to by lpEntryID does not represent a valid entry identifier. 
    MAPI_E_NO_SUPPORT 
    The service provider responsible for the entry identifier pointed to by lpEntryID either does not support the type of events specified in the ulEventMask parameter or does not support notification. 
    MAPI_E_UNKNOWN_ENTRYID 
    The entry identifier pointed to by lpEntryID cannot be handled by any of the service providers in the profile. 微软文档
    ObjectFromLresult
    The ObjectFromLresult function retrieves a requested interface pointer for an accessible object based on a previously generated object reference. This function is designed for internal use by Active Accessibility and is documented for informational purposes only. Neither clients nor servers should call this function.STDAPI ObjectFromLresult(
      LRESULT lResult,
      REFIID riid,
      WPARAM wParam,
      void** ppvObject
    );
    Parameters
    lResult 
    [in] A 32-bit value returned by a previous successful call to the LresultFromObject function. 
    riid 
    [in] Reference identifier of the interface to be retrieved. This is IID_IAccessible. 
    wParam 
    [in] Additional information is provided in the associated wParam parameter of the WM_GETOBJECT message. 
    ppvObject 
    [out] Receives the address of the interface pointer to return to the client. 
    Return Values
    If successful, returns S_OK. If not successful, returns one of the following standard COM error codes.Error Description 
    E_INVALIDARG  One or more arguments are invalid. This occurs when the lResult parameter specified is not a value obtained by a call to LresultFromObject, or when lResult is a value used on a previous call to ObjectFromLresult.  
    E_NOINTERFACE  The object does not support the interface specified by the riid parameter.  
    E_UNEXPECTED  An unexpected error occurred.  
    Requirements 
      Windows NT/2000/XP: Included in Windows XP and Windows .NET Server.
      Windows 95/98/Me: Unsupported.
      Redistributable: Requires Active Accessibility 2.0 RDK on Windows NT 4.0 SP6 and Windows 98.
      Header: Declared in Oleacc.h.
      Library: Use Oleacc.lib.
      

  3.   

    masterz,在枚举子窗口时失败,原因可能是什么?(hwnd是当前IE窗口的句柄呀)
    BOOL CALLBACK EnumChildProc(HWND hwnd,LPARAM lParam)
    {
    TCHAR buf[100]; ::GetClassName( hwnd, (LPTSTR)&buf, 100 );
    if ( _tcscmp( buf, _T("Internet Explorer_Server") ) == 0 )
    {
    *(HWND*)lParam = hwnd;
    return FALSE;
    }
    else
    return TRUE;
    };