Re[2]: [Dev-C++] Network monitor - Question
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
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
|