C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 1st, 2003, 11:25 AM
amit_t amit_t is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: India
Posts: 9 amit_t User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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

Reply With Quote
  #2  
Old July 1st, 2003, 11:55 AM
infamous41md's Avatar
infamous41md infamous41md is offline
not a fan of fascism (n00b)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Feb 2003
Location: ct
Posts: 2,756 infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 11 h 4 m 29 sec
Reputation Power: 26
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.

Reply With Quote
  #3  
Old July 1st, 2003, 12:30 PM
amit_t amit_t is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: India
Posts: 9 amit_t User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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;
}

Reply With Quote
  #4  
Old July 1st, 2003, 01:11 PM
amit_t amit_t is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: India
Posts: 9 amit_t User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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;

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Help : writing a logger in C++ on XP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT