[pywin32-checkins] pywin32/com/win32com/src/extensions PySTGMEDIUM.cpp,1.2,1.3
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2004-04-25 23:58:46
|
Update of /cvsroot/pywin32/pywin32/com/win32com/src/extensions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28720/extensions Modified Files: PySTGMEDIUM.cpp Log Message: When writing to a HGLOBAL's memory, include the strings trailing \0. This should have no effect for binary buffers, but will allow data formats treated as text (eg, CF_TEXT) to work better. Unfortunately, the medium itself has no info about the format, so we can't be smart like the win32clipboard routines. Index: PySTGMEDIUM.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/extensions/PySTGMEDIUM.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PySTGMEDIUM.cpp 9 Oct 2003 12:49:38 -0000 1.2 --- PySTGMEDIUM.cpp 25 Apr 2004 23:58:38 -0000 1.3 *************** *** 47,57 **** break; case TYMED_HGLOBAL: { ! // todo: support buffer if (!PyString_Check(ob)) return PyErr_Format(PyExc_TypeError, "tymed value of %d requires a string", tymed); ! ps->medium.hGlobal = GlobalAlloc(GMEM_FIXED, PyString_Size(ob)); if (!ps->medium.hGlobal) return PyErr_NoMemory(); ! memcpy( (void *)ps->medium.hGlobal, PyString_AsString(ob), PyString_Size(ob)); break; } --- 47,64 ---- break; case TYMED_HGLOBAL: { ! // todo: support buffer (but see byte-count discussion below) if (!PyString_Check(ob)) return PyErr_Format(PyExc_TypeError, "tymed value of %d requires a string", tymed); ! // We need to include the NULL, as the Windows clipboard functions ! // will assume it is there for text related formats (eg, CF_TEXT). ! // I can't see one extra byte could cause any problems - but if ! // in the future it does, we can take the win32clipboard route, ! // and only include the extra \0 for strings, allowing buffers to ! // use the exact cb. ! int cb = PyString_Size(ob)+1; ! ps->medium.hGlobal = GlobalAlloc(GMEM_FIXED, cb); if (!ps->medium.hGlobal) return PyErr_NoMemory(); ! memcpy( (void *)ps->medium.hGlobal, PyString_AsString(ob), cb); break; } |