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

instdev.c File Reference

#include "precomp.h"
#include "ntuser.h"
#include "dbt.h"
#include "pnpmgr.h"

Go to the source code of this file.

Functions

ULONG SrvDeviceEvent (IN OUT PCSR_API_MSG m, IN OUT PCSR_REPLY_STATUS ReplyStatus)


Function Documentation

ULONG SrvDeviceEvent IN OUT PCSR_API_MSG  m,
IN OUT PCSR_REPLY_STATUS  ReplyStatus
 

Definition at line 37 of file instdev.c.

References _DEVICEEVENTMSG::dwFlags, _DEVICEEVENTMSG::dwResult, EXCEPTION_EXECUTE_HANDLER, _DEVICEEVENTMSG::hWnd, IsWindow(), _DEVICEEVENTMSG::lParam, NT_SUCCESS, NTSTATUS(), NtUserSetInformationThread(), NULL, PostMessage(), SendMessageTimeout(), Status, and _DEVICEEVENTMSG::wParam.

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:44:13 2004 for test by doxygen 1.3.7