@@ -2985,17 +2985,18 @@ _winapi.RegisterEventSource -> HANDLE
29852985 If NULL, registers the event source on the local computer.
29862986 source_name: LPCWSTR
29872987 The name of the event source to register.
2988+ /
29882989[clinic start generated code]*/
29892990
29902991static HANDLE
29912992_winapi_RegisterEventSource_impl (PyObject * module , LPCWSTR unc_server_name ,
29922993 LPCWSTR source_name )
2993- /*[clinic end generated code: output=e376c8950a89ae8f input=ee83ab132b89b99c ]*/
2994+ /*[clinic end generated code: output=e376c8950a89ae8f input=16ae3c812a905cab ]*/
29942995{
29952996 HANDLE handle ;
29962997
29972998 Py_BEGIN_ALLOW_THREADS
2998- handle = RegisterEventSource (unc_server_name , source_name );
2999+ handle = RegisterEventSourceW (unc_server_name , source_name );
29993000 Py_END_ALLOW_THREADS
30003001
30013002 if (handle == NULL) {
@@ -3011,11 +3012,12 @@ _winapi.DeregisterEventSource
30113012
30123013 handle: HANDLE
30133014 The handle to the event log to be deregistered.
3015+ /
30143016[clinic start generated code]*/
30153017
30163018static PyObject *
30173019_winapi_DeregisterEventSource_impl (PyObject * module , HANDLE handle )
3018- /*[clinic end generated code: output=7387ff34c7358bce input=07d42083b03ba7b0 ]*/
3020+ /*[clinic end generated code: output=7387ff34c7358bce input=0973c68eddcfd5a7 ]*/
30193021{
30203022 BOOL success ;
30213023
@@ -3029,6 +3031,92 @@ _winapi_DeregisterEventSource_impl(PyObject *module, HANDLE handle)
30293031 Py_RETURN_NONE ;
30303032}
30313033
3034+ /*[clinic input]
3035+ _winapi.ReportEvent
3036+
3037+ handle: HANDLE
3038+ The handle to the event log.
3039+ event_type: int
3040+ The type of event being reported.
3041+ event_category: int
3042+ The event category.
3043+ event_id: int
3044+ The event identifier.
3045+ strings: object(subclass_of='&PyList_Type')
3046+ A list of strings to be inserted into the event message.
3047+ raw_data: Py_buffer
3048+ The raw data for the event.
3049+ [clinic start generated code]*/
3050+
3051+ static PyObject *
3052+ _winapi_ReportEvent_impl (PyObject * module , HANDLE handle , int event_type ,
3053+ int event_category , int event_id , PyObject * strings ,
3054+ Py_buffer * raw_data )
3055+ /*[clinic end generated code: output=9066f114cdfdf5f2 input=fc37cfe1816d02d7]*/
3056+ {
3057+ BOOL success ;
3058+ LPCWSTR * string_array = NULL ;
3059+ WORD num_strings = 0 ;
3060+ LPVOID data = NULL ;
3061+ DWORD data_size = 0 ;
3062+
3063+ // Handle strings list
3064+ if (strings != Py_None && PyList_Check (strings )) {
3065+ Py_ssize_t size = PyList_Size (strings );
3066+ num_strings = (WORD )size ;
3067+
3068+ if (num_strings > 0 ) {
3069+ string_array = (LPCWSTR * )PyMem_Malloc (num_strings * sizeof (LPCWSTR ));
3070+ if (!string_array ) {
3071+ return PyErr_NoMemory ();
3072+ }
3073+
3074+ for (WORD i = 0 ; i < num_strings ; i ++ ) {
3075+ PyObject * item = PyList_GetItem (strings , i );
3076+ if (!PyUnicode_Check (item )) {
3077+ PyMem_Free (string_array );
3078+ PyErr_SetString (PyExc_TypeError , "All strings must be unicode" );
3079+ return NULL ;
3080+ }
3081+ string_array [i ] = PyUnicode_AsWideCharString (item , NULL );
3082+ if (!string_array [i ]) {
3083+ // Clean up already allocated strings
3084+ for (WORD j = 0 ; j < i ; j ++ ) {
3085+ PyMem_Free ((void * )string_array [j ]);
3086+ }
3087+ PyMem_Free (string_array );
3088+ return NULL ;
3089+ }
3090+ }
3091+ }
3092+ }
3093+
3094+ // Handle raw data
3095+ if (raw_data -> buf != NULL ) {
3096+ data = raw_data -> buf ;
3097+ data_size = (DWORD ) raw_data -> len ;
3098+ }
3099+
3100+ Py_BEGIN_ALLOW_THREADS
3101+ success = ReportEventW (handle , event_type , event_category , event_id ,
3102+ NULL , num_strings , data_size ,
3103+ string_array , data );
3104+ Py_END_ALLOW_THREADS
3105+
3106+ // Clean up allocated strings
3107+ if (string_array ) {
3108+ for (WORD i = 0 ; i < num_strings ; i ++ ) {
3109+ PyMem_Free ((void * )string_array [i ]);
3110+ }
3111+ PyMem_Free (string_array );
3112+ }
3113+
3114+ if (!success )
3115+ return PyErr_SetFromWindowsErr (0 );
3116+
3117+ Py_RETURN_NONE ;
3118+ }
3119+
30323120
30333121static PyMethodDef winapi_functions [] = {
30343122 _WINAPI_CLOSEHANDLE_METHODDEF
@@ -3059,6 +3147,7 @@ static PyMethodDef winapi_functions[] = {
30593147 _WINAPI_OPENPROCESS_METHODDEF
30603148 _WINAPI_PEEKNAMEDPIPE_METHODDEF
30613149 _WINAPI_REGISTEREVENTSOURCE_METHODDEF
3150+ _WINAPI_REPORTEVENT_METHODDEF
30623151 _WINAPI_LCMAPSTRINGEX_METHODDEF
30633152 _WINAPI_READFILE_METHODDEF
30643153 _WINAPI_RELEASEMUTEX_METHODDEF
0 commit comments