Anyone here know about C++?

Permabanned
Joined
29 Aug 2006
Posts
164
Help?

I've written this program (which used to work fine)

Code:
#include <windows.h>
#include <stdio.h>
#include <io.h>
#include <process.h>
#include <errno.h>

#define SLEEP_TIME 5000

SERVICE_STATUS ServiceStatus;
SERVICE_STATUS_HANDLE hStatus;
PROCESS_INFORMATION fgProc;
STARTUPINFO procSU;
DWORD exitCode;

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

void main() {
        SERVICE_TABLE_ENTRY ServiceTable[2];
        ServiceTable[0].lpServiceName = "eflow Input Script";
        ServiceTable[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)ServiceMain;

        ServiceTable[1].lpServiceName = NULL;
        ServiceTable[1].lpServiceProc = NULL;
        // Start the control dispatcher thread for our service
        StartServiceCtrlDispatcher(ServiceTable);
}

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("eflow Input Script", (LPHANDLER_FUNCTION)ControlHandler);
        if (hStatus == (SERVICE_STATUS_HANDLE)0) {
                // Registering Control Handler failed
                return;
        }
        // Initialize Service
        error = InitService();
        if (error == false) {
                // Initialization failed
                ServiceStatus.dwCurrentState = SERVICE_STOPPED;
                ServiceStatus.dwWin32ExitCode = -1;
                SetServiceStatus(hStatus, &ServiceStatus);
                return;
        }
        // We report the running status to SCM.
        ServiceStatus.dwCurrentState = SERVICE_RUNNING;
        SetServiceStatus (hStatus, &ServiceStatus);

        // The worker loop of a service
        while (ServiceStatus.dwCurrentState == SERVICE_RUNNING) {
                /* check if the process is still running */
                GetExitCodeProcess(fgProc.hProcess, &exitCode);

                switch(exitCode) {
                        case STILL_ACTIVE:
                                Sleep(SLEEP_TIME);
                                break;
                        default:
                                ServiceStatus.dwCurrentState = SERVICE_STOPPED;
                                ServiceStatus.dwWin32ExitCode = -1;
                                SetServiceStatus(hStatus, &ServiceStatus);
                                return;
                                break;
                }
        }
        return;
}

int InitService() {
        int result;
		result=0;
        GetStartupInfo(&procSU);
        //result = CreateProcess(NULL, "C:\\Progra~1\\Kix32\\Kix32.exe \\\\ukbrafax2\\kix\\input.scr $log=both $IniFile=\\\\ukbrafax2\\kix\\eflow.ini", NULL, NULL, TRUE, 0, NULL, NULL, &procSU, &fgProc);

        return(result);
}

void ControlHandler(DWORD request) {
        switch(request) {
                case SERVICE_CONTROL_STOP:
                        ServiceStatus.dwWin32ExitCode = 0;
                        ServiceStatus.dwCurrentState = SERVICE_STOPPED;
                        TerminateProcess(fgProc.hProcess, 0);
                        SetServiceStatus (hStatus, &ServiceStatus);
                return;

                case SERVICE_CONTROL_SHUTDOWN:
                        ServiceStatus.dwWin32ExitCode = 0;
                        ServiceStatus.dwCurrentState = SERVICE_STOPPED;
                        TerminateProcess(fgProc.hProcess, 0);
                        SetServiceStatus (hStatus, &ServiceStatus);
                return;

                default:
                break;
        }

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

        return;
}

The only thing I have changed is commented out this line
Code:
//result = CreateProcess(NULL, "C:\\Progra~1\\Kix32\\Kix32.exe \\\\ukbrafax2
near the bottom and set the result=0 two lines above.

I now get two build errors.

Heres the log

Code:
Compiling...
prodinput.cpp
c:\documents and settings\a11g1zz\my documents\eflow\prodinput.cpp(21) : error C2440: '=' : cannot convert from 'const char [19]' to 'LPWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\a11g1zz\my documents\eflow\prodinput.cpp(41) : error C2664: 'RegisterServiceCtrlHandlerW' : cannot convert parameter 1 from 'const char [19]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Build log was saved at "file://c:\Documents and Settings\a11g1zz\My Documents\Visual Studio 2005\Projects\IO2\IO2\Debug\BuildLog.htm"
IO2 - 2 error(s), 0 warning(s)

Can anyone see what is wrong??

TIA
 
I had this problem last week, I tihnk you have to change a setting somewhere on visual studio.

Ill try to find...

Here it is.

Project -> Properties -> Configuruation Properties -> General -> Character Set -> Use Multi-Byte Character Set

I think this was the fix, but not 100% sure.
 
Last edited:
Yeah the fix above should work. Or prefix your strings with L ie L"eflow Input Script".
 
Back
Top Bottom