Update of /cvsroot/pywin32/pywin32/win32/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8182
Modified Files:
win32api_display.cpp win32api_display.h win32apimodule.cpp
win32gui.i
Log Message:
Allow to build with UNICODE defined
Fix some 64-bit warnings
Index: win32apimodule.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/win32apimodule.cpp,v
retrieving revision 1.79
retrieving revision 1.80
diff -C2 -d -r1.79 -r1.80
*** win32apimodule.cpp 17 Dec 2007 03:57:33 -0000 1.79
--- win32apimodule.cpp 6 Feb 2008 18:42:51 -0000 1.80
***************
*** 12,16 ****
******************************************************************/
!
#include "PyWinTypes.h"
#include "PyWinObjects.h"
--- 12,16 ----
******************************************************************/
! // #define UNICODE
#include "PyWinTypes.h"
[...3811 lines suppressed...]
! hmodule = GetModuleHandle(TEXT("user32.dll"));
if (hmodule==NULL)
! hmodule=LoadLibrary(TEXT("user32.dll"));
if (hmodule!=NULL){
pfnEnumDisplayMonitors=(EnumDisplayMonitorsfunc)GetProcAddress(hmodule, "EnumDisplayMonitors");
! pfnEnumDisplayDevices=(EnumDisplayDevicesfunc)GetProcAddress(hmodule, "EnumDisplayDevices" A_OR_W);
! pfnChangeDisplaySettingsEx=(ChangeDisplaySettingsExfunc)GetProcAddress(hmodule, "ChangeDisplaySettingsEx" A_OR_W);
pfnMonitorFromWindow=(MonitorFromWindowfunc)GetProcAddress(hmodule,"MonitorFromWindow");
pfnMonitorFromRect=(MonitorFromRectfunc)GetProcAddress(hmodule,"MonitorFromRect");
pfnMonitorFromPoint=(MonitorFromPointfunc)GetProcAddress(hmodule,"MonitorFromPoint");
! pfnGetMonitorInfo=(GetMonitorInfofunc)GetProcAddress(hmodule, "GetMonitorInfo" A_OR_W);
! pfnEnumDisplaySettingsEx=(EnumDisplaySettingsExfunc)GetProcAddress(hmodule, "EnumDisplaySettingsEx" A_OR_W);
}
! hmodule = GetModuleHandle(TEXT("Advapi32.dll"));
if (hmodule==NULL)
! hmodule=LoadLibrary(TEXT("Advapi32.dll"));
if (hmodule!=NULL){
pfnRegRestoreKey=(RegRestoreKeyfunc)GetProcAddress(hmodule, "RegRestoreKeyW");
Index: win32api_display.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/win32api_display.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** win32api_display.cpp 3 Jun 2007 14:53:07 -0000 1.6
--- win32api_display.cpp 6 Feb 2008 18:42:51 -0000 1.7
***************
*** 1,4 ****
// @doc - This file contains autoduck documentation
!
#include "PyWinTypes.h"
#include "structmember.h"
--- 1,4 ----
// @doc - This file contains autoduck documentation
! // #define UNICODE
#include "PyWinTypes.h"
#include "structmember.h"
***************
*** 148,172 ****
if (strcmp(name,"DeviceName")==0)
if (pdisplay_device->DeviceName[31]==0) // in case DeviceName fills space and has no trailing NULL
! return PyString_FromString((char *)&pdisplay_device->DeviceName);
else
! return PyString_FromStringAndSize((char *)&pdisplay_device->DeviceName, 32);
if (strcmp(name,"DeviceString")==0)
if (pdisplay_device->DeviceString[127]==0) // in case DeviceString fills space and has no trailing NULL
! return PyString_FromString((char *)&pdisplay_device->DeviceString);
else
! return PyString_FromStringAndSize((char *)&pdisplay_device->DeviceString, 128);
if (strcmp(name,"DeviceID")==0)
if (pdisplay_device->DeviceID[127]==0) // in case DeviceID fills space and has no trailing NULL
! return PyString_FromString((char *)&pdisplay_device->DeviceID);
else
! return PyString_FromStringAndSize((char *)&pdisplay_device->DeviceID, 128);
if (strcmp(name,"DeviceKey")==0)
if (pdisplay_device->DeviceKey[127]==0) // in case DeviceKey fills space and has no trailing NULL
! return PyString_FromString((char *)&pdisplay_device->DeviceKey);
else
! return PyString_FromStringAndSize((char *)&pdisplay_device->DeviceKey, 128);
return PyObject_GenericGetAttr(self,obname);
--- 148,172 ----
if (strcmp(name,"DeviceName")==0)
if (pdisplay_device->DeviceName[31]==0) // in case DeviceName fills space and has no trailing NULL
! return PyWinObject_FromTCHAR(pdisplay_device->DeviceName);
else
! return PyWinObject_FromTCHAR(pdisplay_device->DeviceName, 32);
if (strcmp(name,"DeviceString")==0)
if (pdisplay_device->DeviceString[127]==0) // in case DeviceString fills space and has no trailing NULL
! return PyWinObject_FromTCHAR(pdisplay_device->DeviceString);
else
! return PyWinObject_FromTCHAR(pdisplay_device->DeviceString, 128);
if (strcmp(name,"DeviceID")==0)
if (pdisplay_device->DeviceID[127]==0) // in case DeviceID fills space and has no trailing NULL
! return PyWinObject_FromTCHAR(pdisplay_device->DeviceID);
else
! return PyWinObject_FromTCHAR(pdisplay_device->DeviceID, 128);
if (strcmp(name,"DeviceKey")==0)
if (pdisplay_device->DeviceKey[127]==0) // in case DeviceKey fills space and has no trailing NULL
! return PyWinObject_FromTCHAR(pdisplay_device->DeviceKey);
else
! return PyWinObject_FromTCHAR(pdisplay_device->DeviceKey, 128);
return PyObject_GenericGetAttr(self,obname);
***************
*** 175,234 ****
int PyDISPLAY_DEVICE::setattro(PyObject *self, PyObject *obname, PyObject *obvalue)
{
! char *name, *value;
! Py_ssize_t valuelen;
name=PyString_AsString(obname);
if (name==NULL)
return -1;
if (strcmp(name,"DeviceName")==0){
! if (PyString_AsStringAndSize(obvalue, &value, &valuelen)==-1)
return -1;
! if (valuelen > 32){
! PyErr_Format(PyExc_ValueError,"DeviceName must be a string of length %d or less", 32);
return -1;
}
! PDISPLAY_DEVICE pdisplay_device=&((PyDISPLAY_DEVICE *)self)->display_device;
! ZeroMemory(&pdisplay_device->DeviceName, 32);
! memcpy(&pdisplay_device->DeviceName, value, valuelen);
return 0;
}
if (strcmp(name,"DeviceString")==0){
! if (PyString_AsStringAndSize(obvalue, &value, &valuelen)==-1)
return -1;
! if (valuelen > 128){
! PyErr_Format(PyExc_ValueError,"DeviceString must be a string of length %d or less", 128);
return -1;
}
! PDISPLAY_DEVICE pdisplay_device=&((PyDISPLAY_DEVICE *)self)->display_device;
! ZeroMemory(&pdisplay_device->DeviceString, 128);
! memcpy(&pdisplay_device->DeviceString, value, valuelen);
return 0;
}
if (strcmp(name,"DeviceID")==0){
! if (PyString_AsStringAndSize(obvalue, &value, &valuelen)==-1)
return -1;
! if (valuelen > 128){
! PyErr_Format(PyExc_ValueError,"DeviceID must be a string of length %d or less", 128);
return -1;
}
! PDISPLAY_DEVICE pdisplay_device=&((PyDISPLAY_DEVICE *)self)->display_device;
! ZeroMemory(&pdisplay_device->DeviceID, 128);
! memcpy(&pdisplay_device->DeviceID, value, valuelen);
return 0;
}
if (strcmp(name,"DeviceKey")==0){
! if (PyString_AsStringAndSize(obvalue, &value, &valuelen)==-1)
return -1;
! if (valuelen > 128){
! PyErr_Format(PyExc_ValueError,"DeviceKey must be a string of length %d or less", 128);
return -1;
}
! PDISPLAY_DEVICE pdisplay_device=&((PyDISPLAY_DEVICE *)self)->display_device;
! ZeroMemory(&pdisplay_device->DeviceKey, 128);
! memcpy(&pdisplay_device->DeviceKey, value, valuelen);
return 0;
}
! int ret=PyObject_GenericSetAttr(self, obname, obvalue);
! return ret;
}
--- 175,248 ----
int PyDISPLAY_DEVICE::setattro(PyObject *self, PyObject *obname, PyObject *obvalue)
{
! char *name;
! TCHAR *value=NULL;
! DWORD valuelen;
name=PyString_AsString(obname);
if (name==NULL)
return -1;
if (strcmp(name,"DeviceName")==0){
! PDISPLAY_DEVICE pdisplay_device=&((PyDISPLAY_DEVICE *)self)->display_device;
! DWORD cch_max=sizeof(pdisplay_device->DeviceName)/sizeof(TCHAR);
! if (!PyWinObject_AsTCHAR(obvalue, &value, FALSE, &valuelen))
return -1;
! if (valuelen > cch_max){
! PyErr_Format(PyExc_ValueError,"DeviceName must be a string of length %d or less", cch_max);
! PyWinObject_FreeTCHAR(value);
return -1;
}
! ZeroMemory(&pdisplay_device->DeviceName, sizeof(pdisplay_device->DeviceName));
! memcpy(&pdisplay_device->DeviceName, value, valuelen * sizeof(TCHAR));
! PyWinObject_FreeTCHAR(value);
return 0;
}
if (strcmp(name,"DeviceString")==0){
! PDISPLAY_DEVICE pdisplay_device=&((PyDISPLAY_DEVICE *)self)->display_device;
! DWORD cch_max=sizeof(pdisplay_device->DeviceString)/sizeof(TCHAR);
! if (!PyWinObject_AsTCHAR(obvalue, &value, FALSE, &valuelen))
return -1;
! if (valuelen > cch_max){
! PyErr_Format(PyExc_ValueError,"DeviceString must be a string of length %d or less", cch_max);
! PyWinObject_FreeTCHAR(value);
return -1;
}
!
! ZeroMemory(&pdisplay_device->DeviceString, sizeof(pdisplay_device->DeviceString));
! memcpy(&pdisplay_device->DeviceString, value, valuelen * sizeof(TCHAR));
! PyWinObject_FreeTCHAR(value);
return 0;
}
if (strcmp(name,"DeviceID")==0){
! PDISPLAY_DEVICE pdisplay_device=&((PyDISPLAY_DEVICE *)self)->display_device;
! DWORD cch_max=sizeof(pdisplay_device->DeviceID)/sizeof(TCHAR);
! if (!PyWinObject_AsTCHAR(obvalue, &value, FALSE, &valuelen))
return -1;
! if (valuelen > cch_max){
! PyErr_Format(PyExc_ValueError,"DeviceID must be a string of length %d or less", cch_max);
! PyWinObject_FreeTCHAR(value);
return -1;
}
!
! ZeroMemory(&pdisplay_device->DeviceID, sizeof(pdisplay_device->DeviceID));
! memcpy(&pdisplay_device->DeviceID, value, valuelen * sizeof(TCHAR));
! PyWinObject_FreeTCHAR(value);
return 0;
}
if (strcmp(name,"DeviceKey")==0){
! PDISPLAY_DEVICE pdisplay_device=&((PyDISPLAY_DEVICE *)self)->display_device;
! DWORD cch_max=sizeof(pdisplay_device->DeviceKey)/sizeof(TCHAR);
! if (!PyWinObject_AsTCHAR(obvalue, &value, FALSE, &valuelen))
return -1;
! if (valuelen > cch_max){
! PyErr_Format(PyExc_ValueError,"DeviceKey must be a string of length %d or less", cch_max);
! PyWinObject_FreeTCHAR(value);
return -1;
}
! ZeroMemory(&pdisplay_device->DeviceKey, sizeof(pdisplay_device->DeviceKey));
! memcpy(&pdisplay_device->DeviceKey, value, valuelen * sizeof(TCHAR));
! PyWinObject_FreeTCHAR(value);
return 0;
}
! return PyObject_GenericSetAttr(self, obname, obvalue);
}
***************
*** 306,316 ****
DWORD Flags=0;
! char *DeviceName=NULL;
PDEVMODE pdevmode;
! PyObject *obdevmode=Py_None;
long ret;
! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|zOk:ChangeDisplaySettingsEx", keywords,
! &DeviceName, // @pyparm str|DeviceName|None|Name of device as returned by <om win32api.EnumDisplayDevices>, use None for default display device
&obdevmode, // @pyparm <o PyDEVMODE>|DevMode|None|A PyDEVMODE object as returned from <om win32api.EnumDisplaySettings>, or None to reset to default settings from registry
&Flags)) // @pyparm int|Flags|0|One of the win32con.CDS_* constants, or 0
--- 320,330 ----
DWORD Flags=0;
! TCHAR *DeviceName=NULL;
PDEVMODE pdevmode;
! PyObject *obDeviceName=Py_None, *obdevmode=Py_None;
long ret;
! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OOk:ChangeDisplaySettingsEx", keywords,
! &obDeviceName, // @pyparm str|DeviceName|None|Name of device as returned by <om win32api.EnumDisplayDevices>, use None for default display device
&obdevmode, // @pyparm <o PyDEVMODE>|DevMode|None|A PyDEVMODE object as returned from <om win32api.EnumDisplaySettings>, or None to reset to default settings from registry
&Flags)) // @pyparm int|Flags|0|One of the win32con.CDS_* constants, or 0
***************
*** 319,325 ****
if (!PyWinObject_AsDEVMODE(obdevmode, &pdevmode, TRUE))
return NULL;
!
// DISP_CHANGE_* errors don't translate as win32 error codes, just return it
ret=(*pfnChangeDisplaySettingsEx)(DeviceName, pdevmode, (HWND) NULL, Flags, (LPVOID) NULL);
return PyLong_FromLong(ret);
}
--- 333,341 ----
if (!PyWinObject_AsDEVMODE(obdevmode, &pdevmode, TRUE))
return NULL;
! if (!PyWinObject_AsTCHAR(obDeviceName, &DeviceName, TRUE))
! return NULL;
// DISP_CHANGE_* errors don't translate as win32 error codes, just return it
ret=(*pfnChangeDisplaySettingsEx)(DeviceName, pdevmode, (HWND) NULL, Flags, (LPVOID) NULL);
+ PyWinObject_FreeTCHAR(DeviceName);
return PyLong_FromLong(ret);
}
***************
*** 331,335 ****
CHECK_PFN(EnumDisplayDevices);
static char *keywords[]={"Device", "DevNum", "Flags", NULL};
! char *Device=NULL;
DWORD DevNum=0;
DWORD Flags=0;
--- 347,352 ----
CHECK_PFN(EnumDisplayDevices);
static char *keywords[]={"Device", "DevNum", "Flags", NULL};
! TCHAR *Device=NULL;
! PyObject *obDevice = Py_None, *ret=NULL;
DWORD DevNum=0;
DWORD Flags=0;
***************
*** 339,353 ****
// @pyparm int|DevNum|0|Index of device of interest, starting with zero
// @pyparm int|Flags|0|Reserved, use 0 if passed in
! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|zkk:EnumDisplayDevices", keywords,
! &Device, &DevNum, &Flags))
return NULL;
-
ZeroMemory(&display_device,sizeof(DISPLAY_DEVICE));
display_device.cb=sizeof(DISPLAY_DEVICE);
! if (!(*pfnEnumDisplayDevices)(Device, DevNum, &display_device, Flags)){
PyWin_SetAPIError("EnumDisplayDevices");
! return NULL;
! }
! return PyWinObject_FromDISPLAY_DEVICE(&display_device);
}
--- 356,372 ----
// @pyparm int|DevNum|0|Index of device of interest, starting with zero
// @pyparm int|Flags|0|Reserved, use 0 if passed in
! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Okk:EnumDisplayDevices", keywords,
! &obDevice, &DevNum, &Flags))
! return NULL;
! if (!PyWinObject_AsTCHAR(obDevice, &Device, TRUE))
return NULL;
ZeroMemory(&display_device,sizeof(DISPLAY_DEVICE));
display_device.cb=sizeof(DISPLAY_DEVICE);
! if (!(*pfnEnumDisplayDevices)(Device, DevNum, &display_device, Flags))
PyWin_SetAPIError("EnumDisplayDevices");
! else
! ret = PyWinObject_FromDISPLAY_DEVICE(&display_device);
! PyWinObject_FreeTCHAR(Device);
! return ret;
}
***************
*** 357,377 ****
{
static char *keywords[]={"DeviceName","ModeNum",NULL};
! char *DeviceName=NULL;
DWORD ModeNum=0;
DEVMODE devmode;
! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|zk:EnumDisplaySettings", keywords,
! &DeviceName, // @pyparm string|DeviceName|None|Name of device as returned by <om win32api.EnumDisplayDevices>, use None for default display device
&ModeNum)) // @pyparm int|ModeNum|0|Index of setting to return, or one of ENUM_CURRENT_SETTINGS, ENUM_REGISTRY_SETTINGS
return NULL;
!
ZeroMemory(&devmode,sizeof(DEVMODE));
devmode.dmSize=sizeof(DEVMODE);
! if (!EnumDisplaySettings(DeviceName, ModeNum, &devmode)){
// msdn says GetLastError should return something on win2k and up, I get 0
PyWin_SetAPIError("EnumDisplaySettings");
! return NULL;
! }
! return PyWinObject_FromDEVMODE(&devmode);
}
--- 376,399 ----
{
static char *keywords[]={"DeviceName","ModeNum",NULL};
! TCHAR *DeviceName=NULL;
! PyObject *obDeviceName=Py_None, *ret=NULL;
DWORD ModeNum=0;
DEVMODE devmode;
! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Ok:EnumDisplaySettings", keywords,
! &obDeviceName, // @pyparm string|DeviceName|None|Name of device as returned by <om win32api.EnumDisplayDevices>, use None for default display device
&ModeNum)) // @pyparm int|ModeNum|0|Index of setting to return, or one of ENUM_CURRENT_SETTINGS, ENUM_REGISTRY_SETTINGS
return NULL;
! if (!PyWinObject_AsTCHAR(obDeviceName, &DeviceName, TRUE))
! return NULL;
ZeroMemory(&devmode,sizeof(DEVMODE));
devmode.dmSize=sizeof(DEVMODE);
! if (!EnumDisplaySettings(DeviceName, ModeNum, &devmode))
// msdn says GetLastError should return something on win2k and up, I get 0
PyWin_SetAPIError("EnumDisplaySettings");
! else
! ret = PyWinObject_FromDEVMODE(&devmode);
! PyWinObject_FreeTCHAR(DeviceName);
! return ret;
}
***************
*** 382,402 ****
CHECK_PFN(EnumDisplaySettingsEx);
static char *keywords[]={"DeviceName","ModeNum","Flags", NULL};
! char *DeviceName=NULL;
DWORD ModeNum=0;
DEVMODE devmode;
DWORD Flags=0;
! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|zkk:EnumDisplaySettingsEx", keywords,
! &DeviceName, // @pyparm string|DeviceName|None|Name of device as returned by <om win32api.EnumDisplayDevices>. Can be None for default display
&ModeNum, // @pyparm int|ModeNum||Index of setting to return, or one of ENUM_CURRENT_SETTINGS, ENUM_REGISTRY_SETTINGS
&Flags)) // @pyparm int|Flags|0|EDS_RAWMODE (2) is only defined flag
return NULL;
ZeroMemory(&devmode,sizeof(DEVMODE));
devmode.dmSize=sizeof(DEVMODE);
! if (!(*pfnEnumDisplaySettingsEx)(DeviceName, ModeNum, &devmode, Flags)){
PyWin_SetAPIError("EnumDisplaySettingsEx");
! return NULL;
! }
! return PyWinObject_FromDEVMODE(&devmode);
}
--- 404,428 ----
CHECK_PFN(EnumDisplaySettingsEx);
static char *keywords[]={"DeviceName","ModeNum","Flags", NULL};
! TCHAR *DeviceName=NULL;
! PyObject *obDeviceName=Py_None, *ret=NULL;
DWORD ModeNum=0;
DEVMODE devmode;
DWORD Flags=0;
! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Okk:EnumDisplaySettingsEx", keywords,
! &obDeviceName, // @pyparm string|DeviceName|None|Name of device as returned by <om win32api.EnumDisplayDevices>. Can be None for default display
&ModeNum, // @pyparm int|ModeNum||Index of setting to return, or one of ENUM_CURRENT_SETTINGS, ENUM_REGISTRY_SETTINGS
&Flags)) // @pyparm int|Flags|0|EDS_RAWMODE (2) is only defined flag
return NULL;
+ if (!PyWinObject_AsTCHAR(obDeviceName, &DeviceName, TRUE))
+ return NULL;
ZeroMemory(&devmode,sizeof(DEVMODE));
devmode.dmSize=sizeof(DEVMODE);
! if (!(*pfnEnumDisplaySettingsEx)(DeviceName, ModeNum, &devmode, Flags))
PyWin_SetAPIError("EnumDisplaySettingsEx");
! else
! ret = PyWinObject_FromDEVMODE(&devmode);
! PyWinObject_FreeTCHAR(DeviceName);
! return ret;
}
***************
*** 479,487 ****
return NULL;
}
! return Py_BuildValue("{s:O&,s:O&,s:k,s:s}",
"Monitor", PyWinObject_FromRECT, &mi.rcMonitor,
"Work", PyWinObject_FromRECT, &mi.rcWork,
"Flags", mi.dwFlags,
! "Device", mi.szDevice);
}
--- 505,513 ----
return NULL;
}
! return Py_BuildValue("{s:O&,s:O&,s:k,s:N}",
"Monitor", PyWinObject_FromRECT, &mi.rcMonitor,
"Work", PyWinObject_FromRECT, &mi.rcWork,
"Flags", mi.dwFlags,
! "Device", PyWinObject_FromTCHAR(mi.szDevice));
}
Index: win32api_display.h
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/win32api_display.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** win32api_display.h 27 May 2006 07:33:21 -0000 1.2
--- win32api_display.h 6 Feb 2008 18:42:51 -0000 1.3
***************
*** 1,4 ****
--- 1,11 ----
#define CHECK_PFN(fname) if (pfn##fname==NULL) return PyErr_Format(PyExc_NotImplementedError,"%s is not available on this platform", #fname);
+ // Macro to allow loading the correct ANSI/wide-character version of a function from a .dll
+ #ifdef UNICODE
+ #define A_OR_W "W"
+ #else
+ #define A_OR_W "A"
+ #endif
+
PyObject *PyChangeDisplaySettings(PyObject *self, PyObject *args);
PyObject *PyChangeDisplaySettingsEx(PyObject *self, PyObject *args, PyObject *kwargs);
Index: win32gui.i
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/win32gui.i,v
retrieving revision 1.114
retrieving revision 1.115
diff -C2 -d -r1.114 -r1.115
*** win32gui.i 21 Jan 2008 11:12:00 -0000 1.114
--- win32gui.i 6 Feb 2008 18:42:51 -0000 1.115
***************
*** 13,16 ****
--- 13,18 ----
%{
+ // #define UNICODE
+ // #define _UNICODE // for CRT string functions
#define _WIN32_IE 0x0501 // to enable balloon notifications in Shell_NotifyIcon
#define _WIN32_WINNT 0x0501
***************
*** 247,253 ****
pmd->ml_flags = METH_VARARGS | METH_KEYWORDS;
! HMODULE hmodule=GetModuleHandle("user32.dll");
if (hmodule==NULL)
! hmodule=LoadLibrary("user32.dll");
if (hmodule){
pfnSetLayeredWindowAttributes=(SetLayeredWindowAttributesfunc)GetProcAddress(hmodule,"SetLayeredWindowAttributes");
--- 249,255 ----
pmd->ml_flags = METH_VARARGS | METH_KEYWORDS;
! HMODULE hmodule=GetModuleHandle(TEXT("user32.dll"));
if (hmodule==NULL)
! hmodule=LoadLibrary(TEXT("user32.dll"));
if (hmodule){
pfnSetLayeredWindowAttributes=(SetLayeredWindowAttributesfunc)GetProcAddress(hmodule,"SetLayeredWindowAttributes");
***************
*** 260,266 ****
}
! hmodule=GetModuleHandle("gdi32.dll");
if (hmodule==NULL)
! hmodule=LoadLibrary("gdi32.dll");
if (hmodule){
pfnAngleArc=(AngleArcfunc)GetProcAddress(hmodule,"AngleArc");
--- 262,268 ----
}
! hmodule=GetModuleHandle(TEXT("gdi32.dll"));
if (hmodule==NULL)
! hmodule=LoadLibrary(TEXT("gdi32.dll"));
if (hmodule){
pfnAngleArc=(AngleArcfunc)GetProcAddress(hmodule,"AngleArc");
***************
*** 275,281 ****
}
! hmodule=GetModuleHandle("msimg32.dll");
if (hmodule==NULL)
! hmodule=LoadLibrary("msimg32.dll");
if (hmodule){
pfnGradientFill=(GradientFillfunc)GetProcAddress(hmodule,"GradientFill");
--- 277,283 ----
}
! hmodule=GetModuleHandle(TEXT("msimg32.dll"));
if (hmodule==NULL)
! hmodule=LoadLibrary(TEXT("msimg32.dll"));
if (hmodule){
pfnGradientFill=(GradientFillfunc)GetProcAddress(hmodule,"GradientFill");
***************
*** 530,534 ****
%typemap(python,argout) PAINTSTRUCT *OUTPUT {
PyObject *o;
! o = Py_BuildValue("(Nl(iiii)lls#)",
PyWinLong_FromHANDLE($source->hdc),
$source->fErase,
--- 532,536 ----
%typemap(python,argout) PAINTSTRUCT *OUTPUT {
PyObject *o;
! o = Py_BuildValue("(Nl(iiii)llN)",
PyWinLong_FromHANDLE($source->hdc),
$source->fErase,
***************
*** 536,541 ****
$source->fRestore,
$source->fIncUpdate,
! (char *)$source->rgbReserved,
! sizeof($source->rgbReserved));
if (!$target) {
$target = o;
--- 538,542 ----
$source->fRestore,
$source->fIncUpdate,
! PyString_FromStringAndSize((char *)$source->rgbReserved,sizeof($source->rgbReserved)));
if (!$target) {
$target = o;
***************
*** 562,581 ****
%typemap(python,in) PAINTSTRUCT *INPUT(PAINTSTRUCT ps_input) {
char *szReserved;
! int lenReserved;
! PyObject *obdc;
if (PyTuple_Check($source)) {
if (!PyArg_ParseTuple($source,
! "Ol(iiii)lls#",
! &obdc,
! &ps_input.fErase,
! &ps_input.rcPaint.left, &ps_input.rcPaint.top, &ps_input.rcPaint.right, &ps_input.rcPaint.bottom,
! &ps_input.fRestore,
! &ps_input.fIncUpdate,
! &szReserved,
! &lenReserved)) {
return NULL;
- }
if (!PyWinObject_AsHANDLE(obdc, (HANDLE *)&ps_input.hdc))
return NULL;
if (lenReserved != sizeof(ps_input.rgbReserved))
return PyErr_Format(PyExc_ValueError, "%s: last element must be string of %d bytes",
--- 563,582 ----
%typemap(python,in) PAINTSTRUCT *INPUT(PAINTSTRUCT ps_input) {
char *szReserved;
! Py_ssize_t lenReserved;
! PyObject *obdc, *obReserved;
if (PyTuple_Check($source)) {
if (!PyArg_ParseTuple($source,
! "Ol(iiii)llO",
! &obdc,
! &ps_input.fErase,
! &ps_input.rcPaint.left, &ps_input.rcPaint.top, &ps_input.rcPaint.right, &ps_input.rcPaint.bottom,
! &ps_input.fRestore,
! &ps_input.fIncUpdate,
! &obReserved))
return NULL;
if (!PyWinObject_AsHANDLE(obdc, (HANDLE *)&ps_input.hdc))
return NULL;
+ if (PyString_AsStringAndSize(obReserved, &szReserved, &lenReserved)==-1)
+ return NULL;
if (lenReserved != sizeof(ps_input.rgbReserved))
return PyErr_Format(PyExc_ValueError, "%s: last element must be string of %d bytes",
***************
*** 1534,1550 ****
{
void *addr;
! char *src;
! size_t nbytes;
! #ifdef _WIN64
! static char *input_fmt="Ls#:PySetMemory";
! #else
! static char *input_fmt="ls#:PySetMemory";
! #endif
// @pyparm int|addr||Address of the memory to reference
// @pyparm string or buffer|String||The string to copy
! if (!PyArg_ParseTuple(args, input_fmt, &addr,&src,&nbytes))
return NULL;
-
if (IsBadWritePtr(addr, nbytes)) {
PyErr_SetString(PyExc_ValueError,
--- 1535,1550 ----
{
void *addr;
! const void *src;
! PyObject *obaddr, *obsrc;
! Py_ssize_t nbytes;
// @pyparm int|addr||Address of the memory to reference
// @pyparm string or buffer|String||The string to copy
! if (!PyArg_ParseTuple(args, "OO:PySetMemory", &obaddr, &obsrc))
! return NULL;
! if (!PyWinLong_AsVoidPtr(obaddr, &addr))
! return NULL;
! if (PyObject_AsReadBuffer(obsrc, &src, &nbytes)==-1)
return NULL;
if (IsBadWritePtr(addr, nbytes)) {
PyErr_SetString(PyExc_ValueError,
***************
*** 1567,1571 ****
PyObject *ob;
int offset;
! int maxlen;
// @pyparm array|array||array object to use
--- 1567,1571 ----
PyObject *ob;
int offset;
! Py_ssize_t maxlen;
// @pyparm array|array||array object to use
***************
*** 2376,2383 ****
PyObject *PyCreateAcceleratorTable(PyObject *self, PyObject *args)
{
! Py_ssize_t num, i;
ACCEL *accels = NULL;
PyObject *ret = NULL;
! PyObject *obAccels;
HACCEL ha;
// @pyparm ( (int, int, int), ...)|accels||A sequence of (fVirt, key, cmd),
--- 2376,2383 ----
PyObject *PyCreateAcceleratorTable(PyObject *self, PyObject *args)
{
! DWORD num, i;
ACCEL *accels = NULL;
PyObject *ret = NULL;
! PyObject *obAccels, *Accels_tuple;
HACCEL ha;
// @pyparm ( (int, int, int), ...)|accels||A sequence of (fVirt, key, cmd),
***************
*** 2385,2392 ****
if (!PyArg_ParseTuple(args, "O:CreateAcceleratorTable", &obAccels))
return NULL;
! if (!PySequence_Check(obAccels))
! return PyErr_Format(PyExc_TypeError, "accels must be a sequence of tuples (got '%s')",
! obAccels->ob_type->tp_name);
! num = PySequence_Length(obAccels);
if (num==0) {
PyErr_SetString(PyExc_ValueError, "Can't create an accelerator with zero items");
--- 2385,2391 ----
if (!PyArg_ParseTuple(args, "O:CreateAcceleratorTable", &obAccels))
return NULL;
! if ((Accels_tuple=PyWinSequence_Tuple(obAccels, &num)) == NULL)
! return NULL;
!
if (num==0) {
PyErr_SetString(PyExc_ValueError, "Can't create an accelerator with zero items");
***************
*** 2400,2410 ****
for (i=0;i<num;i++) {
ACCEL *p = accels+i;
! PyObject *ob = PySequence_GetItem(obAccels, i);
! if (!ob) goto done;
! if (!PyArg_ParseTuple(ob, "BHH:ACCEL", &p->fVirt, &p->key, &p->cmd)) {
! Py_DECREF(ob);
goto done;
- }
- Py_DECREF(ob);
}
ha = ::CreateAcceleratorTable(accels, num);
--- 2399,2405 ----
for (i=0;i<num;i++) {
ACCEL *p = accels+i;
! PyObject *ob = PyTuple_GET_ITEM(Accels_tuple, i);
! if (!PyArg_ParseTuple(ob, "BHH:ACCEL", &p->fVirt, &p->key, &p->cmd))
goto done;
}
ha = ::CreateAcceleratorTable(accels, num);
***************
*** 2414,2417 ****
--- 2409,2413 ----
PyWin_SetAPIError("CreateAcceleratorTable");
done:
+ Py_DECREF(Accels_tuple);
if (accels)
free(accels);
***************
*** 2490,2500 ****
// format for the resource bits pointed to by the presbits parameter.
// This parameter can be 0x00030000.
! char *bits;
! int nBits;
int isIcon;
! int ver = 0x00030000;
! if (!PyArg_ParseTuple(args, "s#i|i", &bits, &nBits, &isIcon, &ver))
return NULL;
! HICON ret = CreateIconFromResource((PBYTE)bits, nBits, isIcon, ver);
if (!ret)
return PyWin_SetAPIError("CreateIconFromResource");
--- 2486,2499 ----
// format for the resource bits pointed to by the presbits parameter.
// This parameter can be 0x00030000.
! PBYTE bits;
! DWORD nBits;
int isIcon;
! DWORD ver = 0x00030000;
! PyObject *obbits;
! if (!PyArg_ParseTuple(args, "Oi|i", &obbits, &isIcon, &ver))
return NULL;
! if (!PyWinObject_AsReadBuffer(obbits, (void **)&bits, &nBits, FALSE))
! return NULL;
! HICON ret = CreateIconFromResource(bits, nBits, isIcon, ver);
if (!ret)
return PyWin_SetAPIError("CreateIconFromResource");
***************
*** 4314,4320 ****
*item_cnt=0;
! if ((trivertex_tuple=PySequence_Tuple(obtvs))==NULL)
return FALSE;
- *item_cnt=PyTuple_GET_SIZE(trivertex_tuple);
bufsize=*item_cnt * sizeof(TRIVERTEX);
*ptvs=(TRIVERTEX *)malloc(bufsize);
--- 4313,4318 ----
*item_cnt=0;
! if ((trivertex_tuple=PyWinSequence_Tuple(obtvs, item_cnt))==NULL)
return FALSE;
bufsize=*item_cnt * sizeof(TRIVERTEX);
*ptvs=(TRIVERTEX *)malloc(bufsize);
***************
*** 4349,4355 ****
*item_cnt=0;
! if ((mesh_tuple=PySequence_Tuple(obmesh))==NULL)
return FALSE;
- *item_cnt=PyTuple_GET_SIZE(mesh_tuple);
switch (mode){
case GRADIENT_FILL_TRIANGLE:
--- 4347,4352 ----
*item_cnt=0;
! if ((mesh_tuple=PyWinSequence_Tuple(obmesh, item_cnt))==NULL)
return FALSE;
switch (mode){
case GRADIENT_FILL_TRIANGLE:
***************
*** 4887,4893 ****
*item_cnt=0;
! if ((points_tuple=PySequence_Tuple(obpoints))==NULL)
return FALSE;
! *item_cnt=PyTuple_GET_SIZE(points_tuple);
bufsize=*item_cnt * sizeof(POINT);
*ppoints=(POINT *)malloc(bufsize);
--- 4884,4890 ----
*item_cnt=0;
! if ((points_tuple=PyWinSequence_Tuple(obpoints, item_cnt))==NULL)
return FALSE;
!
bufsize=*item_cnt * sizeof(POINT);
*ppoints=(POINT *)malloc(bufsize);
***************
*** 5124,5142 ****
static PyObject *PyExtTextOut(PyObject *self, PyObject *args)
{
! char *text;
! int strLen, x, y;
UINT options;
! PyObject *obdc, *rectObject, *widthObject = NULL;
RECT rect, *rectPtr;
int *widths = NULL;
HDC hdc;
! if (!PyArg_ParseTuple (args, "OiiiOs#|O:ExtTextOut",
! &obdc,
&x, // @pyparm x|int||The x coordinate to write the text to.
&y, // @pyparm y|int||The y coordinate to write the text to.
&options, // @pyparm nOptions|int||Specifies the rectangle type. This parameter can be one, both, or neither of ETO_CLIPPED and ETO_OPAQUE
&rectObject, // @pyparm <o PyRECT>|rect||Specifies the text's bounding rectangle. (Can be None.)
! &text, // @pyparm text|string||The text to write.
! &strLen,
&widthObject)) // @pyparm (width1, width2, ...)|tuple||Optional array of values that indicate distance between origins of character cells.
return NULL;
--- 5121,5139 ----
static PyObject *PyExtTextOut(PyObject *self, PyObject *args)
{
! TCHAR *text=NULL;
! int x, y;
! DWORD strLen;
UINT options;
! PyObject *obdc, *rectObject, *obtext, *widthObject = Py_None;
RECT rect, *rectPtr;
int *widths = NULL;
HDC hdc;
! if (!PyArg_ParseTuple (args, "OiiiOO|O:ExtTextOut",
! &obdc, // @pyparm <o PyHANDLE>|hdc||Handle to a device context
&x, // @pyparm x|int||The x coordinate to write the text to.
&y, // @pyparm y|int||The y coordinate to write the text to.
&options, // @pyparm nOptions|int||Specifies the rectangle type. This parameter can be one, both, or neither of ETO_CLIPPED and ETO_OPAQUE
&rectObject, // @pyparm <o PyRECT>|rect||Specifies the text's bounding rectangle. (Can be None.)
! &obtext, // @pyparm text|string||The text to write.
&widthObject)) // @pyparm (width1, width2, ...)|tuple||Optional array of values that indicate distance between origins of character cells.
return NULL;
***************
*** 5153,5161 ****
rectPtr = NULL;
// Parse out widths
! if (widthObject) {
BOOL error = !PyTuple_Check(widthObject);
if (!error) {
! int len = PyTuple_Size(widthObject);
if (len == (strLen - 1)) {
widths = new int[len + 1];
--- 5150,5161 ----
rectPtr = NULL;
+ if (!PyWinObject_AsTCHAR(obtext, &text, FALSE, &strLen))
+ return NULL;
+
// Parse out widths
! if (widthObject != Py_None) {
BOOL error = !PyTuple_Check(widthObject);
if (!error) {
! Py_ssize_t len = PyTuple_Size(widthObject);
if (len == (strLen - 1)) {
widths = new int[len + 1];
***************
*** 5170,5173 ****
--- 5170,5174 ----
}
if (error) {
+ PyWinObject_FreeTCHAR(text);
delete [] widths;
return PyErr_Format(PyExc_TypeError,
***************
*** 5181,5184 ****
--- 5182,5186 ----
ok = ExtTextOut(hdc, x, y, options, rectPtr, text, strLen, widths);
Py_END_ALLOW_THREADS;
+ PyWinObject_FreeTCHAR(text);
delete [] widths;
if (!ok)
***************
*** 5700,5704 ****
static char *err_msg="SCROLLINFO must be a tuple of 1-6 ints";
PyObject *obMin=Py_None, *obMax=Py_None, *obPage=Py_None, *obPos=Py_None, *obTrackPos=Py_None;
! int len = PyTuple_Size(args);
if (len<1 || len > 6) {
PyErr_SetString(PyExc_TypeError, err_msg);
--- 5702,5706 ----
static char *err_msg="SCROLLINFO must be a tuple of 1-6 ints";
PyObject *obMin=Py_None, *obMax=Py_None, *obPage=Py_None, *obPos=Py_None, *obTrackPos=Py_None;
! Py_ssize_t len = PyTuple_Size(args);
if (len<1 || len > 6) {
PyErr_SetString(PyExc_TypeError, err_msg);
***************
*** 6029,6033 ****
PyObject *obdevmode=NULL;
PyObject *obdriver, *obdevice;
! char *driver, *device, *dummyoutput=NULL;
HDC hdc;
if (!PyArg_ParseTuple(args, "OOO", &obdriver, &obdevice, &obdevmode))
--- 6031,6035 ----
PyObject *obdevmode=NULL;
PyObject *obdriver, *obdevice;
! TCHAR *driver, *device, *dummyoutput=NULL;
HDC hdc;
if (!PyArg_ParseTuple(args, "OOO", &obdriver, &obdevice, &obdevmode))
|