sendmsg.c
Upload User: caisha3
Upload Date: 2013-09-21
Package Size: 208739k
Code Size: 3k
Category:

Windows Develop

Development Platform:

Visual C++

  1. /*************************************************************************
  2. *
  3. * sendmsg.c
  4. *
  5. * Copyright (c) 1985 - 1999, Microsoft Corporation
  6. *
  7. * Terminal Server (Hydra) specific code
  8. *
  9. * Processend message to winstation
  10. *
  11. * $Author:  Ara bernardi
  12. *
  13. *************************************************************************/
  14. //
  15. // Includes
  16. //
  17. #include "precomp.h"
  18. #pragma hdrstop
  19. #include "dbt.h"
  20. #include "ntdddisk.h"
  21. #include "ntuser.h"
  22. #include <winsta.h>
  23. #include <wstmsg.h>
  24. #include <winuser.h>
  25. //
  26. // Global variables
  27. //
  28. #if DBG
  29. void DumpOutLastErrorString()
  30. {
  31.     LPVOID  lpMsgBuf;
  32.     DWORD   error = GetLastError();
  33.     DBGHYD(("GetLastError() = 0x%lx n", error ));
  34.     FormatMessage(
  35.             FORMAT_MESSAGE_ALLOCATE_BUFFER |
  36.             FORMAT_MESSAGE_FROM_SYSTEM |
  37.             FORMAT_MESSAGE_IGNORE_INSERTS,
  38.             NULL,
  39.             error,
  40.             MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  41.             (LPTSTR) &lpMsgBuf,
  42.             0,
  43.             NULL
  44.         );
  45.         //
  46.         // Process any inserts in lpMsgBuf.
  47.         // ...
  48.         // Display the string.
  49.         //
  50.         DBGHYD(("%sn", (LPCTSTR)lpMsgBuf ));
  51.         //
  52.         // Free the buffer.
  53.         //
  54.         LocalFree( lpMsgBuf );
  55. }
  56. #endif
  57. #if DBG
  58. #define DumpOutLastError    DumpOutLastErrorString()
  59. #else
  60. #define DumpOutLastError
  61. #endif
  62. /*******************************************************************************
  63.  *
  64.  *  RemoteDoBrroadcastSystemMessage
  65.  *
  66.  * ENTRY:
  67.  *
  68.  * EXIT:
  69.  *    STATUS_SUCCESS - successful
  70.  *
  71.  ******************************************************************************/
  72. NTSTATUS
  73. RemoteDoBroadcastSystemMessage(
  74.     PWINSTATION_APIMSG pMsg)
  75. {
  76.     LONG rc;
  77.     WINSTATIONBROADCASTSYSTEMMSG     *pmsg;
  78.     LPARAM      tmpLPARAM;
  79.     NTSTATUS    status;
  80.     pmsg = &(pMsg->u.bMsg);
  81.     if ( pmsg->bufferSize )
  82.     {
  83.         // we have a databuffer, set the lParam to our copied data buffer
  84.         tmpLPARAM = (LPARAM)pmsg->dataBuffer;
  85.     }
  86.     else
  87.     {
  88.         tmpLPARAM = pmsg->lParam ;
  89.     }
  90.     rc = BroadcastSystemMessage( pmsg->dwFlags, &pmsg->dwRecipients,
  91.                     pmsg->uiMessage, pmsg->wParam, tmpLPARAM );
  92.     status = STATUS_SUCCESS;
  93.     pmsg->Response = rc;
  94.     return status ;
  95. }
  96. NTSTATUS
  97. RemoteDoSendWindowMessage(
  98.     PWINSTATION_APIMSG pMsg)
  99. {
  100.     LONG rc;
  101.     NTSTATUS status;
  102.     WINSTATIONSENDWINDOWMSG  *pmsg;
  103.     LPARAM  tmpLPARAM;
  104.     pmsg = &(pMsg->u.sMsg);
  105.     if ( pmsg->bufferSize )
  106.     {
  107.         // we have a databuffer, set the lParam to our copied data buffer
  108.         tmpLPARAM = (LPARAM)pmsg->dataBuffer;
  109.     }
  110.     else
  111.     {
  112.         tmpLPARAM = (LPARAM)pmsg->lParam;
  113.     }
  114.     //
  115.     // No need to worry about disconnected sessions (desktop), since msg is sent to a specific hwnd.
  116.     // I have verified this imperically.
  117.     //
  118.     rc = (LONG)SendMessage( pmsg->hWnd, pmsg->Msg,
  119.                     pmsg->wParam, tmpLPARAM  );
  120.     status = STATUS_SUCCESS;
  121.     pmsg->Response = rc;
  122.     return status ;
  123. }