Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

instdev.c

Go to the documentation of this file.
00001 00002 /**************************************************************************\ 00003 * Module Name: instdev.c 00004 * 00005 * Server device handling routine for the CSR stuff. 00006 * 00007 * Copyright (c) 1985 - 1999, Microsoft Corporation 00008 * 00009 * Created: 13-Mar-97 00010 * 00011 * History: 00012 * 13-Mar-97 created by PaulaT 00013 * 00014 \**************************************************************************/ 00015 00016 00017 #include "precomp.h" 00018 #pragma hdrstop 00019 00020 #include "ntuser.h" 00021 #include "dbt.h" 00022 #include "pnpmgr.h" 00023 00024 00025 /**************************************************************************\ 00026 * SrvDeviceEvent 00027 * 00028 * User-mode pnp manager (in services.exe) has a message to deliver to an 00029 * app that has registered for this notification but services.exe isn't 00030 * in WinSta0\Default so we need a csr thread to simply send the message. 00031 * 00032 * PaulaT 06/04/97 00033 * 00034 \**************************************************************************/ 00035 00036 ULONG 00037 SrvDeviceEvent( 00038 IN OUT PCSR_API_MSG m, 00039 IN OUT PCSR_REPLY_STATUS ReplyStatus) 00040 { 00041 NTSTATUS Status = STATUS_SUCCESS; 00042 PDEVICEEVENTMSG a = (PDEVICEEVENTMSG)&m->u.ApiMessageData; 00043 USERTHREAD_USEDESKTOPINFO utudi; 00044 00045 UNREFERENCED_PARAMETER(ReplyStatus); 00046 00047 try { 00048 00049 // 00050 // Set the desktop to the active desktop before sending the 00051 // message. 00052 // 00053 00054 utudi.hThread = NULL; 00055 utudi.drdRestore.pdeskRestore = NULL; 00056 Status = NtUserSetInformationThread(NtCurrentThread(), 00057 UserThreadUseActiveDesktop, 00058 &utudi, sizeof(utudi)); 00059 if (!NT_SUCCESS(Status)) { 00060 #if DBG 00061 KdPrint(("--> SrvDeviceEvent: NtUserSetInformationThread failed %d\n", Status)); 00062 #endif 00063 goto Clean1; 00064 } 00065 00066 // 00067 // Verify the window handle is still valid, if not, let the caller know 00068 // so it can be purged from the notification window hand list that the 00069 // user-mode pnp manager keeps. 00070 // 00071 00072 if ((a->hWnd != HWND_BROADCAST) && !IsWindow(a->hWnd)) { 00073 Status = STATUS_INVALID_HANDLE; 00074 goto Clean0; 00075 } 00076 00077 if (a->dwFlags) { 00078 00079 // 00080 // This is a query so we have to send the message but use 00081 // timeouts so an app can't stall us forever. 00082 // 00083 00084 RIPMSG3(RIP_VERBOSE, "--> SrvDeviceEvent: Sending WM_DEVICECHANGE to 0x%x, w 0x%x, l 0x%x", 00085 (ULONG_PTR)a->hWnd, 00086 a->wParam, 00087 a->lParam); 00088 00089 if (!SendMessageTimeout(a->hWnd, WM_DEVICECHANGE, a->wParam, a->lParam, 00090 SMTO_ABORTIFHUNG | SMTO_NORMAL, 00091 PNP_NOTIFY_TIMEOUT, &a->dwResult)) { 00092 Status = STATUS_UNSUCCESSFUL; 00093 } 00094 00095 } else { 00096 00097 // 00098 // It's not a query so just post it and return, we don't 00099 // care what the app returns. 00100 // 00101 00102 RIPMSG3(RIP_VERBOSE, "--> SrvDeviceEvent: Posting WM_DEVICECHANGE to 0x%x, w 0x%x, l 0x%x", 00103 (ULONG_PTR)a->hWnd, 00104 a->wParam, 00105 a->lParam); 00106 00107 if (!PostMessage(a->hWnd, WM_DEVICECHANGE, a->wParam, a->lParam)) { 00108 Status = STATUS_UNSUCCESSFUL; 00109 } 00110 } 00111 00112 Clean0: 00113 00114 // 00115 // Reset this thread's desktop back to NULL before returning. This 00116 // decrements the desktop's reference count. 00117 // 00118 00119 NtUserSetInformationThread(NtCurrentThread(), 00120 UserThreadUseDesktop, 00121 &utudi, sizeof(utudi)); 00122 00123 Clean1: 00124 ; 00125 00126 } except (EXCEPTION_EXECUTE_HANDLER) { 00127 KdPrint(("SrvDeviceEvent generated an exception (%d)\n", GetExceptionCode())); 00128 Status = STATUS_UNSUCCESSFUL; 00129 } 00130 00131 return Status; 00132 00133 } // SrvDeviceEvent

Generated on Sat May 15 19:40:24 2004 for test by doxygen 1.3.7