#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    India
    Posts
    9
    Rep Power
    0

    Help : writing a logger in C++ on XP


    Hi ,

    I m trying to write a C++ program (XP) which logs the total time
    & money any user has spend on internet...the program compiles
    but it crashes...basic idea is :

    while(1) {
    /* check if connected to net */

    if(connected) {
    while(connected) {

    /* update total time & cost taken by that user */

    sleep(60000) //sleep for 60 sec

    /* check again if connected */
    }

    }

    /* write the logs to a file */

    }

    now ,is there something wrong with this???...the code is around
    200 lines ( & this is considerably long for me...so much for my
    experience in programming :()... plsss help...thanks...
    Amit
  2. #2
  3. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    well, if its crashing you should try entering it in debug mode. most likely its an access violation or similar, that's what i usually find when my programs crash. try debug mode, or post some code here.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    India
    Posts
    9
    Rep Power
    0
    here is the code (after removing unwanted garbage)...it waits
    for sometime (3-4 secs) & then crashes...thanks...

    ============================================
    #include <windows.h>
    #include <wininet.h>
    #include <winbase.h>
    #include <iostream>

    using namespace std;

    class Network {
    public:
    int CheckStatus(void);
    };

    int Network::CheckStatus(void)
    {
    DWORD dwflags;
    if(InternetGetConnectedState(&dwflags ,NULL)) {
    return 1;
    }

    else {
    return 0;
    }

    }

    int main(void)
    {
    int status;
    DWORD nSize=1024;
    LPSTR lpBuffer;
    Network N;
    while(1) {
    if(N.CheckStatus()==1) {
    status=1;
    if(GetUserName(lpBuffer , &nSize)) {
    /* do nothing */
    }

    while(status) {
    Sleep(60000);
    status=N.CheckStatus();
    }

    }
    else {
    Sleep(60000);
    }
    }
    return 0;
    }
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    India
    Posts
    9
    Rep Power
    0
    okkk...actually lpBuffer was not initialised &
    that was causing problem...(got it from MSDN
    site)...added this code & problem got solved...
    thanks anyway...

    ===============================
    TCHAR tchBuffer[1024]; // buffer for string
    lpBuffer = tchBuffer;

IMN logo majestic logo threadwatch logo seochat tools logo