Browse Source

Change _tmain to main.

git-svn-id: https://svn.microneil.com/svn/CodeDweller/branches/adeniz_1@41 d34b734f-a00e-4b39-a726-e4eeb87269ab
adeniz_1
adeniz 10 years ago
parent
commit
4cd5ce48db
2 changed files with 28 additions and 9 deletions
  1. 26
    7
      service.cpp
  2. 2
    2
      service.hpp

+ 26
- 7
service.cpp View File

#ifdef WIN32 #ifdef WIN32
#include <windows.h> #include <windows.h>
#include <tchar.h>
#include <strsafe.h> #include <strsafe.h>
#else #else
#ifdef WIN32 #ifdef WIN32
// Application main entry point for Windows. // Application main entry point for Windows.
int _tmain(int argc, TCHAR *argv[]) {
int main(int argc, char *argv[]) {
#ifdef DEBUG_LOG_FILE
std::ofstream logStream;
logStream.open(DEBUG_LOG_FILE, std::fstream::app);
logStream << "main. argc: " << argc << std::endl;
for (int i = 0; i < argc; i++) {
logStream << "arg " << i << ": '" << argv[i] << "'" << std::endl;
}
logStream.close();
#endif
CodeDweller::Service &service = CodeDweller::Service::getInstance(); CodeDweller::Service &service = CodeDweller::Service::getInstance();
// Service entry point for Windows. // Service entry point for Windows.
VOID WINAPI ServiceMain(DWORD argc, LPTSTR *argv) { VOID WINAPI ServiceMain(DWORD argc, LPTSTR *argv) {
#ifdef DEBUG_LOG_FILE
std::ofstream logStream;
logStream.open(DEBUG_LOG_FILE, std::fstream::app);
logStream << "ServiceMain. argc: " << argc << std::endl;
for (unsigned int i = 0; i < argc; i++) {
logStream << "arg " << i << ": '" << argv[i] << "'" << std::endl;
}
logStream.close();
#endif
CodeDweller::Service &service = CodeDweller::Service::getInstance(); CodeDweller::Service &service = CodeDweller::Service::getInstance();
return service.serviceMain(argc, argv); return service.serviceMain(argc, argv);
std::ofstream logStream; std::ofstream logStream;
logStream.open(DEBUG_LOG_FILE, std::fstream::app); logStream.open(DEBUG_LOG_FILE, std::fstream::app);
logStream << "main. argc: " << argc << std::endl;
logStream << "Service::main. argc: " << argc << std::endl;
for (int i = 0; i < argc; i++) { for (int i = 0; i < argc; i++) {
logStream << "arg " << i << ": '" << argv[i] << "'" << std::endl; logStream << "arg " << i << ": '" << argv[i] << "'" << std::endl;
} }
#ifdef WIN32 #ifdef WIN32
SERVICE_TABLE_ENTRY ServiceTable[] = { SERVICE_TABLE_ENTRY ServiceTable[] = {
{"", (LPSERVICE_MAIN_FUNCTION) ServiceMain},
{(LPTSTR) "", ServiceMain},
{NULL, NULL} {NULL, NULL}
}; };
// executable name; append them to the object's argument list. // executable name; append them to the object's argument list.
loadArguments(argc - 1, (char **) argv + 1); loadArguments(argc - 1, (char **) argv + 1);
DWORD Status = E_FAIL;
// Register the service control handler with the SCM. // Register the service control handler with the SCM.
serviceStatusHandle = serviceStatusHandle =
RegisterServiceCtrlHandler("", ServiceCtrlHandler); RegisterServiceCtrlHandler("", ServiceCtrlHandler);
// Change status to stopped. // Change status to stopped.
serviceStatus.dwControlsAccepted = 0; serviceStatus.dwControlsAccepted = 0;
serviceStatus.dwCurrentState = SERVICE_STOPPED; serviceStatus.dwCurrentState = SERVICE_STOPPED;
serviceStatus.dwWin32ExitCode = NO_ERROR;
serviceStatus.dwWin32ExitCode = status;
serviceStatus.dwCheckPoint = 0; serviceStatus.dwCheckPoint = 0;
(void) SetServiceStatus(serviceStatusHandle, &serviceStatus); (void) SetServiceStatus(serviceStatusHandle, &serviceStatus);

+ 2
- 2
service.hpp View File



#ifdef WIN32 #ifdef WIN32


int _tmain(int argc, TCHAR *argv[]);
int main(int argc, char *argv[]);


VOID WINAPI ServiceMain(DWORD argc, LPTSTR *argv); VOID WINAPI ServiceMain(DWORD argc, LPTSTR *argv);


/// Handle for accessing service status on the OS. /// Handle for accessing service status on the OS.
SERVICE_STATUS_HANDLE serviceStatusHandle = NULL; SERVICE_STATUS_HANDLE serviceStatusHandle = NULL;


friend int ::_tmain(int argc, TCHAR *argv[]);
friend int ::main(int argc, char *argv[]);


friend VOID WINAPI ::ServiceMain(DWORD argc, LPTSTR *argv); friend VOID WINAPI ::ServiceMain(DWORD argc, LPTSTR *argv);



Loading…
Cancel
Save