I actually don't even know what is going on here, but I hope someone can help me. A while ago, I created a class to control windows services, using the Windows API SC. For a long time it works fine, without serious error. But today I used this class in my project and when the garbage works (at the and of an if, or a function...) my application crash. And only crashs when I try to stop a service.
int main() {
wchar_t serviceName[] = L"foo";
ServiceController *service = new ServiceController(serviceName);
if(!service->isRunning()){
service->start();
} else {
service->stop();
}
system("PAUSE");
return 0;
}
That example, when the service "foo" is not running, the method start starts the service and the application closes fine, else if the service is running, the method stop stops the service, the system("PAUSE");
works normaly, but the application crashs after return.
I've tried everything, but nothing helps.
The class can be found here
Thanks!
EDIT: On the Event Viewer I can found this error:
Faulting application name: stop.exe, version: 0.0.0.0, time stamp: 0x02430cb0
Faulting module name: ntdll.dll, version: 6.1.7600.16385, time stamp: 0x4a5bdadb
Exception code: 0xc0000005
Fault offset: 0x00055668
Faulting process id: 0xb90
Faulting application start time: 0x01d07389e28c97f4
Faulting application path: C:\Users\CacicQT86\Documents\build-stop-Desktop_Qt_5_3_MinGW_32bit-Debug\debug\stop.exe
Faulting module path: C:\Windows\SYSTEM32\ntdll.dll
Report Id: 20ceff7a-df7d-11e4-905d-08002754d7a4
Solved on this commit. I just changed
LPSERVICE_STATUS
bySERVICE_STATUS_PROCESS
, which does not need to be initialized, onstop()
. Probably was a delete mistake.