Update of /cvsroot/pywin32/pywin32/win32/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16015/win32/src
Modified Files:
PyWinTypes.h PyWinTypesmodule.cpp
Log Message:
Add unified function for converting WPARAM and LPARAM
Index: PyWinTypesmodule.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PyWinTypesmodule.cpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** PyWinTypesmodule.cpp 17 Feb 2007 07:30:16 -0000 1.25
--- PyWinTypesmodule.cpp 20 Feb 2007 10:05:39 -0000 1.26
***************
*** 614,617 ****
--- 614,651 ----
+ // Conversion for WPARAM and LPARAM
+ /* ??? WPARAM is defined as UINT_PTR, and LPARAM is defined as LONG_PTR.
+ Make separate functions to avoid cast ??? */
+ BOOL PyWinObject_AsPARAM(PyObject *ob, WPARAM *pparam)
+ {
+ if (ob==NULL || ob==Py_None){
+ *pparam=NULL;
+ return TRUE;
+ }
+ #ifdef UNICODE
+ #define TCHAR_DESC "Unicode"
+ if (PyUnicode_Check(ob)){
+ *pparam = (WPARAM)PyUnicode_AS_UNICODE(ob);
+ return TRUE;
+ }
+ #else
+ #define TCHAR_DESC "String"
+ if (PyString_Check(ob)){
+ *pparam = (WPARAM)PyString_AS_STRING(ob);
+ return TRUE;
+ }
+ #endif
+ if (PyWinLong_AsVoidPtr(ob, (void **)pparam))
+ return TRUE;
+
+ PyErr_Clear();
+ PyBufferProcs *pb = ob->ob_type->tp_as_buffer;
+ if (pb != NULL && pb->bf_getreadbuffer)
+ return pb->bf_getreadbuffer(ob,0,(VOID **)pparam)!=-1;
+ PyErr_SetString(PyExc_TypeError, "WPARAM must be a " TCHAR_DESC ", int, or buffer object");
+ return FALSE;
+ }
+
+
/* List of functions exported by this module */
// @module pywintypes|A module which supports common Windows types.
Index: PyWinTypes.h
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PyWinTypes.h,v
retrieving revision 1.33
retrieving revision 1.34
diff -C2 -d -r1.33 -r1.34
*** PyWinTypes.h 17 Feb 2007 07:30:16 -0000 1.33
--- PyWinTypes.h 20 Feb 2007 10:05:39 -0000 1.34
***************
*** 341,344 ****
--- 341,347 ----
#endif
+ // WPARAM and LPARAM conversion
+ PYWINTYPES_EXPORT BOOL PyWinObject_AsPARAM(PyObject *ob, WPARAM *pparam);
+
/*
** SECURITY_ATTRIBUTES support
|