搞不懂的链接错,vc。net一个查看tcp网络连接的程序

freevanx 2005-04-17 04:10:57
部分源码为:

#include "stdafx.h"
#include "HttpServer.h"
#include "TcplinkDlg.h"
#include <iphlpapi.h>


// CTcplinkDlg 对话框

IMPLEMENT_DYNAMIC(CTcplinkDlg, CDialog)
CTcplinkDlg::CTcplinkDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTcplinkDlg::IDD, pParent)
{
}

CTcplinkDlg::~CTcplinkDlg()
{
}

void CTcplinkDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_TCP_LIST, m_list);
}


BEGIN_MESSAGE_MAP(CTcplinkDlg, CDialog)
END_MESSAGE_MAP()


// CTcplinkDlg 消息处理程序
BOOL CTcplinkDlg::OnInitDialog()
{
CDialog::OnInitDialog();


RECT rect;
PMIB_TCPTABLE tcpTable = NULL;
BYTE pBuffer[100*20+4];
DWORD dwTableSize = 0;
in_addr addrLoc, addrRem;

// Setup the list box
m_list.ModifyStyle(LVS_TYPEMASK, LVS_REPORT);
ListView_SetExtendedListViewStyle(m_list.m_hWnd, LVS_EX_GRIDLINES |LVS_EX_FULLROWSELECT );

m_list.DeleteAllItems();
m_list.InsertColumn(0, "本地地址");
m_list.InsertColumn(1, "本地端口");
m_list.InsertColumn(2, "远程地址");
m_list.InsertColumn(3, "远程端口");
m_list.InsertColumn(4, "连接状态");

m_list.GetWindowRect(&rect);
int nTotalX = rect.right - rect.left;

m_list.SetColumnWidth(0, nTotalX/5);
m_list.SetColumnWidth(1, nTotalX/5);
m_list.SetColumnWidth(2, nTotalX/5);
m_list.SetColumnWidth(3, nTotalX/5);
m_list.SetColumnWidth(4, nTotalX/5);


dwTableSize = 100*20+4;

// Get the TCP Table
// if the buffer is small this function returns the required size in dwTableSize
DWORD dwRet = GetTcpTable((PMIB_TCPTABLE)pBuffer, &dwTableSize, TRUE);
if(dwRet == NO_ERROR)
{
tcpTable = (PMIB_TCPTABLE)pBuffer;

for(DWORD i=0; i<tcpTable->dwNumEntries; i++)
{
char szTemp[100];
char szLocAddr[100], szRemAddr[100];

DWORD dwRemIP = htonl(tcpTable->table[i].dwRemoteAddr);
unsigned short nRemPort = htons(tcpTable->table[i].dwRemotePort);

DWORD dwLocIP = htonl(tcpTable->table[i].dwLocalAddr);
unsigned short nLocPort = htons(tcpTable->table[i].dwLocalPort);

addrLoc.S_un.S_addr = ntohl(dwLocIP);
addrRem.S_un.S_addr = ntohl(dwRemIP);

strcpy(szLocAddr, inet_ntoa(addrLoc));
strcpy(szRemAddr, inet_ntoa(addrRem));

m_list.InsertItem(i, "");
m_list.SetItemText(i, 0, szLocAddr);

sprintf(szTemp, "%u", nLocPort);
m_list.SetItemText(i, 1, szTemp);

m_list.SetItemText(i, 2, szRemAddr);

sprintf(szTemp, "%u", nRemPort);
m_list.SetItemText(i, 3, szTemp);

switch(tcpTable->table[i].dwState)
{
case MIB_TCP_STATE_CLOSED:
m_list.SetItemText(i, 4, "Closed");
break;
case MIB_TCP_STATE_LISTEN:
m_list.SetItemText(i, 4, "Listening");
break;
case MIB_TCP_STATE_SYN_SENT:
m_list.SetItemText(i, 4, "SYN Sent");
break;
case MIB_TCP_STATE_SYN_RCVD:
m_list.SetItemText(i, 4, "SYN Received");
break;
case MIB_TCP_STATE_ESTAB:
m_list.SetItemText(i, 4, "Established");
break;
case MIB_TCP_STATE_FIN_WAIT1:
m_list.SetItemText(i, 4, "Waiting for FIN");
break;
case MIB_TCP_STATE_FIN_WAIT2:
m_list.SetItemText(i, 4, "Waiting for FIN");
break;
case MIB_TCP_STATE_CLOSE_WAIT:
m_list.SetItemText(i, 4, "Waiting for Close");
break;
case MIB_TCP_STATE_CLOSING:
m_list.SetItemText(i, 4, "Closing");
break;
case MIB_TCP_STATE_LAST_ACK:
m_list.SetItemText(i, 4, "Last ACK");
break;
case MIB_TCP_STATE_TIME_WAIT:
m_list.SetItemText(i, 4, "Time Wait");
break;
case MIB_TCP_STATE_DELETE_TCB:
m_list.SetItemText(i, 4, "TCB deleted");
break;
default:
m_list.SetItemText(i, 4, "Unknown status");

}
}
}
else
{
m_list.SetItemText(0, 0, "Unable to get TCP Connections");
}

UpdateData(FALSE);

return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}

错误提示为:
TcplinkDlg.obj : error LNK2019: 无法解析的外部符号 _GetTcpTable@12 ,该符号在函数 "protected: virtual int __thiscall CTcplinkDlg::OnInitDialog(void)" (?OnInitDialog@CTcplinkDlg@@MAEHXZ) 中被引用

.\Debug/HttpServer.exe : fatal error LNK1120: 1 个无法解析的外部命令

...全文
130 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
oyljerry 2005-04-20
iphlpapi.lib这个库文件是否加入project
回复
freevanx 2005-04-20
那怎样才能使用这个lib库呢?
有一个同样的参考程序能够顺利编译
回复
oyljerry 2005-04-17
缺少对应的lib库文件
回复
相关推荐
发帖
VC.NET
创建于2007-09-28

7540

社区成员

.NET技术 VC.NET
申请成为版主
帖子事件
创建了帖子
2005-04-17 04:10
社区公告
暂无公告