 |
|
 |
Do you have any correction?
|
|
|
|
 |
|
 |
What is this .awx file? How to open this .awx file?
|
|
|
|
 |
|
 |
I wrote it above:
My service wizard was created by the "Custom Wizard" project type. Its output is an AWX file that should be copied to \Common\MSDev98\Template folder.
Therefore, when creating service projects, choose "Service Wizard" from the project type list.
|
|
|
|
 |
|
 |
Thanks for your reply.
|
|
|
|
 |
|
 |
I found this incredibly useful and fairly easy to use. Thank you very much. Is there an easy way to set the text description? Service name and displayed name I found. I want to set the text that is displayed in the service manager.
Thanks again.
|
|
|
|
 |
|
 |
I've find this wizard
http://www.geocities.com/SiliconValley/Vista/8632/code/cppservice.html
The structure based on Class is more clean.
And there are many option I don't find in this wizard like OnPause.
But the Message queue is missing.
So since I'm a beginner, I don't knwon what is the Best ...
Can you give me some comments ?
Thanks
|
|
|
|
 |
|
 |
I am also a beginner in services. Before this I too found the above mentioned wizard. I found that the previous one was better structured in terms of OOP.
However, I still give high rating for this alternative attempt so that I can compare and learn from these two skeleton. There are no Best, just with different advantages I guess.
About the message queue, I believe we can add it on our own.
Thanks
|
|
|
|
 |
|
|
 |
|
 |
Tell me, what exactly is trash in this article?
What would you do in order to write a service? After all, service skeleton
is always the same. So why not to have a wizard for that?
What is your suggestion?
Furthermore, this sample can help you to learn how to write any wizard that is integrated to the Visual Studio IDE.
|
|
|
|
 |
|
 |
Yep it's a good sampe, thanks you for it.
|
|
|
|
 |
|
 |
it failed to work and to respond to stop
|
|
|
|
 |
|
 |
Soory.... it is working fine now.......
|
|
|
|
 |
|
 |
I am having problems converting this to UNICODE and I have been problems with vsprintf. My question is what exactly does that section of code do? So far I haven't seen any difference just ignoring that section and running lpszStrings[0] = pFormat and printf(pFormat). I just want to make sure that it won't cause any problems once I switch from console testing to actual service testing.
void CService::LogEvent(LPCSTR pFormat, ...)
{
TCHAR chMsg[256];
HANDLE hEventSource;
LPTSTR lpszStrings[1];
va_list pArg;
va_start(pArg, pFormat);
vsprintf(chMsg, pFormat, pArg);
va_end(pArg);
lpszStrings[0] = chMsg;
if (m_bService)
{
hEventSource = RegisterEventSource(NULL, m_szServiceName);
if (hEventSource != NULL)
{
ReportEvent(hEventSource, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (LPCTSTR*) &lpszStrings[0], NULL);
DeregisterEventSource(hEventSource);
}
}
else
{
printf(chMsg);
}
}
Matt
|
|
|
|
 |
|
 |
Well, this function sends events (such as "service stopped", service is running", etc...) to the event viewer in case the application runs as a service.
(Open the event viewer and see the events that refer to your service.)
If the application runs as a console one then your events are displayed
on the console window.
You won't have any problems when switching to service application.
|
|
|
|
 |
|
 |
Ok, I just wanted to double check before I got to far in the project then had to hurry up and change it
Thanks for the help.
Matt
|
|
|
|
 |
|
 |
Any plans to update for VC7?
[EDIT]Unicode would be a nice feature too[/EDIT]
Matt
|
|
|
|
 |
|
|
 |
|
 |
Maybe if I get some spare time I will work on it for you. Unfortunately with my schedule it will remain a maybe.
Matt
|
|
|
|
 |
|
 |
When the service receives a control stop it will only sets its status to stop_pending. The service never stops however…
Beside of that it’s a nice idee.
|
|
|
|
 |
|
 |
Not true.
Look at CService::ServiceMain() where i call
SetServiceStatus(SERVICE_STOPPED);
|
|
|
|
 |
|
 |
The code SetServiceStatus(SERVICE_STOPPED) in ServiceManin is never called because the Run() function is in an infinite message loop:
MSG msg;
while (GetMessage(&msg,NULL,NULL,NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
|
|
|
|
 |
|
 |
Not ture.
When the SCM send stop message then GetMessage gets WM_QUIT and therefore
the loop is stopped.
(If GetMessage(...) retrieves the WM_QUIT message, the return value is zero
and therefore the loop is stopped).
Did you try my wizard?
It is quite simple to install/uninstall the service.
Just run your executable file with the argument /Install or /Uninstall.
Start and stop the service and see that it works fine.
|
|
|
|
 |
|
 |
Yes,
I did try your wizard. But the service generated by the wizard wont't respond to a net stop .
The SCM doesn't send a WM_QUIT message. This is because the SCM doesn't know if the service's thread has a message queue. If you want to use a message queue in the thread you will have to send the WM_QUIT message yourself. This isn't in your code (yet).
|
|
|
|
 |
|
 |
Do you try to stop the service from the netwrok?
I didn't check it.
However, when i stop the service by the SCM (local on my computer) the service is stopped. Did you try that?
This means that GetMessage(...) got WM_QUIT message.
Maybe, SCM tries to kill a service in 3 phases:
1) Sending a special message.
2) Sending QM_QUIT
if all those operation fails then
3) SCM calls TerminateProcess.
Now, if you try to kill the service from remote host then the service will
not be able to get WM_QUIT message.
Am i right?
|
|
|
|
 |
|
 |
I did try to stop the service via the commandprompt (net stop) and via the Services mmc applet. I am using winXP by the way.
Normally the ServiceControlManager uses only the Services ControlHandler to try to stop a service. The SCM itselfs doesn't seems to care about failure or Success.
When a system shuts down however, all running processes will terminate in 20 secs or so, if the don't send updates to the scm about there current state.
I never read anywhere on th PSDK about WM_QUIT messages send to the service. I myself have never used services with a MessageQueue.
Then there is another issuee...
You should set the services state to stopped in the ServiceControlHandler function. Not in the main threads itself. Ofcourse you should only set the stopped state if the main thread has exited...
|
|
|
|
 |