Uses the HRESULT and an EXCEPINFO structure to create and set a pythoncom.com_error. Used rarely - currently by IDispatch and IActiveScriptParse* interfaces.
| 617 | // set a pythoncom.com_error. |
| 618 | // Used rarely - currently by IDispatch and IActiveScriptParse* interfaces. |
| 619 | PyObject* PyCom_BuildPyExceptionFromEXCEPINFO(HRESULT hr, EXCEPINFO *pexcepInfo /* = NULL */, UINT nArgErr /* = -1 */) |
| 620 | { |
| 621 | TCHAR buf[512]; |
| 622 | GetScodeString(hr, buf, sizeof(buf)/sizeof(TCHAR)); |
| 623 | PyObject *obScodeString = PyWinObject_FromTCHAR(buf); |
| 624 | PyObject *evalue; |
| 625 | PyObject *obArg; |
| 626 | |
| 627 | if ( nArgErr != -1 ) { |
| 628 | obArg = PyInt_FromLong(nArgErr); |
| 629 | } else { |
| 630 | obArg = Py_None; |
| 631 | Py_INCREF(obArg); |
| 632 | } |
| 633 | if (pexcepInfo==NULL) |
| 634 | { |
| 635 | evalue = Py_BuildValue("iOzO", hr, obScodeString, NULL, obArg); |
| 636 | } |
| 637 | else |
| 638 | { |
| 639 | PyObject *obExcepInfo = PyCom_PyObjectFromExcepInfo(pexcepInfo); |
| 640 | if ( obExcepInfo ) |
| 641 | { |
| 642 | evalue = Py_BuildValue("iOOO", hr, obScodeString, obExcepInfo, obArg); |
| 643 | Py_DECREF(obExcepInfo); |
| 644 | } |
| 645 | else |
| 646 | evalue = NULL; |
| 647 | |
| 648 | /* done with the exception, free it */ |
| 649 | PyCom_CleanupExcepInfo(pexcepInfo); |
| 650 | } |
| 651 | Py_DECREF(obArg); |
| 652 | PyErr_SetObject(PyWinExc_COMError, evalue); |
| 653 | Py_XDECREF(evalue); |
| 654 | Py_XDECREF(obScodeString); |
| 655 | return NULL; |
| 656 | } |
| 657 | |
| 658 | PyObject* PyCom_BuildInternalPyException(char *msg) |
| 659 | { |
no test coverage detected