Click here to Skip to main content
15,896,606 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: C++ dialog question Pin
Rajesh match24-Aug-04 20:17
Rajesh match24-Aug-04 20:17 
GeneralRe: C++ dialog question Pin
Linera25-Aug-04 8:06
Linera25-Aug-04 8:06 
GeneralRe: C++ dialog question Pin
Rajesh match25-Aug-04 19:15
Rajesh match25-Aug-04 19:15 
GeneralRe: C++ dialog question Pin
Linera26-Aug-04 7:20
Linera26-Aug-04 7:20 
GeneralCreateProcess question... Pin
RobJones24-Aug-04 13:51
RobJones24-Aug-04 13:51 
GeneralRe: CreateProcess question... Pin
Archer28224-Aug-04 16:30
Archer28224-Aug-04 16:30 
GeneralRe: CreateProcess question... Pin
RobJones25-Aug-04 4:02
RobJones25-Aug-04 4:02 
GeneralWindow Service Question Pin
aman200624-Aug-04 13:46
aman200624-Aug-04 13:46 
hi
I wrote a window service in which i am using the SOCKET API who listens to the clinet. This service runs fine on win2000 but if i run this on win2003 Server, it stop with some access violation error c0000005. I don't know whats is the problem. If i run my code without service means i make the console application and run this it does not show any error on win2003. I have this code like:

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{

int nRetCode = 0;

if(FillParams())
_chdir(DIR_PATH);
else
return 0;

SERVICE_TABLE_ENTRY ServiceTable[2];
ServiceTable[0].lpServiceName = "TibcoTCPServer";
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_WIN32_SHARE_PROCESS;// 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(
"TibcoTCPServer",
(LPHANDLER_FUNCTION)ControlHandler);
if (hStatus == (SERVICE_STATUS_HANDLE)0)
{
// Registering Control Handler failed
WriteToLog("Registring Control Handler failed");
return;
}
// Initialize Service
error = InitService();
if (error)
{
// Initialization failed
ServiceStatus.dwCurrentState =
SERVICE_STOPPED;
ServiceStatus.dwWin32ExitCode = -1;
SetServiceStatus(hStatus, &ServiceStatus);
return;
}

// WriteToLog("Service Started _2.");

// We report the running status to SCM.
ServiceStatus.dwCurrentState = SERVICE_RUNNING;
SetServiceStatus (hStatus, &ServiceStatus);

AfxBeginThread(MTServerThread,0);


return;
}

UINT MTServerThread(LPVOID pParam)
{
WSADATA wsaData;
sockaddr_in local;

int wsaret=WSAStartup(0x101,&wsaData);
if(wsaret!=0)
{
return 0;
}
local.sin_family=AF_INET;
local.sin_addr.s_addr=INADDR_ANY;
int nPort = atoi(PORT);
local.sin_port=htons((u_short)nPort);
server=socket(AF_INET,SOCK_STREAM,0);
if(server==INVALID_SOCKET)
{
return 0;
}
if(bind(server,(sockaddr*)&local,sizeof(local))!=0)
{
return 0;
}
if(listen(server,SOMAXCONN)!=0)
{
return 0;
}

WriteToLog("Server Started.");
SOCKET client;
sockaddr_in from;
int fromlen=sizeof(from);

WriteToLog("Server Started _ 2.");

while(true)
{

WriteToLog("Server Started _ 3.");
client=accept(server,
(struct sockaddr*)&from,&fromlen);


WriteToLog("Client Request Accepted.");
AfxBeginThread(ClientThread,(LPVOID)client);

//Sleep(3000);

}

return 0;
}

It has the problem in MTServerThread() function when it comes in to the while loop. when it waits for the client at that point it throws the exception of access violation and stops the service.

Any input will be appreciated.

Thanks ina advance

Shailesh
GeneralRe: Window Service Question Pin
Milton Karimbekallil24-Aug-04 18:58
Milton Karimbekallil24-Aug-04 18:58 
GeneralRe: Window Service Question Pin
Stlan25-Aug-04 1:27
Stlan25-Aug-04 1:27 
GeneralRe: Window Service Question Pin
aman200626-Aug-04 7:42
aman200626-Aug-04 7:42 
GeneralCreating an custom dos stub Pin
Vilo99924-Aug-04 13:02
Vilo99924-Aug-04 13:02 
GeneralRe: Creating an custom dos stub Pin
Ryan Binns24-Aug-04 18:23
Ryan Binns24-Aug-04 18:23 
GeneralRe: Creating an custom dos stub Pin
Vilo99925-Aug-04 0:27
Vilo99925-Aug-04 0:27 
GeneralRe: Creating an custom dos stub Pin
David Crow25-Aug-04 3:28
David Crow25-Aug-04 3:28 
GeneralCan't get CScrollView to scroll properly Pin
cyclonez24-Aug-04 11:12
cyclonez24-Aug-04 11:12 
GeneralAccessing Structures Pin
Zero_G24-Aug-04 10:45
Zero_G24-Aug-04 10:45 
GeneralRe: Accessing Structures Pin
palbano24-Aug-04 11:11
palbano24-Aug-04 11:11 
GeneralCast to int * Pin
Anonymous24-Aug-04 10:25
Anonymous24-Aug-04 10:25 
GeneralRe: Cast to int * Pin
Ravi Bhavnani24-Aug-04 10:55
professionalRavi Bhavnani24-Aug-04 10:55 
GeneralRe: Cast to int * Pin
palbano24-Aug-04 11:17
palbano24-Aug-04 11:17 
GeneralRe: Cast to int * Pin
Ravi Bhavnani24-Aug-04 11:32
professionalRavi Bhavnani24-Aug-04 11:32 
GeneralRe: Cast to int * Pin
Anonymous25-Aug-04 2:16
Anonymous25-Aug-04 2:16 
GeneralRe: Cast to int * Pin
Anonymous25-Aug-04 3:28
Anonymous25-Aug-04 3:28 
GeneralRe: Cast to int * Pin
Henry miller25-Aug-04 3:50
Henry miller25-Aug-04 3:50 

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.