Click here to Skip to main content
15,914,165 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to load OCX file in VC++ Project Pin
Pavan_Putra14-Dec-09 23:13
Pavan_Putra14-Dec-09 23:13 
GeneralYou are welcome Pin
CPallini14-Dec-09 23:23
mveCPallini14-Dec-09 23:23 
QuestionHow can vertically move down scroll of List Ctrl? Pin
Le@rner14-Dec-09 21:14
Le@rner14-Dec-09 21:14 
AnswerRe: How can vertically move down scroll of List Ctrl? Pin
Rajesh R Subramanian14-Dec-09 21:29
professionalRajesh R Subramanian14-Dec-09 21:29 
GeneralRe: How can vertically move down scroll of List Ctrl? Pin
Le@rner14-Dec-09 21:54
Le@rner14-Dec-09 21:54 
AnswerRe: How can vertically move down scroll of List Ctrl? Pin
Rajesh R Subramanian15-Dec-09 0:10
professionalRajesh R Subramanian15-Dec-09 0:10 
GeneralRe: How can vertically move down scroll of List Ctrl? Pin
Le@rner15-Dec-09 0:31
Le@rner15-Dec-09 0:31 
QuestionHelp on c++ windows service. Pin
tuhincse02814-Dec-09 20:56
tuhincse02814-Dec-09 20:56 
I have got a code snippet which is very simple windows service,when i start it manually after creating it by sc command it's taking a lot of time to start, and after a long time it gives me an error message of 1053. Then the service's status becomes starting. but surprising part is the service is actually doing its work on background, although i can't stop this service(I need to restart to stop the service). Here is the code,
// Test00.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "Test00.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// The one and only application object

CWinApp theApp;

using namespace std;

#define SLEEP_TIME 5000
#define LOGFILE "d:\\memstatus.txt"

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(LOGFILE, "a+");
	if (log == NULL)
		return -1;
	fprintf(log, "%s\n", str);
	fclose(log);
	return 0;
}


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
	{
		// TODO: code your application's behavior here.
		SERVICE_TABLE_ENTRY ServiceTable[2];
		ServiceTable[0].lpServiceName = "MemoryStatus";
		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);

	}

	return nRetCode;
}
void ServiceMain(int argc, char** argv) 
{ 
    int error; 
 
	ServiceStatus.dwServiceType        = SERVICE_WIN32_OWN_PROCESS|SERVICE_ALL_ACCESS; 
	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(
		"MemoryStatus", 
		(LPHANDLER_FUNCTION)ControlHandler); 
    if (hStatus == (SERVICE_STATUS_HANDLE)0) 
    { 
        // Registering Control Handler failed
        return; 
    }  
    // Initialize Service 
    error = InitService(); 
    if (error) 
    {
		// 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);
 
    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() 
{ 
    int result;
    result = WriteToLog("Monitoring started.");
    return(result); 
} 

// Control handler function
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; 
} 

It would be a great help if someone plz help me regarding this.
AnswerRe: Help on c++ windows service. Pin
conrad Braam24-May-10 20:52
conrad Braam24-May-10 20:52 
QuestionCreate MFC project error Pin
MsmVc14-Dec-09 20:48
MsmVc14-Dec-09 20:48 
AnswerRe: Create MFC project error Pin
Rajesh R Subramanian14-Dec-09 21:19
professionalRajesh R Subramanian14-Dec-09 21:19 
GeneralRe: Create MFC project error Pin
MsmVc14-Dec-09 22:23
MsmVc14-Dec-09 22:23 
QuestionMake setup with all installation components for an exe Pin
jannathali14-Dec-09 20:08
jannathali14-Dec-09 20:08 
AnswerRe: Make setup with all installation components for an exe Pin
Cedric Moonen14-Dec-09 20:14
Cedric Moonen14-Dec-09 20:14 
AnswerRe: Make setup with all installation components for an exe Pin
Rajesh R Subramanian14-Dec-09 21:36
professionalRajesh R Subramanian14-Dec-09 21:36 
JokeRe: Make setup with all installation components for an exe Pin
Moak15-Dec-09 4:48
Moak15-Dec-09 4:48 
GeneralRe: Make setup with all installation components for an exe Pin
Rajesh R Subramanian15-Dec-09 5:39
professionalRajesh R Subramanian15-Dec-09 5:39 
QuestionCreating Bitmap Error Pin
pri_skit14-Dec-09 19:10
pri_skit14-Dec-09 19:10 
AnswerRe: Creating Bitmap Error Pin
KingsGambit14-Dec-09 19:19
KingsGambit14-Dec-09 19:19 
QuestionChange the color of dialog in win32 Pin
002comp14-Dec-09 18:06
002comp14-Dec-09 18:06 
AnswerRe: Change the color of dialog in win32 Pin
Sameerkumar Namdeo14-Dec-09 18:33
Sameerkumar Namdeo14-Dec-09 18:33 
AnswerRe: Change the color of dialog in win32 Pin
Tim Craig14-Dec-09 23:01
Tim Craig14-Dec-09 23:01 
GeneralRe: Change the color of dialog in win32 Pin
Stephen Hewitt15-Dec-09 2:34
Stephen Hewitt15-Dec-09 2:34 
GeneralRe: Change the color of dialog in win32 Pin
Tim Craig15-Dec-09 9:42
Tim Craig15-Dec-09 9:42 
QuestionGet mouse cursor name Pin
Bedke14-Dec-09 16:35
Bedke14-Dec-09 16:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.