| |
 |
SWAPI_IPStringToCountryID
This function returns the country ID corresponding to the given IP address string.
Syntax
| Microsoft Visual C++ |
BOOL _stdcall SWAPI_IPStringToCountryID( PCHAR IPString, WORD* CountryID ); |
|
| Borland Delphi |
function SWAPI_IPStringToCountryID( const IPString: PChar; var CountryID: WORD ): BOOL; stdcall; |
|
| Microsoft Visual Basic |
Declare Function SWAPI_IPStringToCountryID Lib "swapimap.dll" ( ByVal IPString As String, ByRef CountryID As Integer ) As Boolean |
|
Parameters
| IPString |
[in] Pointer to the null-terminated IP address string in dotted notation. |
| CountryID |
| [out] Pointer to a variable that receives the country ID that corresponds to the IP address passed in the IPString parameter. |
Return Value
If the function succeeds, the return value is non-zero. In this case, CountryID contains a non-zero country ID, the value of which is within the boundaries returned by SWAPI_GetMinCountryID and SWAPI_GetMaxCountryID. If the country ID is not found for the given IP address string, the CountryID value is zero, which is not an error but rather an indication that currently the supplied IP address is unallocated.
If the function fails, the return value is zero. The error indicates that the supplied IPString parameter contains an invalid IP address string.
Sample Code
| Microsoft Visual C++ |
WORD CountryID; CString IPString, CountryName; static CHAR result[65]; int i;
IPString = "9.255.255.255"; if (!SWAPI_IPAddressToCountryID(PChar(IPString), CountryID)) { AfxMessageBox("Invalid IP address!"); } else { if (CountryID == 0) { CountryName = "Unknown"; } else { i = SWAPI_CountryIDToCountryName(CountryID, result, 64); result[i] = 0; CountryName = result; } AfxMessageBox(CountryName); } |
|
| Borland Delphi |
var CountryID: WORD; IPString, CountryName: string; begin IPString := '9.255.255.255'; if (not SWAPI_IPAddressToCountryID(PChar(IPString), CountryID)) then ShowMessage('Invalid IP address!') else begin if (CountryID = 0) then CountryName := 'Unknown' else begin SetLength(CountryName, 64); SetLength(CountryName, SWAPI_CountryIDToCountryName(CountryID, Pointer(CountryName), 64)); end; ShowMessage(CountryName); end; end; |
|
| Microsoft Visual Basic |
Dim res As String * 64 IPString = "9.255.255.255" If Not SWAPI_IPAddressToCountryID(IPString, CountryID) Then MsgBox("Invalid IP address!") else if (CountryID = 0) then CountryName = "Unknown" else i = SWAPI_CountryIDToCountryName(CountryID, res, 64) CountryName = Mid$(res, 1, i) End if MsgBox(CountryName) End if |
|
Defined In
| Microsoft Visual C++ |
| SWAPIMap.h, SWAPIMap.cpp |
|
| Borland Delphi |
| SWAPIMap.pas |
|
| Microsoft Visual Basic |
| SWAPIMap.bas |
|
See Also
SWAPI_IPAddressToCountryID SWAPI_GetMinCountryID SWAPI_GetMaxCountryID
Copyright © 2006-2008, TamoSoft
|