| |
 |
SWAPI_EnumCountryIPRanges
This function enumerates the IP address ranges of the given country by passing the information on the range borders one by one to an application-defined callback function. The function doesn't return until all the IP ranges of the given country are enumerated or the callback function returns FALSE.
Syntax
| Microsoft Visual C++ |
BOOL __stdcall SWAPI_EnumCountryIPRanges( WORD CountryID, EnumIPRangesProc EnumProc, DWORD IPFlags, DWORD UserData ); |
|
| Borland Delphi |
function SWAPI_EnumCountryIPRanges( const CountryID: WORD; const EnumProc: TEnumIPRangesProc; const IPFlags: DWORD; const UserData: DWORD ): BOOL; stdcall; |
|
| Microsoft Visual Basic |
Declare Function SWAPI_EnumCountryIPRanges Lib "swapimap.dll" ( ByVal CountryID As Integer, ByVal EnumProc As long, ByVal IPFlags As Long, ByRef UserData As Any ) As Boolean |
|
Parameters
| CountryID |
[in] Country ID retrieved by using the functions for obtaining the country ID. |
| EnumProc |
[in] Pointer to an application-defined callback function. For more information, see EnumIPRangesProc. |
| IPFlags |
[in] Reserved parameter, must be set to zero. |
| UserData |
| [in] Specifies an application-defined value to be passed to the callback function. |
Return Value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero.
Remarks
The ranges are passed to the callback function in ascending order.
Sample Code
| Microsoft Visual C++ |
CString IPToStr(DWORD IP) { CString str; str.Format("%d.%d.%d.%d", IP & 0xFF, (IP >> 8) & 0xFF, (IP >> 16) & 0xFF, (IP >> 24) & 0xFF); return str; }
BOOL __stdcall FillIPRangesProc(WORD CountryID, DWORD RangeBegin, DWORD RangeEnd, DWORD UserData) { CListBox *lb = (CListBox *)UserData; lb->AddString(IPToStr(RangeBegin) + " - " + IPToStr(RangeEnd)); return TRUE; }
void CMainDlg::ListRanges(WORD CountryID) { m_cRangeList.ResetContent(); SWAPI_EnumCountryIPRanges(CountryID, &FillIPRangesProc, 0, (DWORD)&m_cRangeList); m_cRangeList.UpdateWindow(); } |
|
| Borland Delphi |
function IPToStr(const IP: DWORD): string; begin Result := Format('%d.%d.%d.%d', [(IP shl 24) shr 24, (IP shl 16) shr 24, (IP shl 8) shr 24, IP shr 24]); end;
function EnumIPRangesProc(const CountryID: WORD; const RangeBegin, RangeEnd, UserData: DWORD): BOOL; stdcall; begin Result := True; TMemo(UserData).Lines.Add(IPToStr(RangeBegin) + '-' + IPToStr(RangeEnd)); end;
procedure TMainForm.ListRanges(const CountryID: WORD); begin Memo1.Lines.BeginUpdate; try Memo1.Clear; SWAPI_EnumCountryIPRanges(CountryID, EnumIPRangesProc, 0, DWORD(Memo1)); finally Memo1.Lines.EndUpdate; end; end; |
|
| Microsoft Visual Basic |
'Module Public Type myBytes B1 As Byte B2 As Byte B3 As Byte B4 As Byte End Type
Public Type myLong Val As Long End Type
Function IPToStr(ByVal IP As Long) As String Dim L As myLong Dim B As myBytes L.Val = IP LSet B = L IPToStr = Trim(Str$(B.B1)) + "." + Trim(Str$(B.B2)) + "." + Trim(Str$(B.B3)) + "." + Trim(Str$(B.B4)) End Function
Public Function EnumIPRangesProc(ByVal CountryID As Integer, ByVal RangeBegin As Long, ByVal RangeEnd As Long, ByRef lb As ListBox) As Boolean Dim sItem As String sItem = IPToStr(RangeBegin) + "-" + IPToStr(RangeEnd) lb.AddItem sItem EnumIPRangesProc = True End Function
'Form Private Sub ListRanges(CountryID As Integer) List1.Clear SWAPI_EnumCountryIPRanges CountryID, AddressOf EnumIPRangesProc, 0,
List1 End Sub |
|
Defined In
| Microsoft Visual C++ |
| SWAPIMap.h, SWAPIMap.cpp |
|
| Borland Delphi |
| SWAPIMap.pas |
|
| Microsoft Visual Basic |
| SWAPIMap.bas |
|
See Also
Functions for Obtaining the Country ID EnumContinentIPRanges EnumIPRangesProc
Copyright © 2006-2008, TamoSoft
|