[pywin32-checkins] pywin32/win32/src win32apimodule.cpp,1.69,1.70
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Roger U. <ru...@us...> - 2007-02-05 07:53:09
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14723 Modified Files: win32apimodule.cpp Log Message: Add transacted registry functions More compatibility fixes Index: win32apimodule.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32apimodule.cpp,v retrieving revision 1.69 retrieving revision 1.70 diff -C2 -d -r1.69 -r1.70 *** win32apimodule.cpp 13 Jan 2007 09:35:16 -0000 1.69 --- win32apimodule.cpp 5 Feb 2007 07:53:08 -0000 1.70 *************** *** 60,63 **** --- 60,71 ---- static RegSaveKeyExfunc pfnRegSaveKeyEx=NULL; + typedef LONG (WINAPI *RegCreateKeyTransactedfunc)(HKEY,LPWSTR,DWORD,LPWSTR,DWORD, + REGSAM,LPSECURITY_ATTRIBUTES,PHKEY,LPDWORD,HANDLE,PVOID); + static RegCreateKeyTransactedfunc pfnRegCreateKeyTransacted=NULL; + typedef LONG (WINAPI *RegDeleteKeyTransactedfunc)(HKEY,LPWSTR,REGSAM,DWORD,HANDLE,PVOID); + static RegDeleteKeyTransactedfunc pfnRegDeleteKeyTransacted = NULL; + typedef LONG (WINAPI *RegOpenKeyTransactedfunc)(HKEY,LPWSTR,DWORD,REGSAM,PHKEY,HANDLE,PVOID); + static RegOpenKeyTransactedfunc pfnRegOpenKeyTransacted = NULL; + /* error helper */ *************** *** 430,434 **** PyW32_END_ALLOW_THREADS if (rc<=(HINSTANCE)32) { ! if ((int)rc==31) return ReturnError("There is no association for the file"); return ReturnAPIError("FindExecutable", (int)rc ); --- 438,442 ---- PyW32_END_ALLOW_THREADS if (rc<=(HINSTANCE)32) { ! if (rc==(HINSTANCE)31) return ReturnError("There is no association for the file"); return ReturnAPIError("FindExecutable", (int)rc ); *************** *** 1334,1349 **** PyVkKeyScanEx(PyObject * self, PyObject * args) { ! char *key; ! int len; ! long kl; ! // @pyparm chr|char||Specifies a character ! if (!PyArg_ParseTuple(args, "s#l:VkKeyScanEx", &key, &len, &kl)) return (NULL); ! if (len != 1) ! return PyErr_Format(PyExc_ValueError, "arg must be a string of length 1"); int ret; PyW32_BEGIN_ALLOW_THREADS // @pyseeapi VkKeyScanEx ! ret = VkKeyScanEx(key[0], (HKL)kl); PyW32_END_ALLOW_THREADS return PyInt_FromLong(ret); --- 1342,1358 ---- PyVkKeyScanEx(PyObject * self, PyObject * args) { ! char key; ! HKL hkl; ! PyObject *obhkl; ! if (!PyArg_ParseTuple(args, "cO:VkKeyScanEx", ! &key, // @pyparm chr|char||Specifies a character ! &obhkl)) // @pyparm <o PyHANDLE>|hkl||Handle to a keyboard layout at returned by <om win32api.LoadKeyboardLayout> return (NULL); ! if (!PyWinObject_AsHANDLE(obhkl, (HANDLE *)&hkl, FALSE)) ! return NULL; int ret; PyW32_BEGIN_ALLOW_THREADS // @pyseeapi VkKeyScanEx ! ret = VkKeyScanEx(key, hkl); PyW32_END_ALLOW_THREADS return PyInt_FromLong(ret); *************** *** 2547,2550 **** --- 2556,2607 ---- } + // @pymethod <o PyHKEY>, int|win32api|RegCreateKeyTransacted|Creates a registry key as part of a transaction + // @rdesc Returns a transacted handle and disposition flag (winnt.REG_CREATED_NEW_KEY or winnt.REG_OPENED_EXISTING_KEY) + // @pyseeapi RegCreateKeyTransacted + // @comm Accepts keyword args. + // @comm Requires Vista or later. + static PyObject *PyRegCreateKeyTransacted(PyObject *self, PyObject *args, PyObject *kwargs) + { + CHECK_PFN(RegCreateKeyTransacted); + HKEY hKey; + PyObject *obKey, *obsubKey, *obtrans, *obclass=Py_None, *obsa=Py_None, *ret=NULL; + WCHAR *subKey=NULL, *class_name=NULL; + PSECURITY_ATTRIBUTES psa; + REGSAM access; + DWORD disp, options=REG_OPTION_NON_VOLATILE, reserved=0; + PVOID extparam=NULL; // Documented as Reserved + HKEY retKey; + HANDLE htrans; + long rc; + static char *keywords[]={"Key","SubKey","samDesired","Transaction","Class","Options","SecurityAttributes", NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOkO|OkO:RegCreateKeyTransacted", keywords, + &obKey, // @pyparm <o PyHKEY>/int|Key||Registry key or one of win32con.HKEY_* values + &obsubKey, // @pyparm <o PyUnicode>|SubKey||Name of subkey to open or create. + &access, // @pyparm int|samDesired||Access allowed to handle, combination of win32con.KEY_* constants. Can also contain + // standard access rights such as DELETE, WRITE_OWNER, etc. + &obtrans, // @pyparm <o PyHANDLE>|Transaction||Handle to a transaction as returned by <om win32transaction.CreateTransaction> + &obclass, // @pyparm <o PyUnicode>|Class|None|Name of registry key class + &options, // @pyparm int|Options|REG_OPTION_NON_VOLATILE|One of the winnt.REG_OPTION_* values + &obsa)) // @pyparm <o PySECURITY_ATTRIBUTES>|SecurityAttributes|None|Specifies security for key and handle inheritance + return NULL; + if (PyWinObject_AsHKEY(obKey, &hKey) + &&PyWinObject_AsWCHAR(obsubKey, &subKey, FALSE) + &&PyWinObject_AsHANDLE(obtrans, &htrans, FALSE) + &&PyWinObject_AsWCHAR(obclass, &class_name, TRUE) + &&PyWinObject_AsSECURITY_ATTRIBUTES(obsa, &psa, TRUE)){ + rc=(*pfnRegCreateKeyTransacted)(hKey, subKey, reserved, class_name, options, + access, psa, &retKey, &disp, htrans, extparam); + if (rc!=ERROR_SUCCESS) + PyWin_SetAPIError("RegCreateKeyTransacted", rc); + else + ret=Py_BuildValue("Nk", PyWinObject_FromHKEY(retKey), disp); + } + + PyWinObject_FreeWCHAR(subKey); + PyWinObject_FreeWCHAR(class_name); + return ret; + } + // @pymethod |win32api|RegDeleteKey|Deletes the specified key. This method can not delete keys with subkeys. static PyObject * *************** *** 2572,2575 **** --- 2629,2671 ---- // If the method fails, and exception is raised. } + + // @pymethod |win32api|RegDeleteKeyTransacted|Deletes a registry key as part of a transaction + // @comm Accepts keyword args. + // @comm Requires Vista or later. + // @comm Key to be deleted cannot contain subkeys + static PyObject *PyRegDeleteKeyTransacted(PyObject *self, PyObject *args, PyObject *kwargs) + { + CHECK_PFN(RegDeleteKeyTransacted); + HKEY hKey; + PyObject *obKey, *obsubKey, *obtrans, *ret=NULL; + PVOID extparam=NULL; // Reserved, ignore for now + WCHAR *subKey=NULL, *class_name=NULL; + REGSAM access=0; + DWORD reserved=0; + HANDLE htrans; + long rc; + static char *keywords[]={"Key","SubKey","Transaction","samDesired", NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOO|k:RegDeleteKeyTransacted", keywords, + &obKey, // @pyparm <o PyHKEY>/int|Key||Registry key or one of win32con.HKEY_* values + &obsubKey, // @pyparm <o PyUnicode>|SubKey||Name of subkey to be deleted. + &obtrans, // @pyparm <o PyHANDLE>|Transaction||Handle to a transaction as returned by <om win32transaction.CreateTransaction> + &access)) // @pyparm int|samDesired|0|Can be KEY_WOW64_32KEY or KEY_WOW64_64KEY to specify alternate registry view + return NULL; + if (PyWinObject_AsHKEY(obKey, &hKey) + &&PyWinObject_AsWCHAR(obsubKey, &subKey, FALSE) + &&PyWinObject_AsHANDLE(obtrans, &htrans, FALSE)){ + rc=(*pfnRegDeleteKeyTransacted)(hKey, subKey, access, reserved, htrans, extparam); + if (rc!=ERROR_SUCCESS) + PyWin_SetAPIError("RegDeleteKeyTransacted", rc); + else{ + Py_INCREF(Py_None); + ret=Py_None; + } + } + PyWinObject_FreeWCHAR(subKey); + return ret; + } + // @pymethod |win32api|RegDeleteValue|Removes a named value from the specified registry key. static PyObject * *************** *** 3168,3171 **** --- 3264,3307 ---- } + // @pymethod <o PyHKEY>|win32api|RegOpenKeyTransacted|Opens a registry key as part of a transaction + // @rdesc Returns a transacted registry handle. Note that operations on subkeys are not automatically transacted. + // @pyseeapi RegOpenKeyTransacted + // @comm Accepts keyword arguments. + // @comm Requires Vista or later. + static PyObject *PyRegOpenKeyTransacted(PyObject *self, PyObject *args, PyObject *kwargs) + { + CHECK_PFN(RegOpenKeyTransacted); + HKEY hKey; + PyObject *obKey, *obsubKey, *obtrans, *ret=NULL; + WCHAR *subKey=NULL; + REGSAM access; + DWORD options=0; // Reserved + PVOID extparam=NULL; // Reserved, not accepted as arg for now + HKEY retKey; + HANDLE htrans; + long rc; + static char *keywords[]={"Key","SubKey","samDesired","Transaction","Options", NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOkO|k:RegOpenKeyTransacted", keywords, + &obKey, // @pyparm <o PyHKEY>/int|Key||Registry key or one of win32con.HKEY_* values + &obsubKey, // @pyparm <o PyUnicode>|SubKey||Name of subkey to open. Can be None to reopen an existing key. + &access, // @pyparm int|samDesired||Access allowed to handle, combination of win32con.KEY_* constants. Can also contain + // standard access rights such as DELETE, WRITE_OWNER, etc. + &obtrans, // @pyparm <o PyHANDLE>|Transaction||Handle to a transaction as returned by <om win32transaction.CreateTransaction> + &options)) // @pyparm int|Options|0|Reserved, use only 0 + return NULL; + if (PyWinObject_AsHKEY(obKey, &hKey) + &&PyWinObject_AsWCHAR(obsubKey, &subKey, TRUE) + &&PyWinObject_AsHANDLE(obtrans, &htrans, FALSE)){ + rc=(*pfnRegOpenKeyTransacted)(hKey, subKey, options, access, &retKey, htrans, extparam); + if (rc!=ERROR_SUCCESS) + PyWin_SetAPIError("RegOpenKeyTransacted", rc); + else + ret=PyWinObject_FromHKEY(retKey); + } + PyWinObject_FreeWCHAR(subKey); + return ret; + } + // @pymethod (int, int, long)|win32api|RegQueryInfoKey|Returns the number of // subkeys, the number of values a key has, *************** *** 3787,3791 **** return ReturnAPIError("ShellExecute", (int)rc ); } ! return Py_BuildValue("i", rc ); // @rdesc The instance handle of the application that was run. (This handle could also be the handle of a dynamic data exchange [DDE] server application.) // If there is an error, the method raises an exception. --- 3923,3927 ---- return ReturnAPIError("ShellExecute", (int)rc ); } ! return PyLong_FromVoidPtr(rc); // @rdesc The instance handle of the application that was run. (This handle could also be the handle of a dynamic data exchange [DDE] server application.) // If there is an error, the method raises an exception. *************** *** 3838,3842 **** UINT cmd; PyObject *dataOb = Py_None; ! DWORD data; if (!PyArg_ParseTuple(args, "Osi|O:WinHelp", &obhwnd, // @pyparm int|hwnd||The handle of the window requesting help. --- 3974,3978 ---- UINT cmd; PyObject *dataOb = Py_None; ! ULONG_PTR data; if (!PyArg_ParseTuple(args, "Osi|O:WinHelp", &obhwnd, // @pyparm int|hwnd||The handle of the window requesting help. *************** *** 3850,3860 **** data = 0; else if (PyString_Check(dataOb)) ! data = (DWORD)PyString_AsString(dataOb); ! else if (PyInt_Check(dataOb)) ! data = (DWORD)PyInt_AsLong(dataOb); ! else { ! PyErr_SetString(PyExc_TypeError, "4th argument must be a None, string or an integer."); ! return NULL; ! } PyW32_BEGIN_ALLOW_THREADS --- 3986,3997 ---- data = 0; else if (PyString_Check(dataOb)) ! data = (ULONG_PTR)PyString_AsString(dataOb); ! else{ ! data = (ULONG_PTR)PyLong_AsVoidPtr(dataOb); ! if (data==NULL && PyErr_Occurred()){ ! PyErr_SetString(PyExc_TypeError, "4th argument must be a None, string or an integer."); ! return NULL; ! } ! } PyW32_BEGIN_ALLOW_THREADS *************** *** 4604,4612 **** // @rdesc The result is a list of string or integers, one for each resource enumerated. PyObject *result = PyList_New(0); EnumResourceNames( hmodule, restype, reinterpret_cast<ENUMRESNAMEPROC>(EnumResProc), ! reinterpret_cast<LONG>(result)); return result; --- 4741,4751 ---- // @rdesc The result is a list of string or integers, one for each resource enumerated. PyObject *result = PyList_New(0); + if (result==NULL) + return NULL; EnumResourceNames( hmodule, restype, reinterpret_cast<ENUMRESNAMEPROC>(EnumResProc), ! reinterpret_cast<LONG_PTR>(result)); return result; *************** *** 4641,4645 **** if(!EnumResourceTypesW(hmodule, reinterpret_cast<ENUMRESTYPEPROCW>(EnumResourceTypesProc), ! reinterpret_cast<LONG>(ret))){ Py_DECREF(ret); ret=NULL; --- 4780,4784 ---- if(!EnumResourceTypesW(hmodule, reinterpret_cast<ENUMRESTYPEPROCW>(EnumResourceTypesProc), ! reinterpret_cast<LONG_PTR>(ret))){ Py_DECREF(ret); ret=NULL; *************** *** 4682,4686 **** resname, reinterpret_cast<ENUMRESLANGPROCW>(EnumResourceLanguagesProc), ! reinterpret_cast<LONG>(ret))){ Py_DECREF(ret); ret=NULL; --- 4821,4825 ---- resname, reinterpret_cast<ENUMRESLANGPROCW>(EnumResourceLanguagesProc), ! reinterpret_cast<LONG_PTR>(ret))){ Py_DECREF(ret); ret=NULL; *************** *** 5164,5168 **** if (ret!=NULL){ for (int tuple_ind=0;tuple_ind<buflen;tuple_ind++){ ! PyObject *tuple_item=PyLong_FromLong((long)buf[tuple_ind]); if (tuple_item==NULL){ Py_DECREF(ret); --- 5303,5307 ---- if (ret!=NULL){ for (int tuple_ind=0;tuple_ind<buflen;tuple_ind++){ ! PyObject *tuple_item=PyWinLong_FromHANDLE(buf[tuple_ind]); if (tuple_item==NULL){ Py_DECREF(ret); *************** *** 5192,5196 **** if (lcid==NULL) return PyWin_SetAPIError("LoadKeyboardLayout"); ! return PyLong_FromLong((long)lcid); } --- 5331,5335 ---- if (lcid==NULL) return PyWin_SetAPIError("LoadKeyboardLayout"); ! return PyWinLong_FromHANDLE(lcid); } *************** *** 5374,5378 **** --- 5513,5519 ---- {"RegCreateKey", PyRegCreateKey, 1}, // @pymeth RegCreateKey|Creates the specified key, or opens the key if it already exists. {"RegCreateKeyEx", (PyCFunction)PyRegCreateKeyEx, METH_KEYWORDS|METH_VARARGS}, // @pymeth RegCreateKeyEx|Extended version of RegCreateKey + {"RegCreateKeyTransacted",(PyCFunction)PyRegCreateKeyTransacted, METH_KEYWORDS|METH_VARARGS}, // @pymeth RegCreateKeyTransacted|Creates a registry key as part of a transaction {"RegDeleteKey", PyRegDeleteKey, 1}, // @pymeth RegDeleteKey|Deletes the specified key. + {"RegDeleteKeyTransacted",(PyCFunction)PyRegDeleteKeyTransacted, METH_KEYWORDS|METH_VARARGS}, // @pymeth RegDeleteKeyTransacted|Deletes a registry key as part of a transaction {"RegDeleteValue", PyRegDeleteValue, 1}, // @pymeth RegDeleteValue|Removes a named value from the specified registry key. {"RegEnumKey", PyRegEnumKey, 1}, // @pymeth RegEnumKey|Enumerates subkeys of the specified open registry key. *************** *** 5385,5388 **** --- 5526,5530 ---- {"RegOpenKey", PyRegOpenKey, 1}, // @pymeth RegOpenKey|Alias for <om win32api.RegOpenKeyEx> {"RegOpenKeyEx", PyRegOpenKey, 1}, // @pymeth RegOpenKeyEx|Opens the specified key. + {"RegOpenKeyTransacted",(PyCFunction)PyRegOpenKeyTransacted, METH_KEYWORDS|METH_VARARGS}, // @pymeth RegOpenKeyTransacted|Opens a registry key as part of a transaction. {"RegQueryValue", PyRegQueryValue, 1}, // @pymeth RegQueryValue|Retrieves the value associated with the unnamed value for a specified key in the registry. {"RegQueryValueEx", PyRegQueryValueEx, 1}, // @pymeth RegQueryValueEx|Retrieves the type and data for a specified value name associated with an open registry key. *************** *** 5548,5551 **** --- 5690,5696 ---- pfnRegRestoreKey=(RegRestoreKeyfunc)GetProcAddress(hmodule, "RegRestoreKeyW"); pfnRegSaveKeyEx=(RegSaveKeyExfunc)GetProcAddress(hmodule, "RegSaveKeyExW"); + pfnRegCreateKeyTransacted=(RegCreateKeyTransactedfunc)GetProcAddress(hmodule, "RegCreateKeyTransactedW"); + pfnRegOpenKeyTransacted=(RegOpenKeyTransactedfunc)GetProcAddress(hmodule, "RegOpenKeyTransactedW"); + pfnRegDeleteKeyTransacted=(RegDeleteKeyTransactedfunc)GetProcAddress(hmodule, "RegDeleteKeyTransactedW"); } |