Click here to Skip to main content
15,887,485 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: excel automation Pin
prithaa30-Sep-09 22:38
prithaa30-Sep-09 22:38 
QuestionHandle Dialog in VB Script Pin
Bedke23-Sep-09 18:30
Bedke23-Sep-09 18:30 
QuestionTo launch the "Speakers Properties" Pin
Maxwell Chen23-Sep-09 18:05
Maxwell Chen23-Sep-09 18:05 
AnswerRe: To launch the "Speakers Properties" Pin
Maxwell Chen23-Sep-09 18:35
Maxwell Chen23-Sep-09 18:35 
AnswerRe: To launch the "Speakers Properties" Pin
kilt24-Sep-09 7:03
kilt24-Sep-09 7:03 
QuestionMemory mapped file I/O Vs Disk I/O Pin
vipin_nvk23-Sep-09 18:05
vipin_nvk23-Sep-09 18:05 
AnswerRe: Memory mapped file I/O Vs Disk I/O Pin
Stuart Dootson24-Sep-09 6:23
professionalStuart Dootson24-Sep-09 6:23 
Questiona bother about windows service Pin
jinjiashan23-Sep-09 16:16
jinjiashan23-Sep-09 16:16 
Hi,all
I have a windows service program with a service,and I can use "myservice/service" in cmd.exe,it sucess!
then,I can see the service in control pane,I also can start up this service;
But, this service can't run my code;Confused | :confused: why??

the whole code here



void yourfunction()

{

for (int a =0; a<10; a++)

::MessageBoxA(NULL, "ggg", "ghgh" ,MB_OK);

}

SERVICE_STATUS ServiceStatus =

{

SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS,
SERVICE_STOPPED,
SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_PAUSE_CONTINUE,
0,0,0,0
};

TCHAR szSvName[]=TEXT("Myservice1");
SERVICE_STATUS_HANDLE hStatus;
SC_HANDLE SCMger;

void WINAPI ControlHandler(DWORD request);

void ServiceMain(int argc, char* argv);





void CreateMyService()
{
SCMger=OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
CreateService(
SCMger,
szSvName,
szSvName,
SERVICE_START,
SERVICE_WIN32_OWN_PROCESS,
SERVICE_AUTO_START,
SERVICE_ERROR_IGNORE,
TEXT("c:\\myservice1.exe"),
NULL,
NULL,
NULL,
NULL,
NULL);
}





int main()
{
SERVICE_TABLE_ENTRY ServiceTable[2];
ServiceTable[0].lpServiceName = szSvName;
ServiceTable[0].lpServiceProc=(LPSERVICE_MAIN_FUNCTION)ServiceMain;
ServiceTable[1].lpServiceName = NULL;
ServiceTable[1].lpServiceProc= NULL;

if(StartServiceCtrlDispatcher(ServiceTable)==0)CreateMyService();
}






//this fun also can't be debug,can't run
void ServiceMain(int argc, char* argv)
{
hStatus = RegisterServiceCtrlHandler(szSvName,ControlHandler);
ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_SHUTDOWN;
SetServiceStatus(hStatus,&ServiceStatus);

ServiceStatus.dwWin32ExitCode = NO_ERROR;

ServiceStatus.dwCheckPoint = 0;
serviceStatus.dwWaitHint = 0;
ServiceStatus.dwCurrentState = SERVICE_RUNNING;
SetServiceStatus(hStatus,&ServiceStatus);

yourfunction();

ServiceStatus.dwCurrentState = SERVICE_STOPPED;




SetServiceStatus(hStatus,&ServiceStatus);
}




//this fun can't be debug,can't run

void WINAPI ControlHandler(DWORD request)
{
switch(request)
{

case SERVICE_CONTROL_SHUTDOWN:
ServiceStatus.dwCurrentState = SERVICE_STOPPED;
SetServiceStatus(hStatus,&ServiceStatus);
break;
}

}
AnswerRe: a bother about windows service Pin
jinjiashan23-Sep-09 21:50
jinjiashan23-Sep-09 21:50 
GeneralRe: a bother about windows service Pin
jinjiashan24-Sep-09 0:04
jinjiashan24-Sep-09 0:04 
AnswerRe: a bother about windows service Pin
Rolf Kristensen26-Sep-09 7:49
Rolf Kristensen26-Sep-09 7:49 
GeneralRe: a bother about windows service Pin
jinjiashan27-Sep-09 13:29
jinjiashan27-Sep-09 13:29 
QuestionProblem with initializing Main args! Pin
Largo6523-Sep-09 12:58
Largo6523-Sep-09 12:58 
AnswerRe: Problem with initializing Main args! Pin
Game-point23-Sep-09 18:40
Game-point23-Sep-09 18:40 
AnswerRe: Problem with initializing Main args! Pin
Saurabh.Garg23-Sep-09 18:56
Saurabh.Garg23-Sep-09 18:56 
AnswerRe: Problem with initializing Main args! Pin
«_Superman_»23-Sep-09 19:23
professional«_Superman_»23-Sep-09 19:23 
AnswerRe: Problem with initializing Main args! Pin
Richard MacCutchan23-Sep-09 22:32
mveRichard MacCutchan23-Sep-09 22:32 
QuestionC++ with in-code Assembly Pin
paolosh23-Sep-09 10:22
paolosh23-Sep-09 10:22 
AnswerRe: C++ with in-code Assembly Pin
ied23-Sep-09 10:28
ied23-Sep-09 10:28 
AnswerRe: C++ with in-code Assembly Pin
Rick York23-Sep-09 10:37
mveRick York23-Sep-09 10:37 
QuestionLoadImage fails to locate file Pin
raich23-Sep-09 8:32
raich23-Sep-09 8:32 
QuestionRe: LoadImage fails to locate file Pin
David Crow23-Sep-09 9:03
David Crow23-Sep-09 9:03 
AnswerRe: LoadImage fails to locate file Pin
raich23-Sep-09 9:42
raich23-Sep-09 9:42 
QuestionRe: LoadImage fails to locate file Pin
David Crow23-Sep-09 10:00
David Crow23-Sep-09 10:00 
AnswerRe: LoadImage fails to locate file Pin
norish23-Sep-09 21:43
norish23-Sep-09 21:43 

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.