/////////////////////////////////////////////////////////////////// Client Side Errors - translate a COM failure to a Python exception ///////////////////////////////////////////////////////////////////
| 571 | // |
| 572 | //////////////////////////////////////////////////////////////////////// |
| 573 | PyObject *PyCom_BuildPyException(HRESULT errorhr, IUnknown *pUnk /* = NULL */, REFIID iid /* = IID_NULL */) |
| 574 | { |
| 575 | PyObject *obEI = NULL; |
| 576 | TCHAR scodeStringBuf[512]; |
| 577 | GetScodeString(errorhr, scodeStringBuf, sizeof(scodeStringBuf)/sizeof(scodeStringBuf[0])); |
| 578 | |
| 579 | #ifndef MS_WINCE // WINCE doesnt appear to have GetErrorInfo() - compiled, but doesnt link! |
| 580 | if (pUnk != NULL) { |
| 581 | assert(iid != IID_NULL); // If you pass an IUnknown, you should pass the specific IID. |
| 582 | // See if it supports error info. |
| 583 | ISupportErrorInfo *pSEI; |
| 584 | HRESULT hr; |
| 585 | Py_BEGIN_ALLOW_THREADS |
| 586 | hr = pUnk->QueryInterface(IID_ISupportErrorInfo, (void **)&pSEI); |
| 587 | if (SUCCEEDED(hr)) { |
| 588 | hr = pSEI->InterfaceSupportsErrorInfo(iid); |
| 589 | pSEI->Release(); // Finished with this object |
| 590 | } |
| 591 | Py_END_ALLOW_THREADS |
| 592 | if (SUCCEEDED(hr)) { |
| 593 | IErrorInfo *pEI; |
| 594 | Py_BEGIN_ALLOW_THREADS |
| 595 | hr=GetErrorInfo(0, &pEI); |
| 596 | Py_END_ALLOW_THREADS |
| 597 | if (hr==S_OK) { |
| 598 | obEI = PyCom_PyObjectFromIErrorInfo(pEI, errorhr); |
| 599 | PYCOM_RELEASE(pEI); |
| 600 | } |
| 601 | } |
| 602 | } |
| 603 | #endif // MS_WINCE |
| 604 | if (obEI==NULL) { |
| 605 | obEI = Py_None; |
| 606 | Py_INCREF(Py_None); |
| 607 | } |
| 608 | PyObject *evalue = Py_BuildValue("iNOO", errorhr, PyWinObject_FromTCHAR(scodeStringBuf), obEI, Py_None); |
| 609 | Py_DECREF(obEI); |
| 610 | |
| 611 | PyErr_SetObject(PyWinExc_COMError, evalue); |
| 612 | Py_XDECREF(evalue); |
| 613 | return NULL; |
| 614 | } |
| 615 | |
| 616 | // Uses the HRESULT and an EXCEPINFO structure to create and |
| 617 | // set a pythoncom.com_error. |