[pywin32-checkins] pywin32/com/win32com/src PythonCOM.cpp, 1.49, 1.50
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2008-07-19 06:23:35
|
Update of /cvsroot/pywin32/pywin32/com/win32com/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17304/win32com/src Modified Files: PythonCOM.cpp Log Message: Add pythoncom.ObjectFromLresult() and a test using IE. Index: PythonCOM.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/PythonCOM.cpp,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** PythonCOM.cpp 4 Sep 2007 10:53:29 -0000 1.49 --- PythonCOM.cpp 19 Jul 2008 06:23:40 -0000 1.50 *************** *** 15,18 **** --- 15,19 ---- #include "PythonCOMServer.h" #include "PyFactory.h" + #include "OleAcc.h" // for ObjectFromLresult proto... // keep a reference to pythoncom'm __dict__ so the COM currency format can be looked up dynamically *************** *** 91,94 **** --- 92,97 ---- ) = NULL; + // typedefs for the function pointers are in OleAcc.h + LPFNOBJECTFROMLRESULT pfnObjectFromLresult = NULL; BOOL PyCom_HasDCom() *************** *** 1745,1748 **** --- 1748,1795 ---- } + // @pymethod <o PyIUnknown>|pythoncom|ObjectFromLresult|Retrieves a requested + // interface pointer for an object based on a previously generated object reference. + static PyObject *pythoncom_ObjectFromLresult(PyObject *self, PyObject *args) + { + PyObject *oblresult; + PyObject *obIID = NULL; + PyObject *obwparam; + // @pyparam int|lresult|| + // @pyparm <o PyIID>|iid||The IID to query + // @pyparm int|wparm|| + LRESULT lresult; + WPARAM wparam; + IID iid; + if (!PyArg_ParseTuple(args, "OOO", &oblresult, &obIID, &obwparam)) + return NULL; + if (!PyWinLong_AsULONG_PTR(oblresult, (ULONG_PTR *)&lresult)) + return NULL; + if (!PyWinLong_AsULONG_PTR(obwparam, (ULONG_PTR *)&wparam)) + return NULL; + if (obIID && !PyWinObject_AsIID(obIID, &iid)) + return NULL; + + // GIL protects us from races here. + if (pfnObjectFromLresult==NULL) { + HMODULE hmod = LoadLibrary("oleacc.dll"); + if (hmod) + pfnObjectFromLresult = (LPFNOBJECTFROMLRESULT) + GetProcAddress(hmod, "ObjectFromLresult"); + } + if (pfnObjectFromLresult==NULL) + return PyErr_Format(PyExc_NotImplementedError, + "Not available on this platform"); + + HRESULT hr; + void *ret = 0; + Py_BEGIN_ALLOW_THREADS + hr = (*pfnObjectFromLresult)(lresult, iid, wparam, &ret); + Py_END_ALLOW_THREADS + if (FAILED(hr)) { + PyCom_BuildPyException(hr); + return NULL; + } + return PyCom_PyObjectFromIUnknown((IUnknown *)ret, iid, FALSE); + } /* List of module functions */ *************** *** 1815,1818 **** --- 1862,1866 ---- { "new", pythoncom_new, 1 }, { "New", pythoncom_new, 1 }, // @pymeth New|Create a new instance of an OLE automation server. + { "ObjectFromLresult", pythoncom_ObjectFromLresult, 1 }, // @pymeth ObjectFromLresult|Returns a COM object given its address in memory. { "OleInitialize", pythoncom_OleInitialize, 1}, // @pymeth OleInitialize| { "OleGetClipboard", pythoncom_OleGetClipboard, 1}, // @pymeth OleGetClipboard|Retrieves a data object that you can use to access the contents of the clipboard. |