• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
gandolf1212

My Service Doesn't Work

4 posts in this topic

I have been trying for two days to get this to run but it will not start.
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <fstream>

using namespace std;

#define SLEEP_TIME 5000

SERVICE_STATUS ServiceStatus; 
SERVICE_STATUS_HANDLE hStatus; 
 
void  ServiceMain(int argc, char** argv); 
void  ControlHandler(DWORD request); 
int InitService();

int WriteToLog(char* str)
{
	FILE* log;
	log = fopen("output.html", "w");
	if (log == NULL)
		return -1;
	fprintf(log, "%s\n", str);
	fclose(log);
	return 0;
}

ofstream out;

class op{
    public:
        
    op(){
        out.open("output.html");
    }
};  

op _;

int main() 
{ 
   
    SERVICE_TABLE_ENTRY ServiceTable[2];
    ServiceTable[0].lpServiceName = "MemoryStatus3";
    ServiceTable[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)ServiceMain;

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

    out<<"Starting"<<endl;

    out<<"Ret Code"<<StartServiceCtrlDispatcher(ServiceTable)<<endl;  
    
    DWORD myerror = GetLastError();
    
    out<<"Last Error"<<myerror<<endl;
    
    if(ERROR_FAILED_SERVICE_CONTROLLER_CONNECT == myerror){
        out<<"ERROR_FAILED_SERVICE_CONTROLLER_CONNECT"<<ERROR_FAILED_SERVICE_CONTROLLER_CONNECT<<endl;
    }
    if(ERROR_INVALID_DATA == myerror){
        out<<"ERROR_INVALID_DATA"<<ERROR_INVALID_DATA<<endl;
    }
    if(ERROR_FAILED_SERVICE_CONTROLLER_CONNECT == myerror){
        out<<"ERROR_SERVICE_ALREADY_RUNNING"<<ERROR_FAILED_SERVICE_CONTROLLER_CONNECT<<endl;
    }
    
    out<<"Done"<<endl;
    out.close();
    system("PAUSE");
}

void ServiceMain(int argc, char** argv) 
{ 
    out<<"Service Main"<<endl;
    int error; 
 
    ServiceStatus.dwServiceType        = SERVICE_WIN32; 
    ServiceStatus.dwCurrentState       = SERVICE_START; 
    ServiceStatus.dwControlsAccepted   = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
    ServiceStatus.dwWin32ExitCode      = 0; 
    ServiceStatus.dwServiceSpecificExitCode = 0; 
    ServiceStatus.dwCheckPoint         = 0; 
    ServiceStatus.dwWaitHint           = 0; 
 
    hStatus = RegisterServiceCtrlHandler(
		"MemoryStatus3", 
		(LPHANDLER_FUNCTION)ControlHandler); 
    if (hStatus == (SERVICE_STATUS_HANDLE)0) 
    { 
        // Registering Control Handler failed
        cout<<"Registering Control Handler failed"<<endl;
        return; 
    }  
    // Initialize Service 
    error = InitService(); 
    if (error) 
    {
		// Initialization failed
        ServiceStatus.dwCurrentState       = SERVICE_STOPPED; 
        ServiceStatus.dwWin32ExitCode      = -1; 
        SetServiceStatus(hStatus, &ServiceStatus); 
        cout<<"Init Failed"<<endl;
        return; 
    } 
    // We report the running status to SCM. 
    ServiceStatus.dwCurrentState = SERVICE_RUNNING; 
    SetServiceStatus (hStatus, &ServiceStatus);
 
    MEMORYSTATUS memory;
    // The worker loop of a 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; 
}
 
// Service initialization
int InitService() 
{ 
    out<<"Init Service"<<endl;
    int result;
    result = WriteToLog("Monitoring started.");
    return(result); 
} 

// Control handler function
void ControlHandler(DWORD request) 
{ 
    out<<"ControlHandler"<<endl;

    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; 
} 



The start service dispatch control thread dies. Here is the output log: Starting Ret Code0 Last Error1063 ERROR_FAILED_SERVICE_CONTROLLER_CONNECT1063 ERROR_SERVICE_ALREADY_RUNNING1063 Done Anyone have any advice? I just don't know what else to narrow down the problem :(
0

Share this post


Link to post
Share on other sites
Looking at my service code, your ServiceMain function may not be declared correctly.

Mine is declared as

void WINAPI ServiceStart(DWORD argc, LPTSTR * argv)

aslo for the control handler

void WINAPI ServiceCtrlHandler(DWORD opcode)
0

Share this post


Link to post
Share on other sites
Ah right, I forgot an important question.

How are you running this serivce application?

You have to use the service control panel to start the service. You can't start the application like a normal executable by double clicking on the icon.

In order for your service to show up in the service control panel you have to add a registry entry for it.

I believe that there is also a command line for starting services although I dont know what it is off the top of my head.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by cmptrgear
I believe that there is also a command line for starting services although I dont know what it is off the top of my head.
net start your_service_name
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0