[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.6

Compile Errors.

Asked by OBCT in C++ Programming Language

Tags: 1, does, error

A current project involves writing a Windows Service. Due to my lack of experience in C++, I've read an article on creating very basic services.
I've understood everything that was said; however when I try to compile the code, the compiler shows several errors.

Here is the code that I am using...

#include <windows.h>
#include <stdio.h>

#define SLEEP_TIME 5000;
#define LOGFILE "C:\\log.txt";

int WriteToLog(char* str){
      FILE* log;
      log = fopen(LOGFILE, "a+");

      if (log == NULL){
            return -1;
      }

      fprintf(log, "%s\n", str);
      fclose(log);
      return 0;
}

SERVICE_STATUS        ServiceStatus;
SERVICE_STATUS_HANDLE hStatus;

void ServiceMain(int charc, char** argv);
void ControlHandler(DWORD request);
int InitService();

void main(){
      SERVICE_TABLE_ENTRY ServiceTable[2];
      ServiceTable[0].lpServiceName = "MemoryStatusTestService";
      ServiceTable[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION) ServiceMain;
      ServiceTable[1].lpServiceName = NULL;
      ServiceTable[1].lpServiceProc = NULL;
      // Start the control dispatcher thread for the service
      StartServiceCtrlDispatcher(ServiceTable);
}

int InitService(){
      return WriteToLog("Monitoring Started");
}

void ServiceMain(int argc, char** argv){
      int error;
      ServiceStatus.dwServiceType  = SERVICE_WIN32;
      ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
      ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
      ServiceStatus.dwWin32ExitCode = 0;
      ServiceStatus.dwServiceSpecificExitCode = 0;
      ServiceStatus.dwCheckPoint = 0;
      ServiceStatus.dwWaitHint = 0;
      hStatus = RegisterServiceCtrlHandler("MemoryStatusServiceTest", (LPHANDLER_FUNCTION) ControlHandler);

      if (hStatus == (SERVICE_STATUS_HANDLE) 0){
            // Registering Control Handler failed.
            return;
      }

      // Initialize Service
      error = InitService();

      if (error){
            // Initizlization failed
            ServiceStatus.dwCurrentState = SERVICE_STOPPED;
            ServiceStatus.dwWin32ExitCode = -1;
            SetServiceStatus(hStatus, &ServiceStatus);
            return;
      }

      // Report the status the the SCM.
      ServiceStatus.dwCurrentState = SERVICE_RUNNING;
      SetServiceStatus(hStatus, &ServiceStatus);
      MEMORYSTATUS memory;

      // The worker loop of the service
      while (ServiceStatus.dwCurrentState == SERVICE_RUNNING)      {
            char buffer[16];
            GlobalMemoryStatus(&memory);
            sprintf(buffer, "%d", memory.dwAvailPhys);
            int result = WriteToLog(buffer);

            if (result){
                  ServiceStatus.dwCurrentState = SERVICE_STOPPED;
                  ServiceStatus.dwWin32ExitCode = -1;
                  SetServiceStatus(hStatus, &ServiceStatus);
                  return;
            }

            Sleep(SLEEP_TIME);
      }

      return;
}

void ControlHandler(DWORD request){
      switch (request){
            case SERVICE_CONTROL_STOP:
                  WriteToLog("Monitoring stopped.");
                  ServiceStatus.dwWin32ExitCode = 0;
                  ServiceStatus.dwCurrentState  = SERVICE_STOPPED;
                  SetServiceStatus(hStatus, &ServiceStatus);
                  return;

            case SERVICE_CONTROL_SHUTDOWN:
                  WriteToLog("Monitoring stopped.");
                  ServiceStatus.dwWin32ExitCode = 0;
                  ServiceStatus.dwCurrentState  = SERVICE_STOPPED;
                  SetServiceStatus(hStatus, &ServiceStatus);
                  return;

            default:
                  break;
      }

      // Report current status
      SetServiceStatus(hStatus, &ServiceStatus);
      return;
}

And here are the compile errors I'm receiving...
Compiling...
Service.cpp
C:\Documents and Settings\Adam\Desktop\OwnKeyLog\Service\Service.cpp(11) : error C2143: syntax error : missing ')' before ';'
C:\Documents and Settings\Adam\Desktop\OwnKeyLog\Service\Service.cpp(11) : error C2660: 'fopen' : function does not take 1 parameters
C:\Documents and Settings\Adam\Desktop\OwnKeyLog\Service\Service.cpp(11) : error C2143: syntax error : missing ';' before ','
C:\Documents and Settings\Adam\Desktop\OwnKeyLog\Service\Service.cpp(11) : error C2059: syntax error : ')'
C:\Documents and Settings\Adam\Desktop\OwnKeyLog\Service\Service.cpp(107) : error C2143: syntax error : missing ')' before ';'
C:\Documents and Settings\Adam\Desktop\OwnKeyLog\Service\Service.cpp(107) : error C2059: syntax error : ')'
Error executing cl.exe.

I can't see any syntax errors and this is driving me nuts so I have come for help.
I have very little C++ programming experience so please go easy on me.
Any help or suggestions will be greatly appreciated.

Cheers

-OBCT
[+][-]05/16/05 10:00 PM, ID: 14016165Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: C++ Programming Language
Tags: 1, does, error
Sign Up Now!
Solution Provided By: jaime_olivares
Participating Experts: 1
Solution Grade: A
 
[+][-]05/16/05 10:04 PM, ID: 14016174Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091118-EE-VQP-93