mfc 如何获取本地连接的收发字节数
我用GetIfEntry()、 GetIfTable()中dwInOctets、dwOutOctets
得到的值和本地连接的收发字节数完全不一致
请问该如何统计呢???

解决方案 »

  1.   

    #include <windows.h> 
    #include <iphlpapi.h> 
    #include <stdio.h> #pragma comment ( lib, "iphlpapi.lib" ) int main( void ) 

    MIB_IFTABLE *pIfTable = NULL; 
    ULONG dwSize = 0; 

    DWORD dwRet; 

    printf( "This program try to get the speed of a modem by using GetIfTable()\n" ); 

    dwRet = GetIfTable( pIfTable, &dwSize, TRUE ); 
    if ( dwRet == ERROR_INSUFFICIENT_BUFFER ) 

    pIfTable = ( MIB_IFTABLE * ) new char[dwSize]; 

    if ( pIfTable != NULL ) 

    dwRet = GetIfTable( pIfTable, &dwSize, TRUE ); 
    if ( dwRet == NO_ERROR ) 

    printf( "dwNumEntries = %u\n", pIfTable->dwNumEntries ); 

    for ( int i=0; i<pIfTable->dwNumEntries; i++ ) 

    printf( "table[%1d].dwIndex = %u\n", 
    i, 
    (pIfTable->table[i]).dwIndex ); 
    printf( " dwType = %u\n", 
    (pIfTable->table[i]).dwType ); 
    printf( " dwSpeed = %u\n", 
    (pIfTable->table[i]).dwSpeed ); 


    else 

    printf( "Some error occured!\n" ); 


    else 

    printf( "Memory allocate failue\n" ); 


    else 

    printf( "Some error occured!\n" ); 


    getchar();
    return 0; 
    }