Board index » cppbuilder » SendMessage() to the service app
Vladimir Stefanovic
![]() CBuilder Developer |
Vladimir Stefanovic
![]() CBuilder Developer |
SendMessage() to the service app2004-07-26 09:41:11 PM cppbuilder9 Hi, Is it possible to send a custom message via SendMessage() mechanism from the 'Desktop App' to the 'Service App', which both resides on the same PC? I need this just to inform the 'Service App', for example, to reload the configuration because it's changed by the 'Desktop App'. I know that I can use sockets for this but I think it's too robust solution (defining IP and port) for sending just one RELOAD command. Best regards, Vladimir Stefanovic |
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2004-07-27 02:24:19 AM
Re:SendMessage() to the service app
"Vladimir Stefanovic" < XXXX@XXXXX.COM >wrote in message
QuoteIs it possible to send a custom message via SendMessage() ControlService() can send custom SCM messages to a service. Then, the in the service itself, you can override the virtual DoCustomControl() method in order to respond to custom messages. Gambit |
Vladimir Stefanovic
![]() CBuilder Developer |
2004-07-27 02:32:59 AM
Re:SendMessage() to the service app
Thanks,
I have now enough 'material' to start... Quote>Is it possible to send a custom message via SendMessage() {smallsort} |
Vladimir Stefanovic
![]() CBuilder Developer |
2004-07-27 09:52:45 PM
Re:SendMessage() to the service app
Remy,
Following your directions I succeded to control the service and to send custom messages to it. This rough code works fine if someone is interested (I also included starting, stopping, pausing and continuing the service). What about closing the service handles CloseServiceHandle()? I added closing but it is not mentioned explicitely that it's important but it seems prety normal to close the handles. <CONFIG APP> void __fastcall TForm1::SharedButtonClick(TObject *Sender) { int ButtonTag = ( (TButton*)Sender )->Tag; SC_HANDLE H1 = OpenSCManager ( NULL, NULL, SC_MANAGER_ALL_ACCESS ); DWORD DesiredAccess; if ( ButtonTag == 0 ) DesiredAccess = SERVICE_USER_DEFINED_CONTROL; else DesiredAccess = SERVICE_ALL_ACCESS; SC_HANDLE H2 = OpenService ( H1, "TestService", DesiredAccess ); bool R; SERVICE_STATUS sstatus; switch ( ButtonTag ) { case 0: R = ControlService ( H2, 200, &sstatus ); break; case 1: R = ControlService ( H2, SERVICE_CONTROL_STOP, &sstatus ); break; case 2: R = ControlService ( H2, SERVICE_CONTROL_PAUSE, &sstatus ); break; case 3: R = ControlService ( H2, SERVICE_CONTROL_CONTINUE, &sstatus ); break; case 4: R = StartService ( H2, NULL, NULL ); break; } CloseServiceHandle ( H2 ); CloseServiceHandle ( H1 ); } <SERVICE> bool __fastcall TTestService::DoCustomControl(unsigned CtrlCode) { // Some result checking code ... TIniFile* pif = new TIniFile ( "C:\\service.ini" ); if ( CtrlCode == 200 ) pif->WriteString ( "Test", "Value", ntToStr( CtrlCode ) ); else pif->WriteString ( "Test", "Value", "Not 200!" ); delete pif; return ( true ); } |
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2004-07-28 02:35:49 AM
Re:SendMessage() to the service app
"Vladimir Stefanovic" < XXXX@XXXXX.COM >wrote in message
QuoteWhat about closing the service handles CloseServiceHandle()? |