请看看这个网络程序编译错误怎么解决,谢谢!!(100分)

  • 主题发起人 主题发起人 cdvoice415
  • 开始时间 开始时间
C

cdvoice415

Unregistered / Unconfirmed
GUEST, unregistred user!
网上的一个列出当前打开端口的程序,用bcb编写的,我想学一下,down下来编译
但是编译不通过[:(]
里面的一个子程序是:
//Ports.cpp
#include <vcl.h>
#include <Iphlpapi.h>
#include <Winsock.h>
#include "Ports.h"
#include "Port.h"
//------------------------------------------------------------------
//构造函数:传入一个TListView 的指针,在类的运行中,它的一些东西将会被改变。
myPorts::myPorts(TListView *T)
{
pView=T;
}
//----------------------------------------------------------------------------
myPorts::~myPorts(void)
{
}
//----------------------------------------------------------------------------
//公有函数:读取当前打开的所有TCP端口。
void myPorts::GetTCPPorts(void)
{
MIB_TCPTABLE *tcpTable=new MIB_TCPTABLE;
DWORD dwSize;
dwSize=sizeof(MIB_TCPTABLE);
GetTcpTable(tcpTable, &amp;dwSize, true);
delete tcpTable;
tcpTable=new MIB_TCPTABLE[dwSize/sizeof(MIB_TCPTABLE)];
DWORD getInfo=GetTcpTable(tcpTable, &amp;dwSize, true);
if(NO_ERROR == getInfo)
{
for(DWORD i=0;
i < tcpTable->dwNumEntries;
i++)
{
in_addr addr;
addr.S_un.S_addr=tcpTable->table.dwRemoteAddr;
char *pcRAddr=inet_ntoa(addr);
addr.S_un.S_addr=tcpTable->table.dwLocalAddr;
char *pcLAddr=inet_ntoa(addr);
DWORD LPort;
DWORD RPort;
DWORD State=tcpTable->table.dwState;
//读取实际的端口号(DWORD低字,并且是倒序):
RPort=(tcpTable->table.dwRemotePort &amp;
0xff00)/256 + (tcpTable->table.dwRemotePort &amp;
0xff)*256;
LPort=(tcpTable->table.dwLocalPort &amp;
0xff00)/256 + (tcpTable->table.dwLocalPort &amp;
0xff)*256;
TListItem *ItemTemp;
ItemTemp=pView->Items->Add();
ItemTemp->ImageIndex=0;
ItemTemp->Caption=pcLAddr;
ItemTemp->SubItems->Add(LPort);
ItemTemp->SubItems->Add("TCP");
ItemTemp->SubItems->Add(pcRAddr);
ItemTemp->SubItems->Add(RPort);
ItemTemp->SubItems->Add(GetTCPState(State));
}
}
else
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
getInfo,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &amp;
lpMsgBuf,
0,
NULL);
MessageBox(NULL, (LPCTSTR) lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION);
LocalFree(lpMsgBuf);
//ShowMessage(AnsiString("Need ") + String(dwSize) + AnsiString(",give ") + String(sizeof(MIB_TCPTABLE)));
}
delete [] tcpTable;
}
//-----------------------------------------------------------------
//公有函数:读取当前打开的所有UDP端口。
void myPorts::GetUDPPorts(void)
{
MIB_UDPTABLE *udpTable=new MIB_UDPTABLE;
DWORD dwSize;
dwSize=sizeof(MIB_UDPTABLE);
GetUdpTable(udpTable, &amp;dwSize, true);
delete udpTable;
udpTable=new MIB_UDPTABLE[dwSize/sizeof(MIB_UDPTABLE)];
DWORD getInfo=GetUdpTable(udpTable, &amp;dwSize, true);
if(NO_ERROR == getInfo)
{
for(DWORD i=0;
i < udpTable->dwNumEntries;
i++)
{
in_addr addr;
addr.S_un.S_addr=udpTable->table.dwLocalAddr;
char *pcLAddr=inet_ntoa(addr);
DWORD LPort;
//读取实际的端口号(DWORD低字,并且是倒序):
LPort=(udpTable->table.dwLocalPort &amp;
0xff00)/256 + (udpTable->table.dwLocalPort &amp;
0xff)*256;
TListItem *ItemTemp;
ItemTemp=pView->Items->Add();
ItemTemp->ImageIndex=1;
ItemTemp->Caption=pcLAddr;
ItemTemp->SubItems->Add(LPort);
ItemTemp->SubItems->Add("UDP");
ItemTemp->SubItems->Add("");
ItemTemp->SubItems->Add("");
ItemTemp->SubItems->Add("打开");
}
}
else
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
getInfo,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &amp;
lpMsgBuf,
0,
NULL);
MessageBox(NULL, (LPCTSTR) lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION);
LocalFree(lpMsgBuf);
//ShowMessage(AnsiString("Need ") + String(dwSize) + AnsiString(",give ") + String(sizeof(MIB_TCPTABLE)));
}
delete [] udpTable;
}
//------------------------------------------------------------------
//私有函数:由GetTCPPorts调用,输入TCP连接的状态代号,返回其文字意思。
AnsiString myPorts::GetTCPState(DWORD dwState)
{
switch(dwState)
{
case MIB_TCP_STATE_CLOSED: return "已关闭";
case MIB_TCP_STATE_LISTEN: return "监听";
case MIB_TCP_STATE_SYN_SENT: return "SNY 发送";
case MIB_TCP_STATE_SYN_RCVD: return "SNY 接收";
case MIB_TCP_STATE_ESTAB: return "建立连接";
case MIB_TCP_STATE_FIN_WAIT1: return "FIN 等待";
case MIB_TCP_STATE_FIN_WAIT2: return "FIN 等待";
case MIB_TCP_STATE_CLOSE_WAIT: return "等待关闭";
case MIB_TCP_STATE_CLOSING: return "正在关闭";
case MIB_TCP_STATE_LAST_ACK: return "Last ACK";
case MIB_TCP_STATE_TIME_WAIT: return "Time Wait";
case MIB_TCP_STATE_DELETE_TCB: return "Delete TCP";
default: return "";
}
}
//---------------------------------------------------------------------------
//公有函数:刷新所有打开的端口的信息
void myPorts::GetOpenPorts(void)
{
pView->Items->Clear();
GetTCPPorts();
GetUDPPorts();
}

这个程序的头文件是:
//Ports.h
#ifndef PortsH
#define PortsH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <vcl/ComCtrls.hpp>
#include <vcl/ExtCtrls.hpp>
#include <vcl/Buttons.hpp>
#include <vcl/StdCtrls.hpp>
class myPorts
{
/* */
private:
TListView *pView;
void GetTCPPorts(void);
void GetUDPPorts(void);
AnsiString GetTCPState(DWORD dwState);
/* */
public:
void GetOpenPorts(void);
myPorts(TListView *T);
~myPorts(void);
};
#endif

编译通过以后出现下面错误:
[Linker Error] Unresolved external 'GetTcpTable' referenced from E:/NET/PORT.OBJ
[Linker Error] Unresolved external 'GetUdpTable' referenced from E:/NET/PORT.OBJ
由于不知道这两个函数的意义和用法,help里面也找不到,所以不知道怎么解决
还有就是,这是我重新建立一个project再进行编译后出错
但是一开始用他原来的文件编译的时候出现: 连接不了rtl.lib的错误,请问大虾们
这些错误应该怎么解决??
不知道算不算很难,对于网络编程采鸟的我来说就一筹莫展了^_^大家帮帮忙啊

 
各个子程序的具体编程思维也不明白
各位可否随便解释一下?
thx very much!!
 
udpTable=new MIB_UDPTABLE[dwSize/sizeof(MIB_UDPTABLE)];
错误,你分配的内存不够!!!
 
喔,这样啊
那应该怎么修改啊?
还有没有其他错误啊?
这个程序不是我写的,我想编译通过以后,对原理和思维进行学习的
所以在这里请教大家
thx very much!!
 
编译时候原来的错误不见了
出现下面错误:
[Linker Error] Unresolved external 'myPorts::~myPorts()' referenced from E:/NET/TRY/PORT.OBJ
[Linker Error] Unresolved external 'myPorts::myPorts(Comctrls::TListView *)' referenced from E:/NET/TRY/PORT.OBJ
[Linker Error] Unresolved external 'myPorts::GetOpenPorts()' referenced from E:/NET/TRY/PORT.OBJ
这个自定义的类不知道怎么样出错了
救命啊!!!
 
http://www.xxtax.gov.cn/delphi/webanywhere/Qzy/GetTcp.htm
 
编译时候原来的错误不见了
出现下面错误:
[Linker Error] Unresolved external 'myPorts::~myPorts()' referenced from E:/NET/TRY/PORT.OBJ
[Linker Error] Unresolved external 'myPorts::myPorts(Comctrls::TListView *)' referenced from E:/NET/TRY/PORT.OBJ
[Linker Error] Unresolved external 'myPorts::GetOpenPorts()' referenced from E:/NET/TRY/PORT.OBJ
这种错误是由什么引起的呢??
 
后退
顶部