[pywin32-checkins] pywin32/win32/src win32clipboardmodule.cpp, 1.15, 1.16
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Roger U. <ru...@us...> - 2007-01-16 16:56:02
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3911/win32/src Modified Files: win32clipboardmodule.cpp Log Message: Fix places where HANDLEs were treated as ints Index: win32clipboardmodule.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32clipboardmodule.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** win32clipboardmodule.cpp 2 Dec 2005 07:50:47 -0000 1.15 --- win32clipboardmodule.cpp 16 Jan 2007 16:55:51 -0000 1.16 *************** *** 56,64 **** HWND hWndRemove; HWND hWndNewNext; ! ! if (!PyArg_ParseTuple(args, "ii:ChangeClipboardChain", ! &hWndRemove, &hWndNewNext)) { return NULL; } BOOL rc; --- 56,68 ---- HWND hWndRemove; HWND hWndNewNext; ! PyObject *obhWndRemove, *obhWndNewNext; ! if (!PyArg_ParseTuple(args, "OO:ChangeClipboardChain", ! &obhWndRemove, &obhWndNewNext)) { return NULL; } + if (!PyWinObject_AsHANDLE(obhWndRemove, (HANDLE *)&hWndRemove, FALSE)) + return NULL; + if (!PyWinObject_AsHANDLE(obhWndNewNext, (HANDLE *)&hWndNewNext, TRUE)) + return NULL; BOOL rc; *************** *** 286,290 **** if (!handle) return ReturnAPIError("GetClipboardData"); ! return PyLong_FromVoidPtr(handle); } --- 290,294 ---- if (!handle) return ReturnAPIError("GetClipboardData"); ! return PyWinLong_FromHANDLE(handle); } *************** *** 456,465 **** py_get_global_memory(PyObject* self, PyObject* args) { ! int iglobal; ! // @pyparm int|hglobal||The handle to the global memory object ! if (!PyArg_ParseTuple(args, "i", &iglobal)) return NULL; ! HGLOBAL hglobal = (HGLOBAL)iglobal; ! DWORD size = GlobalSize(hglobal); if (!size) return ReturnAPIError("GlobalSize"); --- 460,471 ---- py_get_global_memory(PyObject* self, PyObject* args) { ! HGLOBAL hglobal; ! PyObject *obhglobal; ! // @pyparm <o PyHANDLE>|hglobal||The handle to the global memory object ! if (!PyArg_ParseTuple(args, "O", &obhglobal)) return NULL; ! if (!PyWinObject_AsHANDLE(obhglobal, &hglobal, FALSE)) ! return NULL; ! size_t size = GlobalSize(hglobal); if (!size) return ReturnAPIError("GlobalSize"); *************** *** 530,538 **** Py_END_ALLOW_THREADS; ! if (!rc) { return ReturnAPIError("GetClipboardOwner"); ! } ! ! return (Py_BuildValue("i", (int)rc)); // @comm The clipboard can still contain data even if the clipboard is not --- 536,542 ---- Py_END_ALLOW_THREADS; ! if (!rc) return ReturnAPIError("GetClipboardOwner"); ! return PyWinLong_FromHANDLE(rc); // @comm The clipboard can still contain data even if the clipboard is not *************** *** 613,621 **** Py_END_ALLOW_THREADS; ! if (!rc) { return ReturnAPIError("GetClipboardViewer"); ! } ! ! return (Py_BuildValue("i", (int)rc)); // @pyseeapi GetClipboardViewer --- 617,623 ---- Py_END_ALLOW_THREADS; ! if (!rc) return ReturnAPIError("GetClipboardViewer"); ! return PyWinLong_FromHANDLE(rc); // @pyseeapi GetClipboardViewer *************** *** 646,654 **** Py_END_ALLOW_THREADS; ! if (!rc) { return ReturnAPIError("GetOpenClipboardWindow"); - } ! return (Py_BuildValue("i", (int)rc)); // @comm If an application or dynamic-link library (DLL) specifies a NULL --- 648,655 ---- Py_END_ALLOW_THREADS; ! if (!rc) return ReturnAPIError("GetOpenClipboardWindow"); ! return PyWinLong_FromHANDLE(rc); // @comm If an application or dynamic-link library (DLL) specifies a NULL *************** *** 775,791 **** { ! // @pyparm int|hWnd||Integer handle to the window to be associated with the ! // open clipboard. If this parameter is 0, the open clipboard is associated // with the current task. ! HWND pyHwnd = 0; ! if (!PyArg_ParseTuple(args, "|i:OpenClipboard", ! &pyHwnd)) { return NULL; - } BOOL rc; Py_BEGIN_ALLOW_THREADS; ! rc = OpenClipboard(pyHwnd); Py_END_ALLOW_THREADS; --- 776,794 ---- { ! // @pyparm <o PyHANDLE>|hWnd|None|Integer handle to the window to be associated with the ! // open clipboard. If this parameter is None, the open clipboard is associated // with the current task. ! HWND hWnd; ! PyObject *obhWnd=Py_None; ! if (!PyArg_ParseTuple(args, "|O:OpenClipboard", ! &obhWnd)) return NULL; + if (!PyWinObject_AsHANDLE(obhWnd, (HANDLE *)&hWnd, TRUE)) + return NULL; BOOL rc; Py_BEGIN_ALLOW_THREADS; ! rc = OpenClipboard(hWnd); Py_END_ALLOW_THREADS; *************** *** 887,919 **** int format; HANDLE handle; ! int ihandle; ! if (PyArg_ParseTuple(args, "ii:SetClipboardData", ! &format, &ihandle)) { ! handle = (HANDLE)ihandle; ! } else { PyErr_Clear(); // @pyparmalt1 int|format||Specifies a clipboard format. For a description of // the standard clipboard formats, see Standard Clipboard Formats. - // @pyparmalt1 object|ob||An object that has a read-buffer interface. // A global memory object is allocated, and the objects buffer is copied // to the new memory. - PyObject *obBuf; const void * buf = NULL; int bufSize = 0; - if (!PyArg_ParseTuple(args, "iO:SetClipboardData", - &format, &obBuf)) - return NULL; ! if (PyObject_AsReadBuffer(obBuf,&buf,&bufSize)==-1) RETURN_TYPE_ERR("The object must support the buffer interfaces"); // size doesnt include nulls! ! if (PyString_Check(obBuf)) bufSize += 1; ! else if (PyUnicode_Check(obBuf)) bufSize += sizeof(wchar_t); // else assume buffer needs no terminator... ! handle = GlobalAlloc(GHND, (DWORD)bufSize); if (handle == NULL) { return ReturnAPIError("GlobalAlloc"); --- 890,917 ---- int format; HANDLE handle; ! PyObject *obhandle; ! if (!PyArg_ParseTuple(args, "iO:SetClipboardData", ! &format, &obhandle)) ! return NULL; ! if (!PyWinObject_AsHANDLE(obhandle , &handle, TRUE)){ PyErr_Clear(); // @pyparmalt1 int|format||Specifies a clipboard format. For a description of // the standard clipboard formats, see Standard Clipboard Formats. // @pyparmalt1 object|ob||An object that has a read-buffer interface. // A global memory object is allocated, and the objects buffer is copied // to the new memory. const void * buf = NULL; int bufSize = 0; ! if (PyObject_AsReadBuffer(obhandle,&buf,&bufSize)==-1) RETURN_TYPE_ERR("The object must support the buffer interfaces"); // size doesnt include nulls! ! if (PyString_Check(obhandle)) bufSize += 1; ! else if (PyUnicode_Check(obhandle)) bufSize += sizeof(wchar_t); // else assume buffer needs no terminator... ! handle = GlobalAlloc(GHND, bufSize); if (handle == NULL) { return ReturnAPIError("GlobalAlloc"); *************** *** 928,935 **** Py_END_ALLOW_THREADS; ! if (!data) { return ReturnAPIError("SetClipboardData"); ! } ! return (Py_BuildValue("i", (int)data)); // @comm The uFormat parameter can identify a registered clipboard format, --- 926,932 ---- Py_END_ALLOW_THREADS; ! if (!data) return ReturnAPIError("SetClipboardData"); ! return PyWinLong_FromHANDLE(data); // @comm The uFormat parameter can identify a registered clipboard format, *************** *** 988,996 **** Py_END_ALLOW_THREADS; ! if (!data) { return ReturnAPIError("SetClipboardText"); ! } ! ! return (Py_BuildValue("i", (int)data)); // @pyseeapi SetClipboardData --- 985,991 ---- Py_END_ALLOW_THREADS; ! if (!data) return ReturnAPIError("SetClipboardText"); ! return PyWinLong_FromHANDLE(data); // @pyseeapi SetClipboardData *************** *** 1006,1027 **** //***************************************************************************** // ! // @pymethod int|win32clipboard|SetClipboardViewer|The SetClipboardViewer function // adds the specified window to the chain of clipboard viewers. Clipboard // viewer windows receive a WM_DRAWCLIPBOARD message whenever the content of // the clipboard changes. ! static PyObject * py_set_clipboard_viewer(PyObject* self, PyObject* args) { ! // @pyparm int|hWndNewViewer||Integer handle to the window to be added to ! // the clipboard chain. ! HWND hWndNewViewer; ! if (!PyArg_ParseTuple(args, "i:SetClipboardViewer", ! &hWndNewViewer)) { return NULL; ! } ! HWND rc; Py_BEGIN_ALLOW_THREADS; --- 1001,1021 ---- //***************************************************************************** // ! // @pymethod <o PyHANDLE>|win32clipboard|SetClipboardViewer|The SetClipboardViewer function // adds the specified window to the chain of clipboard viewers. Clipboard // viewer windows receive a WM_DRAWCLIPBOARD message whenever the content of // the clipboard changes. ! // @rdesc Returns a handle to the next window in chain, or None if no other viewer exists. static PyObject * py_set_clipboard_viewer(PyObject* self, PyObject* args) { ! // @pyparm <o PyHANDLE>|hWndNewViewer||Integer handle to the window to be added to ! // the clipboard chain. HWND hWndNewViewer; ! PyObject *obhwnd; ! if (!PyArg_ParseTuple(args, "O:SetClipboardViewer", &obhwnd)) return NULL; ! if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&hWndNewViewer, FALSE)) ! return NULL; HWND rc; Py_BEGIN_ALLOW_THREADS; *************** *** 1029,1037 **** Py_END_ALLOW_THREADS; ! if (!rc) { ! return ReturnAPIError("SetClipboardViewer"); ! } ! ! return (Py_BuildValue("i", (int)rc)); // @comm The windows that are part of the clipboard viewer chain, called --- 1023,1034 ---- Py_END_ALLOW_THREADS; ! // Function can return NULL on success if there is no other viewer ! if (rc!=NULL) ! return PyWinLong_FromHANDLE(rc); ! DWORD e=GetLastError(); ! if (e) ! return PyWin_SetAPIError("SetClipboardViewer",e); ! Py_INCREF(Py_None); ! return Py_None; // @comm The windows that are part of the clipboard viewer chain, called |