Developing in C++, .Net 2003 (7.1)
Running on Windows XP SP2
My delima is that all my windows services run fine until I STOP the service
at which time I get a "The windows service terminated unexpectidly" and the
"Send error to microsoft window." I debugged through MY code and it appears
to clean itself up properly. I don't see any memory leaks. The error occurs
after my ServiceMain exits. I can't debug any further as it appears to be in
the kernel.dll.
Is there something special (not disclosed in the docs or examples) that I
must do to keep this from happening?
Here is the last lines of my ServiceMain:
// Report our status one last time.
ServiceStatus.dwCurrentState = SERVICE_STOPPED;
ServiceStatus.dwWin32ExitCode = 0;
ServiceStatus.dwCheckPoint += 1;
ServiceStatus.dwWaitHint = 0;
SetServiceStatus(hStatus, &ServiceStatus);
} // ServiceMain
And here is the message from the EventLog:
Faulting application OSSExecute.EXE, version 0.0.0.0, faulting module
unknown, version 0.0.0.0, fault address 0x0012e7dc.
This is really annoying me as I can't figure out what the cause is.... Any
help would be appreciated.
Van - 07 Sep 2005 11:45 GMT
FYI for those who find this post later.
The problem was my 'ServiceMain' function was *NOT* using the Windows API
calling convention. The MSDN documentation does show the calling convention
syntax however, the MSDN example (the one I have anyways) does NOT show using
the Windows API calling convention.
I had to change my ServiceMain function declaration from:
void ServiceMain(int argc, char* argv[])
to
VOID WINAPI ServiceMain(DWORD argc, LPSTR* argv)
and that fixed my problem.
Explaination (as it was told to me):
The calling method of 'void ServiceMain' is '__cdecl' and it does not clean
up on its own and thus was corrupting the stacks.
> Developing in C++, .Net 2003 (7.1)
> Running on Windows XP SP2
[quoted text clipped - 26 lines]
> This is really annoying me as I can't figure out what the cause is.... Any
> help would be appreciated.