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_IPAddressToCountryID

This function returns the country ID corresponding to the given IP address.

Syntax

Microsoft Visual C++
WORD __stdcall SWAPI_IPAddressToCountryID(
  DWORD IPAddress,
  DWORD IPFlags
);
Borland Delphi
function SWAPI_IPAddressToCountryID(
  const IPAddress: DWORD;
  const IPFlags: DWORD
): WORD; stdcall;
Microsoft Visual Basic
Declare Function SWAPI_IPAddressToCountryID Lib "swapimap.dll" (
  ByVal IPAddress As Long,
  ByVal IPFlags As Long
) As Integer

Parameters

IPAddress
[in] IP address stored in network byte order.
IPFlags
[in] Reserved parameter, must be set to zero.

Return Value

If the country ID is found for the given IP address, the return value is 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, the return value is zero, which is not an error but rather an indication that currently, the supplied IP address is unallocated.

Sample Code

Microsoft Visual C++
DWORD IPAddress;
WORD CountryID;
static CHAR result[65];
CString CountryName;
int i;

IPAddress = 69956104;
CountryID = SWAPI_IPAddressToCountryID(IPAddress, 0);
if (CountryID == 0) {
  CountryName = "Unknown";
}
else {
  i = SWAPI_CountryIDToCountryName(CountryID, result, 64);
  result[i] = 0;
  CountryName = result;
}
AfxMessageBox(Country);
Borland Delphi
var
  IPAddress: DWORD;
  CountryID: WORD;
  CountryName: string;
begin
  IPAddress := 69956104;
  CountryID := SWAPI_IPAddressToCountryID(IPAddress, 0);
  if (CountryID = 0) then
    CountryName := 'Unknown'
  else
  begin
    SetLength(CountryName, 64);
    SetLength(CountryName, SWAPI_CountryIDToCountryName(CountryID,
      Pointer(CountryName), 64));
  end;
  ShowMessage(CountryName);
end;
Microsoft Visual Basic
Dim res As String * 64
IPAddress = 69956104
CountryID = SWAPI_IPAddressToCountryID(IPAddress, 0)
if (CountryID = 0) then
  CountryName = "Unknown"
else
  i = SWAPI_CountryIDToCountryName(CountryID, res, 64)
  CountryName = Mid$(res, 1, i)
End if
MsgBox(CountryName)

Defined In

Microsoft Visual C++
SWAPIMap.h, SWAPIMap.cpp
Borland Delphi
SWAPIMap.pas
Microsoft Visual Basic
SWAPIMap.bas

See Also

SWAPI_IPStringToCountryID
SWAPI_GetMinCountryID
SWAPI_GetMaxCountryID


Copyright © 2006-2008, TamoSoft