Home
Contents

CountryWhois SDK

 
CountryWhois SDK
About CountryWhois SDK
Using CountryWhois SDK
Functions for Obtaining the Country ID
SWAPI_IPAddressToCountryID
SWAPI_IPStringToCountryID
SWAPI_CountryCodeToCountryID
SWAPI_GetMinCountryID
SWAPI_GetMaxCountryID
Functions for Obtaining Information About a Country
SWAPI_CountryIDToCountryCode
SWAPI_CountryIDToCountryName
SWAPI_CountryIDToContinentCode
SWAPI_CountryIDToContinentName
SWAPI_GetCountryCodeStatus
SWAPI_GetCountryCodeIndex
SWAPI_EnumCountryIPRanges
EnumIPRangesProc
Functions for Obtaining the Continent ID
SWAPI_CountryIDToContinentID
SWAPI_ContinentCodeToContinentID
SWAPI_GetMinContinentID
SWAPI_GetMaxContinentID
Functions for Obtaining Information About a Continent
SWAPI_ContinentIDToContinentCode
SWAPI_ContinentIDToContinentName
SWAPI_EnumContinentIPRanges
SWAPI_EnumContinentCountries
EnumCountriesProc
Country Flags
SWAPI_GetCountryFlagBitmap
SWAPI_GetCountryFlagsImageList
SWAPI_GetCountryFlagsImageListEx
SWAPI_GetCountryFlagsImageListIndex
SWAPI_DestroyCountryFlagsImageList

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