Click here to Skip to main content
15,898,371 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: FILETIME, is the unit correct? Pin
Rajesh R Subramanian12-Aug-09 23:25
professionalRajesh R Subramanian12-Aug-09 23:25 
GeneralRe: FILETIME, is the unit correct? Pin
Stuart Dootson13-Aug-09 0:06
professionalStuart Dootson13-Aug-09 0:06 
QuestionData transfer between serial port and USB port in single PC Pin
praben12-Aug-09 5:36
praben12-Aug-09 5:36 
AnswerRe: Data transfer between serial port and USB port in single PC Pin
CPallini12-Aug-09 6:30
mveCPallini12-Aug-09 6:30 
AnswerRe: Data transfer between serial port and USB port in single PC Pin
Rick York12-Aug-09 7:03
mveRick York12-Aug-09 7:03 
QuestionC++ library for Three Dimensional data visualisation Pin
su_marvel12-Aug-09 5:23
su_marvel12-Aug-09 5:23 
AnswerRe: C++ library for Three Dimensional data visualisation Pin
Stuart Dootson12-Aug-09 6:35
professionalStuart Dootson12-Aug-09 6:35 
QuestionCAsyncSocket::Close Crashes Pin
staticv12-Aug-09 2:26
staticv12-Aug-09 2:26 
Hey, im doing some client/server stuff in a windows service. Pretty much new to this stuff using Visual C++ 6

The problem I'm encountering is that when I try to stop the service through Service Manager, it crashes. I added some MessageBoxes code, to trace where they are crashing and I found that when it closes the listener socket it crashes!!!

I tried to run the service as a console application, and by myself called the function which is called SERVICE__CONTROL__STOP event is received so that I may reproduce the bug and debug easily. But it is working fine. The windows service is only crashing when I stop it through Service Manager

Here is some code

The main function

int main(int argc, char* argv[])
{   
 // Create the service object
    CTestService CustomServiceObject;

    if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
    {
        std::cerr << "MFC failed to initialize!" << std::endl;
        return 1;
    }

    // Parse for standard arguments (install, uninstall, version etc.)
    if (! CustomServiceObject.ParseStandardArgs(argc, argv)) 
    {
        // StartService() calls ::StartServiceCtrlDispatcher() 
    // with the ServiceMain func and stuff
        CustomServiceObject.StartService();
    }

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


The Service Handler callback function
// static member function (callback) to handle commands from the
// service control manager
void CNTService::Handler(DWORD dwOpcode)
{
    // Get a pointer to the object
    CNTService* pService = m_pThis;

    pService->DebugMsg("CNTService::Handler(%lu)", dwOpcode);
    switch (dwOpcode) {
    case SERVICE_CONTROL_STOP: // 1
        pService->SetStatus(SERVICE_STOP_PENDING);
        pService->OnStop();

    // ..
    // .. 
    // other event handling
    // ..
    // ..
}


the OnStop() function
void CTestService::OnStop()
{
    m_sListener.ShutDown(2);
    m_sConnected.ShutDown(2);

    MessageBox(NULL, "After Shutdown", NULL, IDOK); 

    m_sConnected.Close();

    MessageBox(NULL, "Closed connected socket", NULL, IDOK); 

    // crashes here when I try to stop through service manager
    // but if I run as console application works fine and terminates successfully
    m_sListener.Close();

    MessageBox(NULL, "Closed listener socket", NULL, IDOK); 

    ::PostThreadMessage(m_dwThreadID, WM_QUIT, NULL, NULL);

    MessageBox(NULL, "After PostThreadMessage", NULL, IDOK);
}


Moreover, I compiled the code in in VC2008, compiled fine, without any changes and the above code was running fine as expected but only in Release build. In Debug build, I couldn't even start the service, instead got an error that the service does not respond to control requests in a timely fashion Laugh | :laugh:

Top Web Hosting Providers[^]

Do, or do not. There is no 'try'.

AnswerRe: CAsyncSocket::Close Crashes Pin
includeh1012-Aug-09 7:50
includeh1012-Aug-09 7:50 
GeneralRe: CAsyncSocket::Close Crashes Pin
staticv12-Aug-09 19:59
staticv12-Aug-09 19:59 
AnswerRe: CAsyncSocket::Close Crashes Pin
Moak13-Aug-09 13:30
Moak13-Aug-09 13:30 
GeneralRe: CAsyncSocket::Close Crashes Pin
staticv13-Aug-09 19:55
staticv13-Aug-09 19:55 
GeneralRe: CAsyncSocket::Close Crashes Pin
Moak13-Aug-09 21:44
Moak13-Aug-09 21:44 
GeneralRe: CAsyncSocket::Close Crashes Pin
staticv14-Aug-09 5:12
staticv14-Aug-09 5:12 
QuestionHow get the CPU information ? Pin
bzsolt9112-Aug-09 2:11
bzsolt9112-Aug-09 2:11 
AnswerRe: How get the CPU information ? Pin
Garth J Lancaster12-Aug-09 2:28
professionalGarth J Lancaster12-Aug-09 2:28 
GeneralRe: How get the CPU information ? Pin
bzsolt9112-Aug-09 13:15
bzsolt9112-Aug-09 13:15 
AnswerRe: How get the CPU information ? Pin
Rajesh R Subramanian12-Aug-09 2:42
professionalRajesh R Subramanian12-Aug-09 2:42 
QuestionCSocket Problem on Windows Mobile with WLAN Pin
Member 224636612-Aug-09 1:58
Member 224636612-Aug-09 1:58 
QuestionDoubleclick on MDI Frame Pin
baerten12-Aug-09 1:34
baerten12-Aug-09 1:34 
AnswerRe: Doubleclick on MDI Frame Pin
Stuart Dootson12-Aug-09 6:32
professionalStuart Dootson12-Aug-09 6:32 
QuestionInstalling a driver and Registry settings!! Pin
kapardhi12-Aug-09 0:56
kapardhi12-Aug-09 0:56 
AnswerRe: Installing a driver and Registry settings!! Pin
Randor 12-Aug-09 9:08
professional Randor 12-Aug-09 9:08 
QuestionThread Pin
susanne111-Aug-09 23:46
susanne111-Aug-09 23:46 
AnswerRe: Thread Pin
CPallini12-Aug-09 0:07
mveCPallini12-Aug-09 0:07 

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.