|
| 1 | +#define PY_SSIZE_T_CLEAN |
| 2 | +#include <Python.h> |
| 3 | +#ifdef _WIN32 |
| 4 | +#include <Objbase.h> |
| 5 | +#include <Shobjidl.h> |
| 6 | +#endif |
| 7 | + |
| 8 | +static PyObject* mpl_GetCurrentProcessExplicitAppUserModelID(PyObject* module) |
| 9 | +{ |
| 10 | +#ifdef _WIN32 |
| 11 | + wchar_t* appid = NULL; |
| 12 | + HRESULT hr = GetCurrentProcessExplicitAppUserModelID(&appid); |
| 13 | + if (FAILED(hr)) { |
| 14 | + return PyErr_SetFromWindowsErr(hr); |
| 15 | + } |
| 16 | + PyObject* py_appid = PyUnicode_FromWideChar(appid, -1); |
| 17 | + CoTaskMemFree(appid); |
| 18 | + return py_appid; |
| 19 | +#else |
| 20 | + Py_RETURN_NONE; |
| 21 | +#endif |
| 22 | +} |
| 23 | + |
| 24 | +static PyObject* mpl_SetCurrentProcessExplicitAppUserModelID(PyObject* module, PyObject* arg) |
| 25 | +{ |
| 26 | +#ifdef _WIN32 |
| 27 | + wchar_t* appid = PyUnicode_AsWideCharString(arg, NULL); |
| 28 | + if (!appid) { |
| 29 | + return NULL; |
| 30 | + } |
| 31 | + HRESULT hr = SetCurrentProcessExplicitAppUserModelID(appid); |
| 32 | + PyMem_Free(appid); |
| 33 | + if (FAILED(hr)) { |
| 34 | + return PyErr_SetFromWindowsErr(hr); |
| 35 | + } |
| 36 | + Py_RETURN_NONE; |
| 37 | +#else |
| 38 | + Py_RETURN_NONE; |
| 39 | +#endif |
| 40 | +} |
| 41 | + |
| 42 | +static PyMethodDef functions[] = { |
| 43 | + {"Win32_GetCurrentProcessExplicitAppUserModelID", |
| 44 | + (PyCFunction)mpl_GetCurrentProcessExplicitAppUserModelID, METH_NOARGS, |
| 45 | + "Win32_GetCurrentProcessExplicitAppUserModelID()\n--\n\n" |
| 46 | + "Wrapper for Windows's GetCurrentProcessExplicitAppUserModelID. On \n" |
| 47 | + "non-Windows platforms, always returns None."}, |
| 48 | + {"Win32_SetCurrentProcessExplicitAppUserModelID", |
| 49 | + (PyCFunction)mpl_SetCurrentProcessExplicitAppUserModelID, METH_O, |
| 50 | + "Win32_SetCurrentProcessExplicitAppUserModelID(appid, /)\n--\n\n" |
| 51 | + "Wrapper for Windows's SetCurrentProcessExplicitAppUserModelID. On \n" |
| 52 | + "non-Windows platforms, a no-op."}, |
| 53 | + {NULL, NULL}}; // sentinel. |
| 54 | +static PyModuleDef util_module = { |
| 55 | + PyModuleDef_HEAD_INIT, "_c_internal_utils", "", 0, functions, NULL, NULL, NULL, NULL}; |
| 56 | + |
| 57 | +#pragma GCC visibility push(default) |
| 58 | +PyMODINIT_FUNC PyInit__c_internal_utils(void) |
| 59 | +{ |
| 60 | + return PyModule_Create(&util_module); |
| 61 | +} |
0 commit comments