Click here to Skip to main content
15,891,033 members
Articles / Desktop Programming / MFC

Easy Command Line Service

Rate me:
Please Sign up or sign in to vote.
4.56/5 (8 votes)
16 Nov 2012CPOL2 min read 29.2K   922   33  
An easy DOS framework for creating and managing a service
// CLS.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "CLS.h"
#include "WinService.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// The one and only application object

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	int nRetCode = 0;

	// initialize MFC and print and error on failure
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
	{
		// TODO: change error code to suit your needs
		_tprintf(_T("Fatal Error: MFC initialization failed\n"));
		nRetCode = 1;
	}
	else
	{
		// Parse for standard arguments (install, uninstall, usage)
		CMyService MyService;
		if (!MyService.ParseStandardArgs(argc, argv))
			MyService.StartService();

		// When we get here, the service has been stopped
		return MyService.m_Status.dwWin32ExitCode;
	}

	return nRetCode;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Founder
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions