samedi 29 août 2015

Porting the code for GetExtendedTCPTable in older c++ compilers

vector<unsigned char> buffer;    
DWORD dwRetValue = 0;
DWORD dwSize = sizeof(MIB_TCPTABLE_OWNER_PID);
struct in_addr clientAddr;
do{
    buffer.resize(dwSize, 0);
    dwRetValue = GetExtendedTcpTable(buffer.data(), &dwSize, TRUE, AF_INET,  TCP_TABLE_OWNER_PID_ALL, 0);
} while (dwRetValue == ERROR_INSUFFICIENT_BUFFER);
if (dwRetValue == ERROR_SUCCESS)
{
    PMIB_TCPTABLE_OWNER_PID ptTable = reinterpret_cast<PMIB_TCPTABLE_OWNER_PID>(buffer.data());
        //Iterate through ptTable->dwNumEntries
}

I need to initialize the vector buffer.data,it works with compilers who support C++11 but for older compilers say VS2005 this wont run.So instead of Vector i initialized it as unsigned char * buffer with dwSize as its length and passed its address as the first parameter instead of buffer.data but with no success.What am i missing? So basically the question comes down as how to effectively use vector:: data in general c++.Any help is highly appreciated.

Aucun commentaire:

Enregistrer un commentaire