|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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.
|
|
#3
|
|||
|
|||
|
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; } |
|
#4
|
|||
|
|||
|
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; |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > Help : writing a logger in C++ on XP |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|