Thread: Re: [Dev-C++] Network monitor - Question
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Daniel G. <sp...@ho...> - 2003-04-07 14:21:39
|
Hi, this was perfect for me and I didn't even ask the question! However there is something I'm having trouble with relating to this set of functions. I'm using VC++ (boo! lol) and using MFC I've built a dialog-based app that gets info with GetIfTable() and some others. One of these functions is GetIpNetTable() which gets the ARP table. The problem is this - after much debugging I find that when I call GetIpNetTable() the window handle becomes 0 !!!! So while everywhere else I can call SetDlgItemText() to put the buffer contents into an edit box, I now get Assert errors (even if I try to exit the function!) because hwnd is 0! Has anyone heard of this? I've not found it on google. Daniel >From: Zodiaq <zo...@ac...> >Reply-To: Zodiaq <zo...@ac...> >To: Dev...@li... >Subject: Re: [Dev-C++] Network monitor >Date: Sun, 6 Apr 2003 18:13:13 +0200 > >Hello Lambdabit and all Dev-C++ users, > >Sunday, April 6, 2003, 4:33:46 PM, Lambdabit wrote as follows: > >LJGS> how can I get the speed of my net interface's connection and the >packages sent and received? > >By calling Win32 API function named GetIfTable you get CURRENT bytes >sent and received for every interface (including loopback)... if you >call this function every 1sec (using timer) you can easly obtain speed >in bytes... but remember that this gives you total network load - >every byte of packets counts... >for more info and examples check msdn.microsoft.com > >LJGS> Thanks! > >-- >regards, Zodiaq > > > >------------------------------------------------------- >This SF.net email is sponsored by: ValueWeb: >Dedicated Hosting for just $79/mo with 500 GB of bandwidth! >No other company gives more support or power for your dedicated server >http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/ >_______________________________________________ >Dev-cpp-users mailing list >Dev...@li... >TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users _________________________________________________________________ Get Hotmail on your mobile phone http://www.msn.co.uk/mobile |
|
From: Daniel G. <sp...@ho...> - 2003-04-07 14:51:13
|
Quick response! I just logged back on to say I found a solution - and it sounds like you have found the reason. I put a watch on m_hWnd and after calling the function it said the expression could not be evaluated. I had allocated the buffer wrongly! unsigned long Buffer = 420; // wrong unsigned long Buffer[420]; // Horay! So it seems the buffer was overwritten, and the variable m_hWnd was overwritten! Does that seem right? >From: Per Westermark <pw...@ia...> >To: Daniel Glenfield <sp...@ho...> >CC: zo...@ac..., <Dev...@li...> >Subject: Re: [Dev-C++] Network monitor - Question >Date: Mon, 7 Apr 2003 17:38:05 +0200 (CEST) > >DWORD GetIpNetTable( > PMIB_IPNETTABLE pIpNetTable, // buffer for mapping table > PULONG pdwSize, // size of buffer > BOOL bOrder // sort by IP address >); > >Are you setting your dwSize to the size of the buffer before calling >GetIpNetTable()? Else the call might overwrite the buffer, and thereby >destroy other variables in your program. > >/Per W > >On Mon, 7 Apr 2003, Daniel Glenfield wrote: > > > > > > > Hi, this was perfect for me and I didn't even ask the question! However > > there is something I'm having trouble with relating to this set of > > functions. > > > > I'm using VC++ (boo! lol) and using MFC I've built a dialog-based app >that > > gets info with GetIfTable() and some others. One of these functions is > > GetIpNetTable() which gets the ARP table. > > > > The problem is this - after much debugging I find that when I call > > GetIpNetTable() the window handle becomes 0 !!!! So while everywhere >else I > > can call SetDlgItemText() to put the buffer contents into an edit box, I >now > > get Assert errors (even if I try to exit the function!) because hwnd is >0! > > > > Has anyone heard of this? I've not found it on google. > > > > Daniel > > > > > > > > > > >From: Zodiaq <zo...@ac...> > > >Reply-To: Zodiaq <zo...@ac...> > > >To: Dev...@li... > > >Subject: Re: [Dev-C++] Network monitor > > >Date: Sun, 6 Apr 2003 18:13:13 +0200 > > > > > >Hello Lambdabit and all Dev-C++ users, > > > > > >Sunday, April 6, 2003, 4:33:46 PM, Lambdabit wrote as follows: > > > > > >LJGS> how can I get the speed of my net interface's connection and the > > >packages sent and received? > > > > > >By calling Win32 API function named GetIfTable you get CURRENT bytes > > >sent and received for every interface (including loopback)... if you > > >call this function every 1sec (using timer) you can easly obtain speed > > >in bytes... but remember that this gives you total network load - > > >every byte of packets counts... > > >for more info and examples check msdn.microsoft.com > > > > > >LJGS> Thanks! > > > > > >-- > > >regards, Zodiaq > > > > > > > > > > > >------------------------------------------------------- > > >This SF.net email is sponsored by: ValueWeb: > > >Dedicated Hosting for just $79/mo with 500 GB of bandwidth! > > >No other company gives more support or power for your dedicated server > > >http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/ > > >_______________________________________________ > > >Dev-cpp-users mailing list > > >Dev...@li... > > >TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > > >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > > > > _________________________________________________________________ > > Get Hotmail on your mobile phone http://www.msn.co.uk/mobile > > > > > > > > ------------------------------------------------------- > > This SF.net email is sponsored by: ValueWeb: > > Dedicated Hosting for just $79/mo with 500 GB of bandwidth! > > No other company gives more support or power for your dedicated server > > http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/ > > _______________________________________________ > > Dev-cpp-users mailing list > > Dev...@li... > > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > > > >------------------------------------------------------- >This SF.net email is sponsored by: ValueWeb: >Dedicated Hosting for just $79/mo with 500 GB of bandwidth! >No other company gives more support or power for your dedicated server >http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/ >_______________________________________________ >Dev-cpp-users mailing list >Dev...@li... >TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users _________________________________________________________________ Get Hotmail on your mobile phone http://www.msn.co.uk/mobile |
|
From: Per W. <pw...@ia...> - 2003-04-07 15:11:11
|
Problem found, case closed :-) /Per W On Mon, 7 Apr 2003, Daniel Glenfield wrote: > > Quick response! > > I just logged back on to say I found a solution - and it sounds like you > have found the reason. > > I put a watch on m_hWnd and after calling the function it said the > expression could not be evaluated. I had allocated the buffer wrongly! > > unsigned long Buffer = 420; // wrong > unsigned long Buffer[420]; // Horay! > > So it seems the buffer was overwritten, and the variable m_hWnd was > overwritten! > > Does that seem right? > > > >From: Per Westermark <pw...@ia...> > >To: Daniel Glenfield <sp...@ho...> > >CC: zo...@ac..., <Dev...@li...> > >Subject: Re: [Dev-C++] Network monitor - Question > >Date: Mon, 7 Apr 2003 17:38:05 +0200 (CEST) > > > >DWORD GetIpNetTable( > > PMIB_IPNETTABLE pIpNetTable, // buffer for mapping table > > PULONG pdwSize, // size of buffer > > BOOL bOrder // sort by IP address > >); > > > >Are you setting your dwSize to the size of the buffer before calling > >GetIpNetTable()? Else the call might overwrite the buffer, and thereby > >destroy other variables in your program. > > > >/Per W > > > >On Mon, 7 Apr 2003, Daniel Glenfield wrote: > > > > > > > > > > > Hi, this was perfect for me and I didn't even ask the question! However > > > there is something I'm having trouble with relating to this set of > > > functions. > > > > > > I'm using VC++ (boo! lol) and using MFC I've built a dialog-based app > >that > > > gets info with GetIfTable() and some others. One of these functions is > > > GetIpNetTable() which gets the ARP table. > > > > > > The problem is this - after much debugging I find that when I call > > > GetIpNetTable() the window handle becomes 0 !!!! So while everywhere > >else I > > > can call SetDlgItemText() to put the buffer contents into an edit box, I > >now > > > get Assert errors (even if I try to exit the function!) because hwnd is > >0! > > > > > > Has anyone heard of this? I've not found it on google. > > > > > > Daniel > > > > > > > > > > > > > > > >From: Zodiaq <zo...@ac...> > > > >Reply-To: Zodiaq <zo...@ac...> > > > >To: Dev...@li... > > > >Subject: Re: [Dev-C++] Network monitor > > > >Date: Sun, 6 Apr 2003 18:13:13 +0200 > > > > > > > >Hello Lambdabit and all Dev-C++ users, > > > > > > > >Sunday, April 6, 2003, 4:33:46 PM, Lambdabit wrote as follows: > > > > > > > >LJGS> how can I get the speed of my net interface's connection and the > > > >packages sent and received? > > > > > > > >By calling Win32 API function named GetIfTable you get CURRENT bytes > > > >sent and received for every interface (including loopback)... if you > > > >call this function every 1sec (using timer) you can easly obtain speed > > > >in bytes... but remember that this gives you total network load - > > > >every byte of packets counts... > > > >for more info and examples check msdn.microsoft.com > > > > > > > >LJGS> Thanks! > > > > > > > >-- > > > >regards, Zodiaq > > > > > > > > > > > > > > > >------------------------------------------------------- > > > >This SF.net email is sponsored by: ValueWeb: > > > >Dedicated Hosting for just $79/mo with 500 GB of bandwidth! > > > >No other company gives more support or power for your dedicated server > > > >http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/ > > > >_______________________________________________ > > > >Dev-cpp-users mailing list > > > >Dev...@li... > > > >TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > > > >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > > > > > > > _________________________________________________________________ > > > Get Hotmail on your mobile phone http://www.msn.co.uk/mobile > > > > > > > > > > > > ------------------------------------------------------- > > > This SF.net email is sponsored by: ValueWeb: > > > Dedicated Hosting for just $79/mo with 500 GB of bandwidth! > > > No other company gives more support or power for your dedicated server > > > http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/ > > > _______________________________________________ > > > Dev-cpp-users mailing list > > > Dev...@li... > > > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > > > > > > > > >------------------------------------------------------- > >This SF.net email is sponsored by: ValueWeb: > >Dedicated Hosting for just $79/mo with 500 GB of bandwidth! > >No other company gives more support or power for your dedicated server > >http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/ > >_______________________________________________ > >Dev-cpp-users mailing list > >Dev...@li... > >TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > _________________________________________________________________ > Get Hotmail on your mobile phone http://www.msn.co.uk/mobile > > |
|
From: Zodiaq <zo...@ac...> - 2003-04-07 15:39:09
|
Hello Daniel and all Dev-C++ users,
Monday, April 7, 2003, 4:51:04 PM, Daniel wrote as follows:
DG> unsigned long Buffer = 420; // wrong
LOL! Totally wrong...
DG> unsigned long Buffer[420]; // Horay!
hmmm... you are allocating 420 items of size long... and long is AFAIR
32... nevermind, better is to do it like this:
this is howto for using GetIfTable, but GetIpNetTable is extremly
similar...
PMIB_IFTABLE interfaces = NULL;
DWORD response = GetIfTable( interfaces, &ulRozmiar, FALSE );
if( response == ERROR_INSUFFICIENT_BUFFER )
{
//cout << "Recommended size: " << ulRozmiar << endl;
if (!(interfaces = (PMIB_IFTABLE)malloc(ulRozmiar))) {
//cout << "Insufficient Memory" << endl;
MessageBox( Hwnd, "Damn, not enough memory!", "Buuuuu", MB_OK | MB_ICONINFORMATION );
PostQuitMessage( 1 );
return FALSE;
}
response = GetIfTable( interfaces, &ulRozmiar, FALSE );
}
else if( response == ERROR_NOT_SUPPORTED )
{
MessageBox( Hwnd, "Main program function not supported on this platform", "Błąd...", MB_OK | MB_ICONERROR );
PostQuitMessage( 1 );
return FALSE;
}
if( response != NO_ERROR )
{
MessageBox( Hwnd, "Some straaaange error", "Buuuuu", MB_OK | MB_ICONINFORMATION );
PostQuitMessage( 1 );
return FALSE;
}
GetIfTable( interfaces, &ulRozmiar, FALSE );
and now my program remebers that enough memory has been allocated, and
in next calls to obtain new send and received bytes I just use last
line... (ulRozmiar I made global, as interfaces)
DG> So it seems the buffer was overwritten, and the variable m_hWnd was
DG> overwritten!
DG> Does that seem right?
--
regards, Zodiaq
|
|
From: Per W. <pw...@ia...> - 2003-04-07 14:39:25
|
DWORD GetIpNetTable( PMIB_IPNETTABLE pIpNetTable, // buffer for mapping table PULONG pdwSize, // size of buffer BOOL bOrder // sort by IP address ); Are you setting your dwSize to the size of the buffer before calling GetIpNetTable()? Else the call might overwrite the buffer, and thereby destroy other variables in your program. /Per W On Mon, 7 Apr 2003, Daniel Glenfield wrote: > > > Hi, this was perfect for me and I didn't even ask the question! However > there is something I'm having trouble with relating to this set of > functions. > > I'm using VC++ (boo! lol) and using MFC I've built a dialog-based app that > gets info with GetIfTable() and some others. One of these functions is > GetIpNetTable() which gets the ARP table. > > The problem is this - after much debugging I find that when I call > GetIpNetTable() the window handle becomes 0 !!!! So while everywhere else I > can call SetDlgItemText() to put the buffer contents into an edit box, I now > get Assert errors (even if I try to exit the function!) because hwnd is 0! > > Has anyone heard of this? I've not found it on google. > > Daniel > > > > > >From: Zodiaq <zo...@ac...> > >Reply-To: Zodiaq <zo...@ac...> > >To: Dev...@li... > >Subject: Re: [Dev-C++] Network monitor > >Date: Sun, 6 Apr 2003 18:13:13 +0200 > > > >Hello Lambdabit and all Dev-C++ users, > > > >Sunday, April 6, 2003, 4:33:46 PM, Lambdabit wrote as follows: > > > >LJGS> how can I get the speed of my net interface's connection and the > >packages sent and received? > > > >By calling Win32 API function named GetIfTable you get CURRENT bytes > >sent and received for every interface (including loopback)... if you > >call this function every 1sec (using timer) you can easly obtain speed > >in bytes... but remember that this gives you total network load - > >every byte of packets counts... > >for more info and examples check msdn.microsoft.com > > > >LJGS> Thanks! > > > >-- > >regards, Zodiaq > > > > > > > >------------------------------------------------------- > >This SF.net email is sponsored by: ValueWeb: > >Dedicated Hosting for just $79/mo with 500 GB of bandwidth! > >No other company gives more support or power for your dedicated server > >http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/ > >_______________________________________________ > >Dev-cpp-users mailing list > >Dev...@li... > >TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > _________________________________________________________________ > Get Hotmail on your mobile phone http://www.msn.co.uk/mobile > > > > ------------------------------------------------------- > This SF.net email is sponsored by: ValueWeb: > Dedicated Hosting for just $79/mo with 500 GB of bandwidth! > No other company gives more support or power for your dedicated server > http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/ > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |