看看我的程序!!!
Uses WinSock;Function GetLocalIPAddress : String;
Var
WSAData : TWSAData;
HostName : Array[ 1 .. 32 ] Of Char;
HostInfo : PHostEnt;
I : Integer;
Begin
Result := '';
If( WSAStartUp( 2, WSAData ) = 0 ) Then
Begin
If( GetHostName( @HostName[ 1 ], 32 ) = 0 ) Then
Begin
HostInfo := GetHostByName( @HostName[ 1 ] );
If( Hostinfo <> Nil ) Then
Begin
For I := 1 To 4 Do
Begin
Result := Result + IntToStr( Ord( HostInfo.h_addr^[ I - 1 ] ) );
If( I < 4 ) Then Result := Result + '.';
End;
End;
End;
End;
WSACleanup;
End;
Uses WinSock;Function GetLocalIPAddress : String;
Var
WSAData : TWSAData;
HostName : Array[ 1 .. 32 ] Of Char;
HostInfo : PHostEnt;
I : Integer;
Begin
Result := '';
If( WSAStartUp( 2, WSAData ) = 0 ) Then
Begin
If( GetHostName( @HostName[ 1 ], 32 ) = 0 ) Then
Begin
HostInfo := GetHostByName( @HostName[ 1 ] );
If( Hostinfo <> Nil ) Then
Begin
For I := 1 To 4 Do
Begin
Result := Result + IntToStr( Ord( HostInfo.h_addr^[ I - 1 ] ) );
If( I < 4 ) Then Result := Result + '.';
End;
End;
End;
End;
WSACleanup;
End;
解决方案 »
- 关于div 的问题
- 如何截取字符串最后一个空格前的部分?
- 我在非技术区发的帖子怎么自己找不到啊?就是想告诉大家,海淀书城外面这十天有很多计算机方面的打折书促销到5号
- 散分:如何在form上显示一个excel表格
- 太奇怪了,关于查询的问题(在线等......)。
- 简单问题,进者有分!
- 精度和小数宽度到底什么意思?
- 如何把一个不可见字符和一段字符串同时写入文本文件?
- 请newyj(老鬼)和wbamboo(波波)两位大侠说清楚!
- Delphi 4编程内幕的例子delphi 5.0编译不过
- #####有关数据精度的问题,请大家来看看!!(一定给分)######
- 对一个函数的使用,请各位大虾指教!一定给分!!!
Uses WinSock;Function GetLocalIPAddress : String;
Var
WSAData : TWSAData;
HostName : Array[ 1 .. 32 ] Of Char;
HostInfo : PHostEnt;
I : Integer;
Begin
Result := '';
If( WSAStartUp( 2, WSAData ) = 0 ) Then
Begin
If( GetHostName( @HostName[ 1 ], 32 ) = 0 ) Then
Begin
HostInfo := GetHostByName( @HostName[ 1 ] );
If( Hostinfo <> Nil ) Then
Begin
For I := 1 To 4 Do
Begin
Result := Result + IntToStr( Ord( HostInfo.h_addr^[ I - 1 ] ) );
If( I < 4 ) Then Result := Result + '.';
End;
End;
End;
End;
WSACleanup;
End;
Uses WinSock;Function GetLocalIPAddress : String;
Var
WSAData : TWSAData;
HostName : Array[ 1 .. 32 ] Of Char;
HostInfo : PHostEnt;
I : Integer;
Begin
Result := '';
If( WSAStartUp( 2, WSAData ) = 0 ) Then
Begin
If( GetHostName( @HostName[ 1 ], 32 ) = 0 ) Then
Begin
HostInfo := GetHostByName( @HostName[ 1 ] );
If( Hostinfo <> Nil ) Then
Begin
For I := 1 To 4 Do
Begin
Result := Result + IntToStr( Ord( HostInfo.h_addr^[ I - 1 ] ) );
If( I < 4 ) Then Result := Result + '.';
End;
End;
End;
End;
WSACleanup;
End;
不过我use Winsock;
msdn里说WSAStartup的第一个参数是:
wVersionRequested
[in] Highest version of Windows Sockets support that the caller can use. The high-order byte specifies the minor version (revision) number; the low-order byte specifies the major version number.
如果初始化成功,返回0;否则返回的是 ERROR CODESThe Windows Sockets WSAStartup function initiates use of the Windows Sockets DLL by a process.int WSAStartup (
WORD wVersionRequested,
LPWSADATA lpWSAData
);
Parameters
wVersionRequested
[in] The highest version of Windows Sockets support that the caller can use. The high order byte specifies the minor version (revision) number; the low-order byte specifies the major version number.
lpWSAData
[out] A pointer to the WSADATA data structure that is to receive details of the Windows Sockets implementation.
Res
This function must be the first Windows Sockets function called by an application or DLL. It allows an application or DLL to specify the version of Windows Sockets required and to retrieve details of the specific Windows Sockets implementation. The application or DLL may only issue further Windows Sockets functions after a successful WSAStartup invocation.
In order to support future Windows Sockets implementations and applications which may have functionality differences from current version of Windows Sockets, a negotiation takes place in WSAStartup. The caller of WSAStartup and the Windows Sockets DLL indicate to each other the highest version that they can support, and each confirms that the other's highest version is acceptable. Upon entry to WSAStartup, the Windows Sockets DLL examines the version requested by the application. If this version is equal to or higher than the lowest version supported by the DLL, the call succeeds and the DLL returns in wHighVersion the highest version it supports and in wVersion the minimum of its high version and wVersionRequested. The Windows Sockets DLL then assumes that the application will use wVersion. If the wVersion field of the WSADATA structure is unacceptable to the caller, it should call WSACleanup and either search for another Windows Sockets DLL or fail to initialize.
This negotiation allows both a Windows Sockets DLL and a Windows Sockets application to support a range of Windows Sockets versions. An application can successfully utilize a Windows Sockets DLL if there is any overlap in the version ranges. The following chart gives examples of how WSAStartup works in conjunction with different application and Windows Sockets DLL versions:
App versions DLL Versions wVersion
Requested wVersion wHigh
Version End Result
1.1 1.1 1.1 1.1 1.1 use 1.1
1.0 1.1 1.0 1.1 1.0 1.0 use 1.0
1.0 1.0 1.1 1.0 1.0 1.1 use 1.0
1.1 1.0 1.1 1.1 1.1 1.1 use 1.1
1.1 1.0 1.1 1.0 1.0 Application fails
1.0 1.1 1.0 --- --- WSAVERNOT
SUPPORTED
1.0 1.1 1.0 1.1 1.1 1.1 1.1 use 1.1
1.1 2.0 1.1 2.0 1.1 1.1 use 1.1
2.0 2.0 2.0 2.0 2.0 use 2.0
The following code fragment demonstrates how an application which supports only version 2 of Windows Sockets makes a WSAStartup call:
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 0 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
/* Tell the user that we couldn't find a usable */
/* WinSock DLL. */
return;
/* Confirm that the WinSock DLL supports 2.0.*/
/* Note that if the DLL supports versions greater */
/* than 2.0 in addition to 2.0, it will still return */
/* 2.0 in wVersion since that is the version we */
/* requested. */
if ( LOBYTE( wsaData.wVersion ) != 2 ||
HIBYTE( wsaData.wVersion ) != 0 ) {
/* Tell the user that we couldn't find a usable */
/* WinSock DLL. */
WSACleanup( );
return;
}