@@ -2784,6 +2784,43 @@ _Py_set_blocking(int fd, int blocking)
27842784 return -1 ;
27852785}
27862786#else /* MS_WINDOWS */
2787+
2788+ // The Windows Games API family doesn't expose GetNamedPipeHandleStateW so attempt
2789+ // to load it directly from the Kernel32.dll
2790+ #if !defined(MS_WINDOWS_APP ) && !defined(MS_WINDOWS_SYSTEM )
2791+ BOOL
2792+ GetNamedPipeHandleStateW (HANDLE hNamedPipe , LPDWORD lpState , LPDWORD lpCurInstances , LPDWORD lpMaxCollectionCount ,
2793+ LPDWORD lpCollectDataTimeout , LPWSTR lpUserName , DWORD nMaxUserNameSize )
2794+ {
2795+ static int initialized = 0 ;
2796+ typedef BOOL (__stdcall* PGetNamedPipeHandleStateW ) (
2797+ HANDLE hNamedPipe , LPDWORD lpState , LPDWORD lpCurInstances , LPDWORD lpMaxCollectionCount ,
2798+ LPDWORD lpCollectDataTimeout , LPWSTR lpUserName , DWORD nMaxUserNameSize );
2799+ static PGetNamedPipeHandleStateW _GetNamedPipeHandleStateW ;
2800+
2801+ if (initialized == 0 ) {
2802+ HMODULE api = LoadLibraryExW (L"Kernel32.dll" , NULL , LOAD_LIBRARY_SEARCH_SYSTEM32 );
2803+ if (api ) {
2804+ _GetNamedPipeHandleStateW = (PGetNamedPipeHandleStateW )GetProcAddress (
2805+ api , "GetNamedPipeHandleStateW" );
2806+ }
2807+ else {
2808+ _GetNamedPipeHandleStateW = NULL ;
2809+ }
2810+ initialized = 1 ;
2811+ }
2812+
2813+ if (!_GetNamedPipeHandleStateW ) {
2814+ SetLastError (E_NOINTERFACE );
2815+ return FALSE;
2816+ }
2817+
2818+ return _GetNamedPipeHandleStateW (
2819+ hNamedPipe , lpState , lpCurInstances , lpMaxCollectionCount , lpCollectDataTimeout , lpUserName , nMaxUserNameSize
2820+ );
2821+ }
2822+ #endif /* !MS_WINDOWS_APP && !MS_WINDOWS_SYSTEM */
2823+
27872824int
27882825_Py_get_blocking (int fd )
27892826{
0 commit comments