presponse参数WTSSendMessage

时间:2012-05-17 12:09:29

标签: c winapi service windows-services

我参与编写服务,我想在“服务停止请求”上显示一个消息框。

我尝试使用“WTSSendmessage”API ..但是没有显示消息框。 我的另一个疑问是WTSSendmessage中“Presponse”参数的输入应该是什么。

有没有例子?

1 个答案:

答案 0 :(得分:1)

Presponse是指向接收用户响应的变量的指针。表示用户按下的按钮。

    typedef BOOL (*TypeSendMessage) ( HANDLE,DWORD,LPWSTR,DWORD, LPWSTR, DWORD, DWORD,DWORD, DWORD*, BOOL);

   TypeSendMessage SendMessage;
   HMODULE hModule = LoadLibrary(L"Wtsapi32.dll");

 if(hModule)
 {
   ////////////////// WTSSendMessage ////////////////
   SendMessage = (TypeSendMessage) GetProcAddres(hModule,
                 "WTSSendMessageW");
   if(!SendMessage) 
          return FALSE;

   DWORD res;
   SendMessage( WTS_CURRENT_SERVER_HANDLE,
               WTSGetActiveConsoleSessionId(), (LPWSTR)L"Title", 5*2,
               (LPWSTR)L"Sample Message",14*2, MB_ICONERROR| MB_TOPMOST|MB_SETFOREGROUND,
               FALSE,    &res,  0);
 }