I have a big code in c#and asp.net , it connects to IPHLPAPI.lib on windows 7 (64 bit) and return TCP and UDP connections informations in XMl,
You can see the pieces of code which stop with error in following:
#region GetTcpExTable
[DllImport("iphlpapi.dll",SetLastError=true)]
private extern static
UInt32 AllocateAndGetTcpExTableFromStack(
ref IntPtr pTcpTable,
bool bOrder,
IntPtr heap,
UInt32 zero,
UInt32 flags
);
public static CMIB_TCPEXTABLE GetTcpExTable()
{
UInt32 error_code=0;
return iphelper.GetTcpExTable(true,ref error_code);
}
public static CMIB_TCPEXTABLE GetTcpExTable(bool b_verbose,ref UInt32 error_code)
{
int BufferSize = 300*CMIB_TCPEXROW.size_ex+4;
IntPtr lpTable = Marshal.AllocHGlobal(BufferSize);
error_code= AllocateAndGetTcpExTableFromStack(ref lpTable, true, GetProcessHeap(),0,2);
if (error_code!=0)
{
if (b_verbose)
{
string str_msg=Tools.API.API_error.GetAPIErrorMessageDescription(error_code);
System.Windows.Forms.MessageBox.Show( str_msg,"Error",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Error);
}
return null;
}
int NumEntries= (int)Marshal.ReadIntPtr(lpTable);
int real_buffer_size=NumEntries*CMIB_TCPEXROW.size_ex+4;
if (BufferSize<real_buffer_size)
{
Marshal.FreeHGlobal(lpTable);
BufferSize = real_buffer_size;
lpTable = Marshal.AllocHGlobal(BufferSize);
error_code=AllocateAndGetTcpExTableFromStack(ref lpTable,true,GetProcessHeap(),0,2);
if (error_code!=0)
{
if (b_verbose)
{
string str_msg=Tools.API.API_error.GetAPIErrorMessageDescription(error_code);
System.Windows.Forms.MessageBox.Show( str_msg,"Error",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Error);
}
return null;
}
}
BufferSize=real_buffer_size;
byte[] array=new byte[BufferSize];
Marshal.Copy(lpTable,array,0,BufferSize);
Marshal.FreeHGlobal(lpTable);
CMIB_TCPEXTABLE mtet = new CMIB_TCPEXTABLE();
mtet.decode(array);
return mtet;
}
#endregion
[DllImport("iphlpapi.dll",SetLastError=true)]
public extern static
UInt32 SetTcpEntry(
ref MIB_TCPROW pTcpRow
);
The underlined code is stop with error:
"Unable to find an entry point named 'AllocateAndGetTcpExTableFromStack' in DLL 'iphlpapi.dll'."
I know that i should change the member "AllocateAndGetTcpExTableFromStack" to Newer member like "GetTcpExtendedTable" , but I do not know how to make these changes? what should i put as input/output parameters.. and what other changes I should do in other part of my code (other classes) to be worked correctly by "GetTcpExtendedTable" member?
( and I should make all these changes again for UDP part)
Your Help Will Be Appreciated.