[pywin32-checkins] pywin32/com/win32com/src PythonCOM.cpp,1.34,1.35
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2005-05-24 14:45:12
|
Update of /cvsroot/pywin32/pywin32/com/win32com/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28437 Modified Files: PythonCOM.cpp Log Message: Add CoWaitForMultipleHandles Index: PythonCOM.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/PythonCOM.cpp,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** PythonCOM.cpp 7 Jan 2005 06:54:56 -0000 1.34 --- PythonCOM.cpp 24 May 2005 14:45:01 -0000 1.35 *************** *** 73,76 **** --- 73,84 ---- extern LONG _PyCom_GetGatewayCount(void); + // Function pointers we load at runtime. + HRESULT (STDAPICALLTYPE *pfnCoWaitForMultipleHandles)(DWORD dwFlags, + DWORD dwTimeout, + ULONG cHandles, + LPHANDLE pHandles, + LPDWORD lpdwindex + ) = NULL; + BOOL PyCom_HasDCom() *************** *** 211,215 **** // Jump hoops in case the platform doesnt have it. { // scoping ! HRESULT (*mypfn)(REFCLSID, IUnknown *, DWORD, COSERVERINFO *, ULONG, MULTI_QI *); HMODULE hMod = GetModuleHandle("ole32.dll"); if (hMod==0) { --- 219,223 ---- // Jump hoops in case the platform doesnt have it. { // scoping ! HRESULT (STDAPICALLTYPE *mypfn)(REFCLSID, IUnknown *, DWORD, COSERVERINFO *, ULONG, MULTI_QI *); HMODULE hMod = GetModuleHandle("ole32.dll"); if (hMod==0) { *************** *** 222,226 **** goto done; } ! mypfn = (HRESULT (*)(REFCLSID, IUnknown *, DWORD, COSERVERINFO *, ULONG, MULTI_QI *))fp; PY_INTERFACE_PRECALL; HRESULT hr = (*mypfn)(clsid, punk, dwClsContext, pServerInfo, numIIDs, mqi); --- 230,234 ---- goto done; } ! mypfn = (HRESULT (STDAPICALLTYPE *)(REFCLSID, IUnknown *, DWORD, COSERVERINFO *, ULONG, MULTI_QI *))fp; PY_INTERFACE_PRECALL; HRESULT hr = (*mypfn)(clsid, punk, dwClsContext, pServerInfo, numIIDs, mqi); *************** *** 1311,1314 **** --- 1319,1386 ---- } + static BOOL MakeHandleList(PyObject *handleList, HANDLE **ppBuf, DWORD *pNumEntries) + { + if (!PySequence_Check(handleList)) { + PyErr_SetString(PyExc_TypeError, "Handles must be a list of integers"); + return FALSE; + } + DWORD numItems = (DWORD)PySequence_Length(handleList); + HANDLE *pItems = (HANDLE *)malloc(sizeof(HANDLE) * numItems); + if (pItems==NULL) { + PyErr_SetString(PyExc_MemoryError,"Allocating array of handles"); + return FALSE; + } + for (DWORD i=0;i<numItems;i++) { + PyObject *obItem = PySequence_GetItem(handleList, i); + if (obItem==NULL) { + free(pItems); + return FALSE; + } + if (!PyWinObject_AsHANDLE(obItem,pItems+i)) { + Py_DECREF(obItem); + free(pItems); + PyErr_SetString(PyExc_TypeError, "Handles must be a list of integers"); + return FALSE; + } + Py_DECREF(obItem); + } + *ppBuf = pItems; + *pNumEntries = numItems; + return TRUE; + } + + // @pymethod int|pythoncom|CoWaitForMultipleHandles|Waits for specified handles to be signaled or for a specified timeout period to elapse. + static PyObject *pythoncom_CoWaitForMultipleHandles(PyObject *self, PyObject *args) + { + DWORD flags, timeout; + PyObject *obHandles; + DWORD numItems; + HANDLE *pItems = NULL; + if (!pfnCoWaitForMultipleHandles) { + return PyCom_BuildPyException(E_NOTIMPL); + return NULL; + } + + if (!PyArg_ParseTuple(args, "iiO:CoWaitForMultipleHandles", + &flags, // @pyparm int|flags|| + &timeout, // @pyparm int|timeout|| + &obHandles)) // @pyparm [<o PyHANDLE>, ...]|handles|| + return NULL; + if (!MakeHandleList(obHandles, &pItems, &numItems)) + return NULL; + DWORD index; + PyObject *rc = NULL; + HRESULT hr; + Py_BEGIN_ALLOW_THREADS + hr = (*pfnCoWaitForMultipleHandles)(flags, timeout, numItems, pItems, &index); + Py_END_ALLOW_THREADS + if (FAILED(hr)) { + PyCom_BuildPyException(hr); + } else + rc = PyInt_FromLong(index); + free(pItems); + return rc; + } + // @pymethod <o PyIDataObject>|pythoncom|OleGetClipboard|Retrieves a data object that you can use to access the contents of the clipboard. static PyObject *pythoncom_OleGetClipboard(PyObject *, PyObject *args) *************** *** 1511,1514 **** --- 1583,1587 ---- { "CoRevokeClassObject",pythoncom_CoRevokeClassObject, 1 },// @pymeth CoRevokeClassObject|Informs OLE that a class object, previously registered with the <om pythoncom.CoRegisterClassObject> method, is no longer available for use. { "CoTreatAsClass", pythoncom_CoTreatAsClass, 1}, // @pymeth CoTreatAsClass|Establishes or removes an emulation, in which objects of one class are treated as objects of a different class. + { "CoWaitForMultipleHandles", pythoncom_CoWaitForMultipleHandles, 1}, // @pymeth CoWaitForMultipleHandles|Waits for specified handles to be signaled or for a specified timeout period to elapse. { "Connect", pythoncom_connect, 1 }, // @pymeth Connect|Connects to a running instance of an OLE automation server. { "connect", pythoncom_connect, 1 }, *************** *** 1696,1699 **** --- 1769,1778 ---- PyDict_SetItemString(dict, "PyUnicodeType", (PyObject *)&PyUnicodeType); + // Load function pointers. + HMODULE hModOle32 = GetModuleHandle("ole32.dll"); + pfnCoWaitForMultipleHandles = \ + (HRESULT (STDAPICALLTYPE *)(DWORD, DWORD, ULONG, LPHANDLE, LPDWORD)) \ + GetProcAddress(hModOle32, "CoWaitForMultipleHandles"); + // Symbolic constants. ADD_CONSTANT(ACTIVEOBJECT_STRONG); |