N
niuqi31
Unregistered / Unconfirmed
GUEST, unregistred user!
我根据前人的知识将获得本机IP地址的函数(delphi)改成了BCB5中可以调用的函数.
我遇到了两个问题:1函数名不能封装到Form类里;
2:在Form的Active或Create不能调用该函数,放在Button里可以.[].
现附上函数,请各位帮忙,看一下是什么问题.
#include <WinSock.hpp> // Pascal unit
void GetComputerNameAndIP(void)
{
WORD wVersionRequested;//: WORD;
TWSAData wsaData ;
PHostEnt p;//: ;
char s[128];
char *p2;
AnsiString OutPut;
// {Start up WinSock}
wVersionRequested = MAKEWORD(1, 1);
WSAStartup(wVersionRequested, &wsaData);
// {Get the computer name}
gethostbyname((char *)&s);
p = gethostbyname(s);
// {Get the IpAddress}
if (p!=NULL){
p2 = inet_ntoa(*(PInAddr(*p->h_addr_list)));
MainFrom->dkh->Caption=StrPas(p->h_name);
MainFrom->btl->Caption=StrPas(p2);
}
WSACleanup;
}
我遇到了两个问题:1函数名不能封装到Form类里;
2:在Form的Active或Create不能调用该函数,放在Button里可以.[].
现附上函数,请各位帮忙,看一下是什么问题.
#include <WinSock.hpp> // Pascal unit
void GetComputerNameAndIP(void)
{
WORD wVersionRequested;//: WORD;
TWSAData wsaData ;
PHostEnt p;//: ;
char s[128];
char *p2;
AnsiString OutPut;
// {Start up WinSock}
wVersionRequested = MAKEWORD(1, 1);
WSAStartup(wVersionRequested, &wsaData);
// {Get the computer name}
gethostbyname((char *)&s);
p = gethostbyname(s);
// {Get the IpAddress}
if (p!=NULL){
p2 = inet_ntoa(*(PInAddr(*p->h_addr_list)));
MainFrom->dkh->Caption=StrPas(p->h_name);
MainFrom->btl->Caption=StrPas(p2);
}
WSACleanup;
}